]> git.sur5r.net Git - i3/i3/blob - include/log.h
Merge branch 'dpi-log'
[i3/i3] / include / log.h
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * log.c: Logging functions.
8  *
9  */
10 #ifndef I3_LOG_H
11 #define I3_LOG_H
12
13 #include <stdarg.h>
14 #include <stdbool.h>
15
16 /* We will include libi3.h which define its own version of LOG, ELOG.
17  * We want *our* version, so we undef the libi3 one. */
18 #if defined(LOG)
19 #undef LOG
20 #endif
21 #if defined(ELOG)
22 #undef ELOG
23 #endif
24 #if defined(DLOG)
25 #undef DLOG
26 #endif
27 /** ##__VA_ARGS__ means: leave out __VA_ARGS__ completely if it is empty, that
28    is, delete the preceding comma */
29 #define LOG(fmt, ...) verboselog(fmt, ##__VA_ARGS__)
30 #define ELOG(fmt, ...) errorlog("ERROR: " fmt, ##__VA_ARGS__)
31 #define DLOG(fmt, ...) debuglog("%s:%s:%d - " fmt, I3__FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
32
33 extern char *errorfilename;
34 extern char *shmlogname;
35 extern int shmlog_size;
36
37 /**
38  * Initializes logging by creating an error logfile in /tmp (or
39  * XDG_RUNTIME_DIR, see get_process_filename()).
40  *
41  */
42 void init_logging(void);
43
44 /**
45  * Opens the logbuffer.
46  *
47  */
48 void open_logbuffer(void);
49
50 /**
51  * Closes the logbuffer.
52  *
53  */
54 void close_logbuffer(void);
55
56 /**
57  * Checks if debug logging is active.
58  *
59  */
60 bool get_debug_logging(void);
61
62 /**
63  * Set debug logging.
64  *
65  */
66 void set_debug_logging(const bool _debug_logging);
67
68 /**
69  * Set verbosity of i3. If verbose is set to true, informative messages will
70  * be printed to stdout. If verbose is set to false, only errors will be
71  * printed.
72  *
73  */
74 void set_verbosity(bool _verbose);
75
76 /**
77  * Logs the given message to stdout while prefixing the current time to it,
78  * but only if debug logging was activated.
79  *
80  */
81 void debuglog(char *fmt, ...)
82     __attribute__ ((format (printf, 1, 2)));
83
84 /**
85  * Logs the given message to stdout while prefixing the current time to it.
86  *
87  */
88 void errorlog(char *fmt, ...)
89     __attribute__ ((format (printf, 1, 2)));
90
91 /**
92  * Logs the given message to stdout while prefixing the current time to it,
93  * but only if verbose mode is activated.
94  *
95  */
96 void verboselog(char *fmt, ...)
97     __attribute__ ((format (printf, 1, 2)));
98
99 /**
100  * Deletes the unused log files. Useful if i3 exits immediately, eg.
101  * because --get-socketpath was called. We don't care for syscall
102  * failures. This function is invoked automatically when exiting.
103  */
104 void purge_zerobyte_logfile(void);
105
106 #endif