pnmixer
Volume mixer for the system tray
support-log.c
Go to the documentation of this file.
1 /* support-log.c
2  * PNmixer is written by Nick Lanham, a fork of OBmixer
3  * which was programmed by Lee Ferrett, derived
4  * from the program "AbsVolume" by Paul Sherman
5  * This program is free software; you can redistribute
6  * it and/or modify it under the terms of the GNU General
7  * Public License v3. source code is available at
8  * <http://github.com/nicklan/pnmixer>
9  */
10 
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <stdio.h>
22 #include <glib.h>
23 
24 #include "support-log.h"
25 
26 #define VT_ESC "\033"
27 #define VT_RESET "[0m"
28 #define VT_RED "[0;31m"
29 #define VT_GREY "[0;37m"
30 #define VT_YELLOW "[1;33m"
31 
38 gboolean want_debug = FALSE;
39 
48 void
49 log_msg_v(enum log_level level, const char *file, const char *format, va_list args)
50 {
51  char buf[1024];
52  const char *pfx;
53 
54  if (level == LOG_DEBUG && want_debug == FALSE)
55  return;
56 
57  switch (level) {
58  case LOG_ERROR:
59  pfx = VT_ESC VT_RED "error" VT_ESC VT_RESET;
60  break;
61  case LOG_WARN:
62  pfx = VT_ESC VT_YELLOW "warning" VT_ESC VT_RESET;
63  break;
64  case LOG_DEBUG:
65  pfx = VT_ESC VT_GREY "debug" VT_ESC VT_RESET;
66  break;
67  default:
68  pfx = "unknown";
69  }
70 
71  snprintf(buf, sizeof buf, "%s: %s: %s\n", pfx, file, format);
72  vfprintf(stderr, buf, args);
73 }
74 
83 void
84 log_msg(enum log_level level, const char *file, const char *format, ...)
85 {
86  va_list args;
87 
88  va_start(args, format);
89  log_msg_v(level, file, format, args);
90  va_end(args);
91 }
Logging support.
#define VT_YELLOW
Definition: support-log.c:30
gboolean want_debug
Definition: support-log.c:38
#define VT_RED
Definition: support-log.c:28
void log_msg_v(enum log_level level, const char *file, const char *format, va_list args)
Definition: support-log.c:49
log_level
Definition: support-log.h:27
#define VT_ESC
Definition: support-log.c:26
void log_msg(enum log_level level, const char *file, const char *format,...)
Definition: support-log.c:84
#define VT_RESET
Definition: support-log.c:27
#define VT_GREY
Definition: support-log.c:29