---
# System prepended metadata

title: C snippets

---

# C snippets

## Taglogger
```C
#include <stdarg.h>
#include <stdio.h>

#define RED   "\x1B[31m"
#define GRN   "\x1B[32m"
#define YEL   "\x1B[33m"
#define BLU   "\x1B[34m"
#define MAG   "\x1B[35m"
#define CYN   "\x1B[36m"
#define WHT   "\x1B[37m"
#define RESET "\x1B[0m"

void loge(const char *tag, const char* fmt, ...) {
  printf(RED "%10llu [%s] ERROR: ", get_time(), tag);
  va_list argp;
  va_start(argp, fmt);
  vfprintf(stdout, fmt, argp);
  va_end(argp);
}

void logi(const char *tag, const char* fmt, ...) {
  printf(GRN "%10llu [%s]: " RESET, get_time(), tag);
  va_list argp;
  va_start(argp, fmt);
  vfprintf(stdout, fmt, argp);
  va_end(argp);
}

void logw(const char *tag, const char* fmt, ...) {
  printf(YEL "%10llu [%s] WARNING: " RESET, get_time(), tag);
  va_list argp;
  va_start(argp, fmt);
  vfprintf(stdout, fmt, argp);
  va_end(argp);
}
```