summaryrefslogtreecommitdiffstats
path: root/src/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/log.c b/src/log.c
new file mode 100644
index 0000000..7a45023
--- /dev/null
+++ b/src/log.c
@@ -0,0 +1,48 @@
+#include "log.h"
+#include "util.h"
+
+#include <stdbool.h>
+#include <stdlib.h>
+
+int log_active;
+FILE *log_file;
+
+void
+log_init(void)
+{
+ const char *envstr;
+
+ log_active = false;
+
+ envstr = getenv("TMUS_LOG");
+ if (!envstr) return;
+
+ log_file = fopen(envstr, "w+");
+ if (!log_file) PANIC("Failed to open log file\n");
+
+ log_active = true;
+}
+
+void
+log_info(const char *fmtstr, ...)
+{
+ va_list ap;
+
+ if (!log_active) return;
+
+ va_start(ap, fmtstr);
+ vfprintf(log_file, fmtstr, ap);
+ va_end(ap);
+
+ fflush(log_file);
+}
+
+void
+log_end(void)
+{
+ if (!log_active) return;
+
+ fclose(log_file);
+ log_active = 0;
+}
+