[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

@@ -47,7 +47,7 @@ channel::create(size_t size)
j6_handle_t vma = j6_handle_invalid;
if (size < arch::frame_size || (size & (size - 1)) != 0) {
syslog("Bad channel size: %lx", size);
syslog(j6::logs::ipc, j6::log_level::error, "Bad channel size: %lx", size);
return nullptr;
}
@@ -58,7 +58,7 @@ channel::create(size_t size)
result = j6_vma_create_map(&vma, size, &addr, j6_vm_flag_write|j6_vm_flag_ring);
if (result != j6_status_ok) {
syslog("Failed to create channel VMA. Error: %lx", result);
syslog(j6::logs::ipc, j6::log_level::error, "Failed to create channel VMA. Error: %lx", result);
return nullptr;
}
@@ -79,7 +79,7 @@ channel::open(j6_handle_t vma)
result = j6_vma_map(vma, 0, &addr, 0);
if (result != j6_status_ok) {
syslog("Failed to map channel VMA. Error: %lx", result);
syslog(j6::logs::ipc, j6::log_level::error, "Failed to map channel VMA. Error: %lx", result);
return nullptr;
}

View File

@@ -12,7 +12,7 @@ namespace j6 {
void
condition::wait()
{
j6::syslog("Waiting on condition %lx", this);
j6::syslog(j6::logs::app, j6::log_level::verbose, "Waiting on condition %lx", this);
uint32_t v = __atomic_add_fetch(&m_state, 1, __ATOMIC_ACQ_REL);
j6_status_t s = j6_futex_wait(&m_state, v, 0);
while (s == j6_status_futex_changed) {
@@ -20,7 +20,7 @@ condition::wait()
if (v == 0) break;
s = j6_futex_wait(&m_state, v, 0);
}
j6::syslog("Woke on condition %lx", this);
j6::syslog(j6::logs::app, j6::log_level::verbose, "Woke on condition %lx", this);
}
void

View File

@@ -2,15 +2,26 @@
/// \file j6/syslog.hh
/// Utility function for writing messages to the kernel log
#include <util/api.h>
// The kernel depends on libj6 for some shared code,
// but should not include the user-specific code.
#ifndef __j6kernel
#include <stdint.h>
#include <util/api.h>
namespace j6 {
void API syslog(const char *fmt, ...);
enum class logs : uint8_t {
#define LOG(name, lvl) name,
#include <j6/tables/log_areas.inc>
#undef LOG
COUNT
};
enum class log_level : uint8_t {
silent, fatal, error, warn, info, verbose, spam, max
};
void API syslog(logs area, log_level severity, const char *fmt, ...);
} // namespace j6

View File

@@ -10,3 +10,6 @@ LOG(syscall,verbose)
LOG(task, verbose)
LOG(timer, info)
LOG(ipc, spam)
LOG(app, spam)
LOG(proto, spam)
LOG(srv, spam)

View File

@@ -42,7 +42,7 @@ client::lookup_service(uint64_t proto_id, j6_handle_t &handle)
size_t data_size = sizeof(proto_id);
handle = j6_handle_invalid;
j6::syslog("Looking up service for %x", proto_id);
j6::syslog(j6::logs::proto, j6::log_level::verbose, "Looking up service for %x", proto_id);
j6_status_t s = j6_mailbox_call(m_service, &tag,
&data, &data_size, data_size,
&handle, &handle_count);

View File

@@ -9,7 +9,7 @@
namespace j6 {
void
syslog(const char *fmt, ...)
syslog(logs area, log_level severity, const char *fmt, ...)
{
char buffer[200];
@@ -19,7 +19,7 @@ syslog(const char *fmt, ...)
va_end(va);
buffer[n] = 0;
j6_log(buffer);
j6_log(static_cast<uint8_t>(area), static_cast<uint8_t>(severity), buffer);
}
} // namespace j6