chiark / gitweb /
shared/log: add log_trace as compile-time optional debugging
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 23 Oct 2014 04:27:57 +0000 (23:27 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 23 Oct 2014 04:27:57 +0000 (00:27 -0400)
Repetetive messages can be annoying when running with
SYSTEMD_LOG_LEVEL=debug, but they are sometimes very useful
when debugging problems. Add log_trace which is like log_debug
but becomes a noop unless LOG_TRACE is defined during compilation.
This makes it easy to enable very verbose logging for a subset
of programs when compiling from source.

src/journal-remote/journal-remote-parse.c
src/journal-remote/journal-remote.c
src/shared/log.h

index 224e8f140bd06d5d5ef7f781004cc93ea8a942b3..7dd8878ca68780e5953e027c02d1e9790da7954d 100644 (file)
@@ -330,7 +330,7 @@ int process_data(RemoteSource *source) {
                 assert(line[n-1] == '\n');
 
                 if (n == 1) {
-                        log_debug("Received empty line, event is ready");
+                        log_trace("Received empty line, event is ready");
                         return 1;
                 }
 
@@ -350,7 +350,7 @@ int process_data(RemoteSource *source) {
                 else
                         /* replace \n with = */
                         line[n-1] = '=';
-                log_debug("Received: %.*s", (int) n, line);
+                log_trace("Received: %.*s", (int) n, line);
 
                 r = iovw_put(&source->iovw, line, n);
                 if (r < 0) {
@@ -438,7 +438,7 @@ int process_source(RemoteSource *source, bool compress, bool seal) {
                 return r;
 
         /* We have a full event */
-        log_debug("Received a full event from source@%p fd:%d (%s)",
+        log_trace("Received a full event from source@%p fd:%d (%s)",
                   source, source->fd, source->name);
 
         if (!source->iovw.count) {
index 8a72c6eb2b5711b26da48161cb444d10bcce9334..dc7120bbd534aa786b014d328698469e1a1a4f7c 100644 (file)
@@ -505,11 +505,11 @@ static int process_http_upload(
 
         assert(source);
 
-        log_debug("request_handler_upload: connection %p, %zu bytes",
-                  connection, *upload_data_size);
+        log_trace("%s: connection %p, %zu bytes",
+                  __func__, connection, *upload_data_size);
 
         if (*upload_data_size) {
-                log_debug("Received %zu bytes", *upload_data_size);
+                log_trace("Received %zu bytes", *upload_data_size);
 
                 r = push_data(source, upload_data, *upload_data_size);
                 if (r < 0)
@@ -572,7 +572,7 @@ static int request_handler(
         assert(url);
         assert(method);
 
-        log_debug("Handling a connection %s %s %s", method, url, version);
+        log_trace("Handling a connection %s %s %s", method, url, version);
 
         if (*connection_cls)
                 return process_http_upload(connection,
index 9918381d39df19dd5cceb63d887579613fedbbb5..a3e23a855cf570e5db94ef6151a807324bb648ae 100644 (file)
@@ -157,6 +157,12 @@ do { \
 #define log_warning(...) log_full(LOG_WARNING, __VA_ARGS__)
 #define log_error(...)   log_full(LOG_ERR,     __VA_ARGS__)
 
+#ifdef LOG_TRACE
+#  define log_trace(...) log_debug(__VA_ARGS__)
+#else
+#  define log_trace(...) do {} while(0)
+#endif
+
 #define log_struct(level, ...) log_struct_internal(level, __FILE__, __LINE__, __func__, __VA_ARGS__)
 
 #define log_oom() log_oom_internal(__FILE__, __LINE__, __func__)