socketplate.log

Logging

While D standard library’s std.logger “implements logging facilities” (At the time of writing, this is its actual module description.), this modules makes sense of them.

import socketplate.log;

log("Hello world"); // prints a log message with text “Hello world”
More...

Members

Aliases

log
alias log = logInfo
logCritical
alias logCritical = defaultLogFunction!(LogLevel.critical)

Logs a critical error

logError
alias logError = defaultLogFunction!(LogLevel.error)

Logs an non-critical error

logFatalAndCrash
alias logFatalAndCrash = defaultLogFunction!(LogLevel.fatal)

Logs a fatal error and raises an Error to halt execution by crashing the application

logInfo
alias logInfo = defaultLogFunction!(LogLevel.info)

Logs an informational message

logTrace
alias logTrace = defaultLogFunction!(LogLevel.trace)

Logs a trace/debug message

logWarning
alias logWarning = defaultLogFunction!(LogLevel.warning)

Logs a warning

Functions

logException
void logException(Throwable exception, string description, int line, string file, string funcName, string prettyFuncName, string moduleName)

Logs an exception (including a stack trace)

setLogLevel
void setLogLevel(LogLevel logLevel)

Sets the LogLevel of the default logger (also known as sharedLog)

Imports

LogLevel (from std.logger)
public import std.logger : LogLevel;
Undocumented in source.

Detailed Description

Log levels

// set the log level of `sharedLog` to *INFO*
// (`sharedLog` is the globally available default logger implemented in `std.logger`)
setLogLevel(LogLevel.info);

logTrace("Trace/debug message");
logInfo("Info message");
logWarning("Warning message");
logError("(Non-fatal, uncritical) error message");
logCritical("(Non-fatal yet critical) error message");
logFatalAndCrash("Fatal error message, also crashes the program");

Notable differences to std.logger

  • The “default” log functions applys a log level of *INFO* instead of *ALL*.
  • Logging function names are prefixed with log.
  • The “fatal”-level logging function mentions in its name that it will crash the application.
  • The hello-world example will actually print a log message out of the box.

Meta