Overview

The FreeWorld OS kernel logging system provides comprehensive logging capabilities with klog (kernel log buffer), dmesg (display messages), and syslog integration.

Components

klog (Kernel Log Buffer)

Circular buffer for kernel messages:

  • 64KB Circular Buffer: Efficient memory usage with automatic wrapping
  • Timestamp Support: All messages include timestamps (ticks since boot)
  • Log Level Filtering: DEBUG, INFO, WARNING, ERROR, CRITICAL
  • Thread-Safe: Spinlock-protected operations
  • Multiple Outputs: Serial, buffer, and file (future) support
  • Up to 1024 Entries: Indexed entry management
  • Message Formatting: Timestamps, levels, facilities, and messages

dmesg (Display Messages)

Read and display kernel messages:

  • Read All Messages: Display all messages from klog buffer
  • Level Filtering: Filter by log level (bitmask)
  • Facility Filtering: Filter by facility (bitmask)
  • Clear Buffer: Option to clear buffer after reading
  • Follow Mode: Continuous output of new messages
  • Thread-Safe Reading: Safe concurrent access

syslog Integration

syslog protocol support (RFC 3164):

  • 8 Priority Levels: EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO, DEBUG
  • 24 Facilities: KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP, CRON, AUTHPRIV, FTP, NTP, SECURITY, CONSOLE, LOCAL0-7
  • Local syslog: Integrated with klog
  • Remote syslog: Structure ready for network syslog
  • Priority Mapping: Automatic mapping to klog levels
  • RFC 3164 Format: Standard syslog message format

Log Levels

Level Value Description
DEBUG 0 Debug messages (lowest priority)
INFO 1 Informational messages
WARNING 2 Warning messages
ERROR 3 Error messages
CRITICAL 4 Critical messages (highest priority)

Features

  • 64KB circular buffer for kernel messages
  • Timestamp support (ticks since boot)
  • Thread-safe operations (spinlock)
  • Log level filtering
  • Multiple output destinations
  • Message formatting with timestamps, levels, and facilities
  • dmesg command for viewing messages
  • Follow mode for continuous monitoring
  • syslog protocol support (RFC 3164)
  • Priority and facility support
  • Local and remote syslog support

Implementation

Total Lines of Code: ~1,238 lines

  • kernel/logging/klog.asm (~650 lines) - Kernel log buffer
  • kernel/logging/dmesg.asm (~200 lines) - Display messages
  • kernel/logging/syslog.asm (~380 lines) - syslog integration

Integration

The logging system is integrated with:

  • Kernel initialization sequence
  • Serial port (output destination)
  • All kernel components (for logging)