aboutsummaryrefslogtreecommitdiffstats
path: root/init/log.c
diff options
context:
space:
mode:
authorturret <turret@duck.com>2023-11-24 00:57:35 -0600
committerturret <turret@duck.com>2023-11-24 00:57:35 -0600
commit2f957068e567391e7aef5d7a2c075c14c1e6b37a (patch)
tree2e58f3008886e3372ebb26d1d7ae83a3ac0adae5 /init/log.c
parent40bff7788865b519b79b1ee7eb9851914010ffb4 (diff)
downloaddiscord-bot-skeleton-2f957068e567391e7aef5d7a2c075c14c1e6b37a.tar.gz
discord-bot-skeleton-2f957068e567391e7aef5d7a2c075c14c1e6b37a.tar.bz2
discord-bot-skeleton-2f957068e567391e7aef5d7a2c075c14c1e6b37a.zip
misc: subsys upgrade, log timestamps
(log) - create LOGLEVEL constant numbers - implement CONSOLE_LOGLEVEL - color array now uses loglevel constants - timestamp now shown (thanks util-linux) (init) - register mainpid - hello world print - fix process reaper to refer to subsys when reaping (subsys) - create maximum subsystem count - create subsystem table - add debugging prints to subsystem entry and termination - create function to handle process termination (unmap stack, free subsystem malloc, clear entry in table) - disable subsystem inception - change die references to fail with print - supply clone with signal to send on termination (SIGCHLD)
Diffstat (limited to 'init/log.c')
-rw-r--r--init/log.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/init/log.c b/init/log.c
index d3bcbe4..eb2cd09 100644
--- a/init/log.c
+++ b/init/log.c
@@ -2,32 +2,38 @@
#include <stdio.h>
#include <string.h>
#include <sys/file.h>
+#include <sys/time.h>
#include <unistd.h>
#include <log.h>
#include <util.h>
static const char *colors[] = {
- [0] = ANSI_BLINK ANSI_REVERSE ANSI_BOLD ANSI_RED,
- [1] = ANSI_REVERSE ANSI_BOLD ANSI_RED,
- [2] = ANSI_BOLD ANSI_RED,
- [3] = ANSI_RED,
- [4] = ANSI_BOLD,
- [5] = ANSI_BRIGHT_WHITE,
- [6] = ANSI_RESET,
- [7] = ANSI_ITALIC ANSI_BRIGHT_BLUE,
+ [EMERG_LOGLEVEL] = ANSI_BLINK ANSI_REVERSE ANSI_BOLD ANSI_RED,
+ [ALERT_LOGLEVEL] = ANSI_REVERSE ANSI_BOLD ANSI_RED,
+ [CRIT_LOGLEVEL] = ANSI_BOLD ANSI_RED,
+ [ERR_LOGLEVEL] = ANSI_RED,
+ [WARNING_LOGLEVEL] = ANSI_BOLD,
+ [NOTICE_LOGLEVEL] = ANSI_BRIGHT_WHITE,
+ [INFO_LOGLEVEL] = ANSI_RESET,
+ [DEBUG_LOGLEVEL] = ANSI_ITALIC ANSI_BRIGHT_BLUE,
};
+int start_time = 0;
int console_lock = 0;
int print(const char *fmt, ...)
{
- int loglevel = 5;
+ int loglevel = DEFAULT_LOGLEVEL;
if(fmt[0] == LOG_SOH_ASCII) {
loglevel = (fmt[1] - 0x30) % 10;
fmt += 2;
}
+ /* not going to be printed? dont bother! */
+ if(loglevel > CONSOLE_LOGLEVEL)
+ return 0;
+
/* we essentially print the user's raw input to its own buffer,
later we will parse it and print out ANSI colors and what not */
char buf[512];
@@ -44,6 +50,11 @@ int print(const char *fmt, ...)
break;
}
+ char tsbuf[64] = "\0";
+ struct timeval time;
+ gettimeofday(&time, NULL);
+ snprintf(tsbuf, sizeof(tsbuf), "[%5ld.%06ld] ", (long)time.tv_sec % 100000, (long)time.tv_usec);
+
/* spin lock, at the cost of architecture portability
concurrency is something that we need to adjust for, and the
console will be scrambled and unreadable if we allow writing all
@@ -58,8 +69,10 @@ int print(const char *fmt, ...)
/* we want to support stuff without colons, but frankly I havent
tested this at time of writing. will find out later */
+ writeputs(ANSI_RESET ANSI_GREEN);
+ writeputs(tsbuf);
+ writeputs(ANSI_RESET);
if(buf[colon] == ':') {
- writeputs(ANSI_RESET);
writeputs(colors[loglevel]);
writeputs(ANSI_YELLOW);
write(STDOUT_FILENO, buf, colon);