-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrutils.c
More file actions
63 lines (52 loc) · 1.4 KB
/
rutils.c
File metadata and controls
63 lines (52 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
RUtils Single Source Library
Copyright (c) 2026 RandomPerson
SPDX-License-Identifier: MIT-0
*/
#include <stdio.h>
/* Variables */
/* ANSI Colors */
const char *RUTILS_COLOR_RED = "\x1b[1;31m";
const char *RUTILS_COLOR_YELLOW = "\x1b[1;33m";
const char *RUTILS_COLOR_GREEN = "\x1b[1;32m";
const char *RUTILS_COLOR_RESET = "\x1b[0;0m";
/* Enums */
/* Log Types */
enum RUtilsLogtype {
RUTILS_LOGGING_NORMAL,
RUTILS_LOGGING_WARNING,
RUTILS_LOGGING_ERROR
};
/* Functions */
/* Function To Log Messages To stdout/stderr */
void rutils_logging_log(const char *log_msg, enum RUtilsLogtype log_type) {
switch (log_type) {
case RUTILS_LOGGING_ERROR:
fprintf(stderr,
"%s[E]: %s%s\n",
RUTILS_COLOR_RED,
log_msg,
RUTILS_COLOR_RESET);
break;
case RUTILS_LOGGING_WARNING:
fprintf(stdout,
"%s[W]: %s%s\n",
RUTILS_COLOR_YELLOW,
log_msg,
RUTILS_COLOR_RESET);
break;
case RUTILS_LOGGING_NORMAL:
fprintf(stdout,
"%s[N]: %s%s\n",
RUTILS_COLOR_GREEN,
log_msg,
RUTILS_COLOR_RESET);
break;
default:
fprintf(stdout,
"%s[W]: Log type %d is invalid, actual log message will not be shown!%s\n",
RUTILS_COLOR_YELLOW,
log_type,
RUTILS_COLOR_RESET);
}
}