[libj6] Add log area and severity to j6::syslog()

User code can now set the log area and severity of log messages. This also updates the j6_log
syscall to take these parameters, but removes all calls to it except through j6::syslog().
This commit is contained in:
Justin C. Miller
2024-02-24 13:39:24 -08:00
parent a1e2c58afc
commit bc46c9a7d5
22 changed files with 114 additions and 77 deletions

View File

@@ -124,7 +124,8 @@ LOG_LEVEL_FUNCTION(info);
LOG_LEVEL_FUNCTION(warn);
LOG_LEVEL_FUNCTION(error);
void fatal(logs area, const char *fmt, ...)
void
fatal(logs area, const char *fmt, ...)
{
logger *l = logger::s_log;
if (!l) return;
@@ -137,4 +138,19 @@ void fatal(logs area, const char *fmt, ...)
kassert(false, "log::fatal");
}
void
log(logs area, level severity, const char *fmt, ...)
{
logger *l = logger::s_log;
if (!l) return;
level limit = l->get_level(area);
if (severity > limit) return;
va_list args;
va_start(args, fmt);
l->output(severity, area, fmt, args);
va_end(args);
}
} // namespace log

View File

@@ -77,6 +77,7 @@ private:
friend void warn (logs area, const char *fmt, ...);
friend void error (logs area, const char *fmt, ...);
friend void fatal (logs area, const char *fmt, ...);
friend void log (logs area, level severity, const char *fmt, ...);
void output(level severity, logs area, const char *fmt, va_list args);
@@ -113,6 +114,8 @@ void warn (logs area, const char *fmt, ...);
void error (logs area, const char *fmt, ...);
void fatal (logs area, const char *fmt, ...);
void log (logs area, level severity, const char *fmt, ...);
} // namespace log
extern log::logger &g_logger;

View File

@@ -21,10 +21,11 @@ namespace syscalls {
using system = class ::system;
j6_status_t
log(const char *message)
log(uint8_t area, uint8_t severity, const char *message)
{
thread &th = thread::current();
log::info(logs::syscall, "Message <%02lx:%02lx>: %s", th.parent().obj_id(), th.obj_id(), message);
log::log(static_cast<logs>(area), static_cast<log::level>(severity),
"<%02lx:%02lx>: %s", th.parent().obj_id(), th.obj_id(), message);
return j6_status_ok;
}