aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-11-11 08:32:32 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-11-11 08:32:32 -0500
commitd729032ba2e8da8b4efa4b3112231662c6912f98 (patch)
tree18da4d079539dcc53bf15b5a967b448ac1d5082c /sway
parentAdd some documentation comments (diff)
downloadsway-d729032ba2e8da8b4efa4b3112231662c6912f98.tar.gz
sway-d729032ba2e8da8b4efa4b3112231662c6912f98.tar.zst
sway-d729032ba2e8da8b4efa4b3112231662c6912f98.zip
Add file and line number to log in Debug build
Diffstat (limited to 'sway')
-rw-r--r--sway/log.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/sway/log.c b/sway/log.c
index 2ad9657d..f2b828f9 100644
--- a/sway/log.c
+++ b/sway/log.c
@@ -3,11 +3,13 @@
3#include <stdarg.h> 3#include <stdarg.h>
4#include <stdio.h> 4#include <stdio.h>
5#include <stdlib.h> 5#include <stdlib.h>
6#include <libgen.h>
6#include <fcntl.h> 7#include <fcntl.h>
7#include <unistd.h> 8#include <unistd.h>
8#include <signal.h> 9#include <signal.h>
9#include <errno.h> 10#include <errno.h>
10#include <string.h> 11#include <string.h>
12#include <stringop.h>
11#include <execinfo.h> 13#include <execinfo.h>
12 14
13int colored = 1; 15int colored = 1;
@@ -59,7 +61,11 @@ void sway_abort(const char *format, ...) {
59 sway_terminate(); 61 sway_terminate();
60} 62}
61 63
62void sway_log(log_importance_t verbosity, const char* format, ...) { 64#ifndef NDEBUG
65void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) {
66#else
67void _sway_log(log_importance_t verbosity, const char* format, ...) {
68#endif
63 if (verbosity <= v) { 69 if (verbosity <= v) {
64 unsigned int c = verbosity; 70 unsigned int c = verbosity;
65 if (c > sizeof(verbosity_colors) / sizeof(char *)) { 71 if (c > sizeof(verbosity_colors) / sizeof(char *)) {
@@ -72,6 +78,11 @@ void sway_log(log_importance_t verbosity, const char* format, ...) {
72 78
73 va_list args; 79 va_list args;
74 va_start(args, format); 80 va_start(args, format);
81#ifndef NDEBUG
82 char *file = strdup(filename);
83 fprintf(stderr, "[%s:%d] ", basename(file), line);
84 free(file);
85#endif
75 vfprintf(stderr, format, args); 86 vfprintf(stderr, format, args);
76 va_end(args); 87 va_end(args);
77 88