]> git.sur5r.net Git - i3/i3/blob - include/log.h
i3/log.h: Prepare for libi3.h inclusion
[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 _LOG_H
11 #define _LOG_H
12
13 #include <stdarg.h>
14 #include <stdbool.h>
15
16 /** ##__VA_ARGS__ means: leave out __VA_ARGS__ completely if it is empty, that
17    is, delete the preceding comma */
18 #define LOG(fmt, ...) verboselog(fmt, ##__VA_ARGS__)
19 /* We will include libi3.h which define its own version of ELOG.
20  * We want *our* version, so we undef the libi3 one. */
21 #if defined(ELOG)
22 #undef ELOG
23 #endif
24 #define ELOG(fmt, ...) errorlog("ERROR: " fmt, ##__VA_ARGS__)
25 #define DLOG(fmt, ...) debuglog("%s:%s:%d - " fmt, I3__FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
26
27 extern char *errorfilename;
28 extern char *shmlogname;
29 extern int shmlog_size;
30
31 /**
32  * Initializes logging by creating an error logfile in /tmp (or
33  * XDG_RUNTIME_DIR, see get_process_filename()).
34  *
35  */
36 void init_logging(void);
37
38 /**
39  * Set debug logging.
40  *
41  */
42 void set_debug_logging(const bool _debug_logging);
43
44 /**
45  * Set verbosity of i3. If verbose is set to true, informative messages will
46  * be printed to stdout. If verbose is set to false, only errors will be
47  * printed.
48  *
49  */
50 void set_verbosity(bool _verbose);
51
52 /**
53  * Logs the given message to stdout while prefixing the current time to it,
54  * but only if debug logging was activated.
55  *
56  */
57 void debuglog(char *fmt, ...)
58     __attribute__ ((format (printf, 1, 2)));
59
60 /**
61  * Logs the given message to stdout while prefixing the current time to it.
62  *
63  */
64 void errorlog(char *fmt, ...)
65     __attribute__ ((format (printf, 1, 2)));
66
67 /**
68  * Logs the given message to stdout while prefixing the current time to it,
69  * but only if verbose mode is activated.
70  *
71  */
72 void verboselog(char *fmt, ...)
73     __attribute__ ((format (printf, 1, 2)));
74
75 /**
76  * Deletes the unused log files. Useful if i3 exits immediately, eg.
77  * because --get-socketpath was called. We don't care for syscall
78  * failures. This function is invoked automatically when exiting.
79  */
80 void purge_zerobyte_logfile(void);
81
82 #endif