wk1: initial docker image setup
This commit is contained in:
commit
51738fcac7
33 changed files with 1833 additions and 0 deletions
65
src/log/log.c
Normal file
65
src/log/log.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LEVEL_ERROR 0
|
||||
#define LEVEL_WARN 4
|
||||
#define LEVEL_INFO 6
|
||||
#define LEVEL_DEBUG 7
|
||||
|
||||
#define RED "\e[0;31m"
|
||||
#define GREEN "\e[0;32m"
|
||||
#define YELLOW "\e[0;33m"
|
||||
#define BLUE "\e[0;34m"
|
||||
#define PURPLE "\e[0;35m"
|
||||
#define CYAN "\e[0;36m"
|
||||
#define WHITE "\e[0;37m"
|
||||
#define LRED "\e[1;31m"
|
||||
#define LGREEN "\e[1;32m"
|
||||
#define LYELLOW "\e[1;33m"
|
||||
#define LBLUE "\e[1;34m"
|
||||
#define LPURPLE "\e[1;35m"
|
||||
#define LCYAN "\e[1;36m"
|
||||
#define LWHITE "\e[1;37m"
|
||||
#define RESET "\e[0m"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 3) {
|
||||
printf("log: usage: %s <level> <message>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char level = 0;
|
||||
char *colour = WHITE;
|
||||
char *level_str;
|
||||
|
||||
if (strncmp(argv[1], "error", 6) == 0) level = LEVEL_ERROR;
|
||||
if (strncmp(argv[1], "warn", 5) == 0) level = LEVEL_WARN;
|
||||
if (strncmp(argv[1], "info", 5) == 0) level = LEVEL_INFO;
|
||||
if (strncmp(argv[1], "debug", 6) == 0) level = LEVEL_DEBUG;
|
||||
|
||||
switch (level) {
|
||||
case LEVEL_ERROR:
|
||||
colour = RED;
|
||||
level_str = "ERROR";
|
||||
break;
|
||||
case LEVEL_WARN:
|
||||
colour = YELLOW;
|
||||
level_str = "WARN";
|
||||
break;
|
||||
case LEVEL_INFO:
|
||||
colour = GREEN;
|
||||
level_str = "INFO";
|
||||
break;
|
||||
case LEVEL_DEBUG:
|
||||
colour = BLUE;
|
||||
level_str = "DEBUG";
|
||||
break;
|
||||
default:
|
||||
printf("log: invalid log level argument \"%s\"\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("[%s%s"RESET"] %s\n", colour, level_str, argv[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue