/tomo/pyhst

To get this branch, use:
bzr branch http://darksoft.org/webbzr/tomo/pyhst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * The PyHST program is Copyright (C) 2002-2011 of the
 * European Synchrotron Radiation Facility (ESRF) and
 * Karlsruhe Institute of Technology (KIT).
 *
 * PyHST is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * hst is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _PYHST_DEBUG_H
#define _PYHST_DEBUG_H

#include <glib.h>

#define pyhst_log(log_levels, module, err, ...) \
    _ds_log_message(0, G_LOG_DOMAIN, log_levels,  (log_levels&DS_LOG_FATAL_MESSAGE)?__FILE__:NULL, __func__, __LINE__, NULL, module, NULL, NULL, err, __VA_ARGS__)

#define pyhst_custom_log(condition, log_levels, module, prefix, err, ...) \
    _ds_log_message(condition, G_LOG_DOMAIN, log_levels, (log_levels&DS_LOG_FATAL_MESSAGE)?__FILE__:NULL, __func__, __LINE__, NULL, module, NULL, prefix, err, __VA_ARGS__)

#define pyhst_debug(...) pyhst_log(G_LOG_LEVEL_DEBUG, NULL, 0, __VA_ARGS__)
#define pyhst_info(...) pyhst_log(G_LOG_LEVEL_INFO, NULL, 0, __VA_ARGS__)
#define pyhst_warning(...) pyhst_log(G_LOG_LEVEL_WARNING, NULL, 0, __VA_ARGS__)
#define pyhst_error(...) pyhst_log(G_LOG_LEVEL_CRITICAL, NULL, 0, __VA_ARGS__)
#define pyhst_fail(...) pyhst_log((GLogLevelFlags)(G_LOG_LEVEL_ERROR|DS_LOG_FATAL_MESSAGE), NULL, 0, __VA_ARGS__)

#define pyhst_debug_module(mod, ...) pyhst_log(G_LOG_LEVEL_DEBUG, mod, 0, __VA_ARGS__)

#define MESSAGE(s) pyhst_debug_module("C_HST_RECON_OVERSLICES", s)
#define DEBUG(s) pyhst_debug(s);
#define check_alloc(ptr, ...) pyhst_custom_log((ptr != NULL), (GLogLevelFlags)(G_LOG_LEVEL_ERROR|DS_LOG_FATAL_MESSAGE), NULL, "failed allocations of array %s", 0, __VA_ARGS__)
#define check_code(code, ...) pyhst_custom_log((code == 0), (GLogLevelFlags)(G_LOG_LEVEL_ERROR|DS_LOG_FATAL_MESSAGE), NULL, "error %u during execution of function %s", code, __VA_ARGS__)

#ifdef __cplusplus
extern "C" {
#endif

int pyhst_configure_logger(int log_level, GLogFunc handler, gpointer arg);

/**
  * Pushes message into the glib log file, this is maximal function which is
  * expected to be called from various define macroses
  *
  * @param condition is message is shown only if condition is false
  * @param log_domain is the log domain, usually G_LOG_DOMAIN
  * @param log_level is the log level, either from GLogLevelFlags or a user-defined level, may indicate fatality
  * @param file is source file where the event have occured
  * @param func is function name where the event have occured
  * @param line is source line where the event have occured
  * @param service is the type of service which haev produced the event
  * @param module is the type of module which have produced the event
  * @param ptr is the object which have produced the event
  * @param prefix is a message enclosing err and message (%s replaced with message and %iud... with error code)
  * @param err is error code (0 - not an error, -1 - from errno)
  * @param format is the message format. See the printf() documentation
  */
void _ds_log_message(int condition, const gchar *log_domain, GLogLevelFlags log_levels, const char *file, const char *func, int line, const gchar *service, const gchar *module, void *ptr, const gchar *prefix, int err, const gchar *format, ...);


#define ds_log_message(condition, log_domain, log_levels, service, module, addr, prefix, err, ...) \
    _ds_log_message(condition, log_domain, log_levels, __FILE__, __func__, __LINE__, service, module, addr, prefix, err, __VA_ARGS__)

/** Terminate application after printing message */
#define DS_LOG_FATAL_MESSAGE G_LOG_FLAG_FATAL
/** Free memory occupied by message if prefix is undefined or prefix otherwise */
#define DS_LOG_CLEAN_MESSAGE G_LOG_FLAG_RECURSION
/** Mask for selecting all levels */
#define DS_LOG_LEVEL_MASK G_LOG_LEVEL_MASK

/** Set required logger output and logging details (for all domains)
  * 
  * @param log_level - maximal log detail
  * @param sink - currently unsupported
  */
void ds_configure_logger(GLogLevelFlags log_level, const char *sink);

/** Set required logging details (for all domains)
  * 
  * @param log_level - maximal log detail
  */
void ds_log_set_level(GLogLevelFlags log_level);

/** Switches on logging message timestmaps */
void ds_log_enable_timestamps(void);

/** Switches on logging threading information */
void ds_log_enable_threads(void);

/** Returns non zero if logging is enabled for specified level */
int ds_log_check_level(GLogLevelFlags log_level);


# ifdef __cplusplus
}
# endif

#endif /* _PYHST_DEBUG_H */