core/log

log

Types

4

Constants

11

Default_Console_Logger_Opts

Default_Console_Logger_Opts :: Options = Options{ .Level, .Terminal_Color, .Short_File_Path, .Line, .Procedure, } + Full_Timestamp_OptsSource

The default option set for a console logger.

It is similar to the file logger default option set, but the output includes colors.

When you use this set of options you can expect the following output:

[LEVEL] --- [YYYY-MM-DD HH:MM:SS] [file.odin:L:proc()] Message

For example:

	[INFO ] --- [2025-01-02 12:34:56] [main.odin:8:main()] Hello World!

Default_File_Logger_Opts

Default_File_Logger_Opts :: Options = Options{ .Level, .Short_File_Path, .Line, .Procedure, } + Full_Timestamp_OptsSource

The default option set for a file logger.

It is similar to the console logger default option set, but the output is not colored.

When you use this set of options you can expect the following output:

[LEVEL] --- [YYYY-MM-DD HH:MM:SS] [file.odin:L:proc()] Message

For example:

	[INFO ] --- [2025-01-02 12:34:56] [main.odin:8:main()] Hello World!

Full_Timestamp_Opts

Full_Timestamp_Opts :: Options = Options{ .Date, .Time, }Source

A preset option set for a logger.

When you use this set of options you can expect the following output:

[YYYY-MM-DD HH:MM:SS] Message

For example:

	[2025-01-02 12:34:56] Hello World!

Level

Level :: runtime.Logger_LevelSource

These are defined in package base:runtime as they are used in the context. This is to prevent an import definition cycle. Logger_Level :: enum {

	Debug   = 0,
		Info    = 10,
		Warning = 20,
		Error   = 30,
		Fatal   = 40,
	}

Location_File_Opts

Location_File_Opts :: Options = Options{ .Short_File_Path, .Long_File_Path, }Source

A preset option set for a logger.

When you use this set of options you can expect the following output:

[file.odin] Message

For example:

	[main.odin] Hello World!

Location_Header_Opts

Location_Header_Opts :: Options = Options{ .Short_File_Path, .Long_File_Path, .Line, .Procedure, }Source

A preset option set for a logger.

When you use this set of options you can expect the following output:

[file.odin:L:proc()] Message

For example:

	[main.odin:8:main()] Hello World!

Logger

Logger :: runtime.LoggerSource

Data backing the logger.

Defined in package runtime as it is used in the context. This is to prevent an import definition cycle.

Logger :: struct {
		// Implementation
		procedure:    Logger_Proc,
		// Configuration data passed to the implementation
		data:         rawptr,
		// Minimum level for messages passed to the implementation
		lowest_level: Level,
		// Additional data present in the log output
		options:      Logger_Options,
	}

Option

Option :: runtime.Logger_OptionSource

Specifies additional data present in the log output.

Defined in package runtime as it is used in the context. This is to prevent an import definition cycle.

Option :: enum {
		// The log level, e.g. "[DEBUG] ---"
		Level,
		// The date, e.g. [2025-01-02]
		Date,
		// The time, e.g. [12:34:56]
		Time,
		// Just the filename, e.g. [main.odin]
		Short_File_Path,
		// Full file path, e.g. [/tmp/project/main.odin]
		Long_File_Path,
		// File line of the log statement, e.g. [8]
		Line,
		// Calling procedure, e.g. [main()]
		Procedure,
		// Enables colored output
		Terminal_Color
	}

Variables

1

Level_Headers

Level_Headers :: [?]string = [?]string{ 0..<10 = "[DEBUG] --- ", 10..<20 = "[INFO ] --- ", 20..<30 = "[WARN ] --- ", 30..<40 = "[ERROR] --- ", 40..<50 = "[FATAL] --- ", }Source

Strings to output when .Level is included in the logger options.

Procedures

34

assert

