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