feat: add userspace system logging, rename klog to syslog, rename relevant syscalls and API functions
This commit is contained in:
@@ -27,9 +27,9 @@ void open_texteditor(DesktopState* ds) {
|
||||
spawn_app("0:/apps/texteditor/texteditor.elf");
|
||||
}
|
||||
|
||||
void open_klog(DesktopState* ds) {
|
||||
void open_syslog(DesktopState* ds) {
|
||||
(void)ds;
|
||||
spawn_app("0:/apps/klog/klog.elf");
|
||||
spawn_app("0:/apps/klog/syslog.elf");
|
||||
}
|
||||
|
||||
void open_wordprocessor(DesktopState* ds) {
|
||||
|
||||
@@ -249,7 +249,7 @@ void open_system_configuration(DesktopState* ds);
|
||||
void ensure_filemanager_icons_loaded(DesktopState* ds);
|
||||
void open_calculator(DesktopState* ds);
|
||||
void open_texteditor(DesktopState* ds);
|
||||
void open_klog(DesktopState* ds);
|
||||
void open_syslog(DesktopState* ds);
|
||||
void open_settings(DesktopState* ds);
|
||||
void open_user_manager(DesktopState* ds);
|
||||
void open_reboot_dialog(DesktopState* ds);
|
||||
|
||||
@@ -897,7 +897,7 @@ void gui::desktop_handle_keyboard(DesktopState* ds, const montauk::abi::KeyEvent
|
||||
return;
|
||||
}
|
||||
if (routed_key.ascii == 'k' || routed_key.ascii == 'K') {
|
||||
open_klog(ds);
|
||||
open_syslog(ds);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,15 @@
|
||||
#define C_CYAN "\033[36m"
|
||||
#define C_WHITE "\033[37m"
|
||||
|
||||
// ---- Process scan ----
|
||||
|
||||
static bool system_already_initialized() {
|
||||
/* A valid init will always be PID 0 */
|
||||
|
||||
if (montauk::getpid() != 0) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---- Logging ----
|
||||
|
||||
static void log_timestamp(char* buf, int size) {
|
||||
@@ -39,16 +48,16 @@ static void log(LogLevel level, const char* msg) {
|
||||
const char* tag;
|
||||
const char* color;
|
||||
switch (level) {
|
||||
case LOG_OK: tag = " OK "; color = C_GREEN; break;
|
||||
case LOG_INFO: tag = " INFO "; color = C_CYAN; break;
|
||||
case LOG_WARN: tag = " WARN "; color = C_YELLOW; break;
|
||||
case LOG_ERR: tag = " FAIL "; color = C_RED; break;
|
||||
case LOG_OK: tag = "OK:"; color = C_GREEN; break;
|
||||
case LOG_INFO: tag = "INFO:"; color = C_CYAN; break;
|
||||
case LOG_WARN: tag = "WARN:"; color = C_YELLOW; break;
|
||||
case LOG_ERR: tag = "FAIL:"; color = C_RED; break;
|
||||
}
|
||||
|
||||
snprintf(line, sizeof(line),
|
||||
C_DIM "%s" C_RESET " %s%s" C_RESET " " C_BOLD "init" C_RESET " %s\n",
|
||||
C_DIM "%s" C_RESET " %s%s" C_RESET " %s",
|
||||
ts, color, tag, msg);
|
||||
montauk::print(line);
|
||||
montauk::write_log("init", line);
|
||||
}
|
||||
|
||||
static void log_ok(const char* msg) { log(LOG_OK, msg); }
|
||||
@@ -178,11 +187,27 @@ static bool run_configured_service(const montauk::toml::Doc& doc,
|
||||
return run_configured_service(doc, fallback_service, fallback_depth + 1);
|
||||
}
|
||||
|
||||
const char* getReleaseString(char* buffer, int n) {
|
||||
montauk::abi::SysInfo info;
|
||||
montauk::get_info(&info);
|
||||
|
||||
snprintf(buffer, n, "The Montauk Operating System, version %s (build %u)",
|
||||
info.osVersion, info.buildNumber);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// ---- Main ----
|
||||
|
||||
extern "C" void _start() {
|
||||
if (system_already_initialized()) {
|
||||
montauk::exit(1);
|
||||
}
|
||||
|
||||
log_info("The Montauk Operating System");
|
||||
char releaseString[128] = "";
|
||||
getReleaseString(releaseString, 128);
|
||||
|
||||
log_info(releaseString);
|
||||
|
||||
auto config = montauk::config::load("init");
|
||||
int discovered = 0;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#include <montauk/syscall.h>
|
||||
|
||||
extern "C" void _start() {
|
||||
|
||||
montauk::write_log("testapp", "hello, logging world!");
|
||||
|
||||
montauk::exit(0);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
# Makefile for klog (standalone Window Server app) on MontaukOS
|
||||
# Makefile for syslog (standalone Window Server app) on MontaukOS
|
||||
# Copyright (c) 2026 Daniel Hammer
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
@@ -45,14 +45,14 @@ SRCS := main.cpp stb_truetype_impl.cpp font_data.cpp
|
||||
OBJS := $(addprefix $(OBJDIR)/,$(SRCS:.cpp=.o))
|
||||
DEPS := $(OBJS:.o=.d)
|
||||
|
||||
TARGET := $(BINDIR)/apps/klog/klog.elf
|
||||
TARGET := $(BINDIR)/apps/syslog/syslog.elf
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS) $(LINK_LD) Makefile $(LIBDIR)/libc/liblibc.a
|
||||
mkdir -p $(BINDIR)/apps/klog
|
||||
mkdir -p $(BINDIR)/apps/syslog
|
||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(LIBDIR)/libc/liblibc.a -o $@
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp Makefile
|
||||
@@ -68,7 +68,7 @@ static bool klog_poll() {
|
||||
if (now - g_klog.last_poll_ms < KLOG_POLL_MS) return false;
|
||||
g_klog.last_poll_ms = now;
|
||||
|
||||
int n = (int)montauk::read_klog(g_klog.klog_buf, KLOG_READ_SIZE);
|
||||
int n = (int)montauk::read_log(g_klog.klog_buf, KLOG_READ_SIZE);
|
||||
if (n <= 0 && g_klog.last_len <= 0) return false;
|
||||
|
||||
if (n > g_klog.last_len) {
|
||||
@@ -157,7 +157,7 @@ extern "C" void _start() {
|
||||
if (!fonts::init())
|
||||
montauk::exit(1);
|
||||
|
||||
if (!g_win.create("Kernel Log", INIT_W, INIT_H))
|
||||
if (!g_win.create("System Log", INIT_W, INIT_H))
|
||||
montauk::exit(1);
|
||||
|
||||
int cols = g_win.width / mono_cell_width();
|
||||
@@ -180,7 +180,7 @@ extern "C" void _start() {
|
||||
|
||||
g_klog.last_pixels = g_win.pixels;
|
||||
|
||||
int n = (int)montauk::read_klog(g_klog.klog_buf, KLOG_READ_SIZE);
|
||||
int n = (int)montauk::read_log(g_klog.klog_buf, KLOG_READ_SIZE);
|
||||
if (n > 0) {
|
||||
klog_refeed(n);
|
||||
g_klog.last_len = n;
|
||||
@@ -1,6 +1,6 @@
|
||||
[app]
|
||||
name = "Kernel Log"
|
||||
binary = "klog.elf"
|
||||
name = "System Log"
|
||||
binary = "syslog.elf"
|
||||
icon = "utilities-terminal.svg"
|
||||
|
||||
[menu]
|
||||
Reference in New Issue
Block a user