tmus

TUI Music Player
git clone https://git.sinitax.com/sinitax/tmus
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

log.c (748B)


      1#include "log.h"
      2#include "util.h"
      3
      4#include <stdbool.h>
      5#include <stdlib.h>
      6
      7static int log_active;
      8static FILE *log_file;
      9
     10void
     11log_init(void)
     12{
     13	const char *envstr;
     14
     15	log_active = false;
     16
     17	envstr = getenv("TMUS_LOG");
     18	if (!envstr) return;
     19
     20	log_file = fopen(envstr, "w+");
     21	if (!log_file) ERROR(SYSTEM, "fopen %s", envstr);
     22
     23	log_active = true;
     24}
     25
     26void
     27log_deinit(void)
     28{
     29	if (!log_active) return;
     30
     31	fclose(log_file);
     32	log_active = 0;
     33}
     34
     35void
     36log_info(const char *fmtstr, ...)
     37{
     38	va_list ap;
     39
     40	if (!log_active) return;
     41
     42	va_start(ap, fmtstr);
     43	vfprintf(log_file, fmtstr, ap);
     44	va_end(ap);
     45
     46	fflush(log_file);
     47}
     48
     49void
     50log_infov(const char *fmtstr, va_list ap)
     51{
     52	if (!log_active) return;
     53
     54	vfprintf(log_file, fmtstr, ap);
     55
     56	fflush(log_file);
     57}
     58