assert :: proc(condition: bool, message = #caller_expression(condition), loc = #caller_location)Source

When condition is false log a message at the Fatal level and abort the program.

Can be disabled using ODIN_DISABLE_ASSERT.

  • condition: A boolean to check
  • message: Message to log when condition is false (a default is provided)
  • loc: Location of the caller (default is #caller_location)

assertf

assertf :: proc(condition: bool, fmt_str: string, args, loc = #caller_location)Source

When condition is false log a formatted message at the Fatal level and abort the program.

Can be disabled using ODIN_DISABLE_ASSERT.

  • condition: A boolean to check
  • fmt_str: A format string to use when condition is false, e.g. `"a: %v, b: %v"
  • args: Arguments for the format string
  • loc: Location of the caller (default is #caller_location)

create_console_logger

create_console_logger :: proc(lowest = Level.Debug, opt = Default_Console_Logger_Opts, ident: untyped string = "", allocator: mem.Allocator = context.allocator) -> (Logger)Source

Create a logger that outputs to the terminal.

Allocates Using Provided Allocator

When no longer needed can be destroyed with destroy_console_logger.

  • lowest: Log level to use (default is .Debug)
  • opt: Specifies additional data present in the log output (default is log.Default_Console_Logger_Opts)
  • ident: Identifier to include in the output (default is "")
  • allocator: Allocator to use for data backing the logger (default is context.allocator)

create_file_logger

create_file_logger :: proc(f: ^os.File, lowest = Level.Debug, opt = Default_File_Logger_Opts, ident: untyped string = "", allocator: mem.Allocator = context.allocator) -> (Logger)Source

Create a logger that outputs to a file.

Allocates Using Provided Allocator

When no longer needed can be destroyed with destroy_file_logger.

  • h: A handle to the output file
  • lowest: Log level to use (default is .Debug)
  • opt: Specifies additional data present in the log output (default is log.Default_File_Logger_Opts)
  • ident: Identifier to include in the output (default is "")
  • allocator: Allocator to use for data backing the logger (default is context.allocator)

create_multi_logger

create_multi_logger :: proc(logs, allocator: mem.Allocator = context.allocator) -> (Logger)Source

Create a logger that logs to all backing loggers.

Allocates Using Provided Allocator

When no longer needed can be destroyed with destroy_multi_logger.

Note: Logs using a multi logger take both the multi logger and the backing loggers' log levels into account.

  • logs - Backing loggers passed as multiple arguments
  • allocator - An allocator used to allocate data to store backing loggers (default is context.allocator)
  • A multi logger

debug

debug :: proc(args, sep: untyped string = " ", location = #caller_location)Source

Log a message at the Debug level.

  • args: values to be concatenated into the output
  • sep: separator to use when concatenating (default is " ")
  • location: Location of the caller (default is #caller_location)

debugf

debugf :: proc(fmt_str: string, args, location = #caller_location)Source

Log a formatted message at the Debug level.

  • fmt_str: A format string, e.g. `"a: %v, b: %v"
  • args: Arguments for the format string
  • location: Location of the caller (default is #caller_location)

ensure

ensure :: proc(condition: bool, message = #caller_expression(condition), loc = #caller_location)Source

When condition is false log a message at the Fatal level and abort the program.

Unlike assert this procedure cannot be disabled with ODIN_DISABLE_ASSERT and will always execute.

  • condition: A boolean to check
  • message: Message to log when condition is false (a default is provided)
  • loc: Location of the caller (default is #caller_location)

ensuref

ensuref :: proc(condition: bool, fmt_str: string, args, loc = #caller_location)Source

When condition is false log a formatted message at the Fatal level and abort the program.

Unlike assertf this procedure cannot be disabled with ODIN_DISABLE_ASSERT and will always execute.

  • condition: A boolean to check
  • fmt_str: A format string to use when condition is false, e.g. `"a: %v, b: %v"
  • args: Arguments for the format string
  • loc: Location of the caller (default is #caller_location)

error

error :: proc(args, sep: untyped string = " ", location = #caller_location)Source

Log a message at the Error level.

  • args: values to be concatenated into the output
  • sep: separator to use when concatenating (default is " ")
  • location: Location of the caller (default is #caller_location)

errorf

errorf :: proc(fmt_str: string, args, location = #caller_location)Source

Log a formatted message at the Error level.

  • fmt_str: A format string, e.g. `"a: %v, b: %v"
  • args: Arguments for the format string
  • location: Location of the caller (default is #caller_location)

fatal

fatal :: proc(args, sep: untyped string = " ", location = #caller_location)Source

Log a message at the Fatal level.

  • args: values to be concatenated into the output
  • sep: separator to use when concatenating (default is " ")
  • location: Location of the caller (default is #caller_location)

fatalf

fatalf :: proc(fmt_str: string, args, location = #caller_location)Source

Log a formatted message at the Fatal level.

  • fmt_str: A format string, e.g. `"a: %v, b: %v"
  • args: Arguments for the format string
  • location: Location of the caller (default is #caller_location)

info

info :: proc(args, sep: untyped string = " ", location = #caller_location)Source

Log a message at the Info level.

  • args: values to be concatenated into the output
  • sep: separator to use when concatenating (default is " ")
  • location: Location of the caller (default is #caller_location)

infof

infof :: proc(fmt_str: string, args, location = #caller_location)Source

Log a formatted message at the Info level.

  • fmt_str: A format string, e.g. `"a: %v, b: %v"
  • args: Arguments for the format string
  • location: Location of the caller (default is #caller_location)

log

log :: proc(level: Level, args, sep: untyped string = " ", location = #caller_location)Source

Log a message at the desired level.

  • level: The level of the message
  • args: values to be concatenated into the output
  • sep: separator to use when concatenating (default is " ")
  • location: Location of the caller (default is #caller_location)

log_allocator_init

log_allocator_init :: proc(la: ^Log_Allocator, level: Level, size_fmt = Log_Allocator_Format.Bytes, allocator: mem.Allocator = context.allocator, prefix: untyped string = "")Source

Initialize the backing data for the allocator that logs all allocations.

  • la: Pointer to the data structure to initialize
  • level: Log level to use for allocations
  • size_fmt: Format to use when logging allocations (default is .Bytes)
  • allocator: Wrapped allocator (default is context.allocator)
  • prefix: Prefix to use in log messages (default is "")

logf

logf :: proc(level: Level, fmt_str: string, args, location = #caller_location)Source

Log a formatted message at the desired level.

  • level: The level of the message
  • fmt_str: A format string, e.g. `"a: %v, b: %v"
  • args: Arguments for the format string
  • location: Location of the caller (default is #caller_location)

panic

panic :: proc(args, location = #caller_location) -> ()Source

Log a message at the Fatal level and abort the program.

  • args: values to be concatenated into the output
  • location: Location of the caller (default is #caller_location)

panicf

panicf :: proc(fmt_str: string, args, location = #caller_location) -> ()Source

Log a formatted message at the Fatal level and abort the program.

  • fmt_str: A format string, e.g. `"a: %v, b: %v"
  • args: Arguments for the format string
  • location: Location of the caller (default is #caller_location)

warn

warn :: proc(args, sep: untyped string = " ", location = #caller_location)Source

Log a message at the Warn level.

  • args: values to be concatenated into the output
  • sep: separator to use when concatenating (default is " ")
  • location: Location of the caller (default is #caller_location)

warnf

warnf :: proc(fmt_str: string, args, location = #caller_location)Source

Log a formatted message at the Warn level.

  • fmt_str: A format string, e.g. `"a: %v, b: %v"
  • args: Arguments for the format string
  • location: Location of the caller (default is #caller_location)

Reference search

Find anything

Documentation preferences

Settings

System theme variants

Used only while Theme is set to System.