Skip to content

Log Manager

Xellu edited this page May 29, 2026 · 1 revision

The built-in logger provides leveled, colored console output with automatic file writes and memory storage.

from nautica import Logger

Log Levels

Each method corresponds to a log level, which controls the color and severity of the output

Method Level Use for
Logger.info(msg) INFO General information
Logger.ok(msg) OK Successful operations
Logger.warn(msg) WARN Non-critical issues
Logger.error(msg) ERROR Errors that need attention
Logger.critical(msg) CRITICAL Severe errors
Logger.debug(msg) DEBUG Debug info, only shown when nautica.debug is True
Logger.info("Server is starting...")
Logger.ok("Connected to database")
Logger.warn("Config value missing, using default")
Logger.error("Failed to load plugin")
Logger.critical("Service failed to initialize")
Logger.debug("Raw response: " + str(data))

File Output

Logs are automatically written to .logs/ in your project directory. A new file is created each time the project starts, named by timestamp:

.logs/nautica_01_01_25__12_00_00.log

This directory is excluded from git by default in .gitignore.

Log Memory

Nautica keeps the last 100 log entries in memory, accessible via LogMemory:

from nautica import Logger
from nautica.manager import LogMemory

entries = LogMemory.Recall()      # all entries
entries = LogMemory.Recall(10)    # last 10 entries

Each entry is a dict:

{
    "moduleName": {
        "full": "myproject.services.myservice",
        "short": "myserv"
    },
    "timestamp": {
        "formatted": "12:00:00",
        "raw": 1234567890.0
    },
    "message": "Connected to database",
    "level": "OK"
}

Tables

Use Logger.table() to display structured data in a table format:

Logger.table() \
    .labels(["Name", "Status", "Port"]) \
    .row(["HTTPServer", "Running", "8100"]) \
    .row(["WebSocket", "Disabled", "-"]) \
    .display()

.display() accepts an optional log level, defaulting to INFO:

.display(LogLevel.DEBUG)  # only shown when debug mode is on

Tracing Exceptions

Use Logger.trace() to log a full exception stacktrace:

try:
    do_something()
except Exception as e:
    Logger.trace(e)

This logs the exception type, message, file, line number, and full traceback.

Log Levels (Advanced)

If you need to log at a specific level directly, use Logger.log():

from nautica.manager import LogLevel

Logger.log("Something happened", LogLevel.INFO)

Available levels:

Level Value
LogLevel.DEBUG 10
LogLevel.TRACE 11
LogLevel.INFO 20
LogLevel.OK 21
LogLevel.WARN 30
LogLevel.ERROR 40
LogLevel.CRITICAL 41
LogLevel.SILENT -999

Clone this wiki locally