dnsjit.core.log(3)

πŸ“¦
version 1.5.1 Β· 5 versions
, in epel 10, epel 9, fedora 43, fedora 44, ubuntu resolute, ubuntu stonking

dnsjit.core.log πŸ’– the core logging facility (yes, from the dnsjit library, manual section 3)

okay bestie sit DOWN because this is the logging glow-up page 🌸 it's literally called dnsjit.core.log and it's the Core logging facility β€” every single module in dnsjit leans on it. no cap.


✨ SYNOPSIS ✨

πŸ’… Usage to control global log level

local log = require("dnsjit.core.log")
log.enable("all")
log.disable("debug")

πŸ’… Usage to control module log level

local example = require("example") -- Example as below
example.log():enable("all")
example.log():disable("debug")

πŸ’… Usage to control object instance log level

local example = require("example") -- Example as below
local obj = example.new()
obj:log():enable("all")
obj:log():disable("debug")

πŸ’… Usage in C module

NOTE β€” the naming of variables and module-only globals has to be exactly like described, otherwise the macros just will not work. self is the pointer to the object instance, self->_log is the object instance logging configuration struct, and _log is the module logging configuration struct. it's giving strict, but she's worth it 🫢

Include logging:

#include "core/log.h"

Add the logging struct to the module struct:

typedef struct example {
    core_log_t _log;
    ...
} example_t;

Add a module logging configuration and a struct default:

static core_log_t _log = LOG_T_INIT("example");
static example_t _defaults = {
    LOG_T_INIT_OBJ("example"),
    ...
};

Use new/free and/or init/destroy functions (depends if you create the object in Lua or not):

example_t* example_new() {
    example_t* self = calloc(1, sizeof(example_t));

    *self = _defaults;
    ldebug("new()");

    return self;
}

void example_free(example_t* self) {
    ldebug("free()");
    free(self);
}

int example_init(example_t* self) {
    *self = _defaults;

    ldebug("init()");

    return 0;
}

void example_destroy(example_t* self) {
    ldebug("destroy()");
    ...
}

In the Lua part of the C module you need to create a function that returns either the object instance Log or the module's Log πŸ‘‘

Add C function to get module only Log:

core_log_t* example_log() {
    return &_log;
}

For the structure's metatable add the following function:

local ffi = require("ffi")
local C = ffi.C

function Example:log()
    if self == nil then
        return C.example_log()
    end
    return self._log
end

πŸ’… Usage in pure Lua module

local log = require("dnsjit.core.log")
local ffi = require("ffi")
local C = ffi.C

local Example = {}
local module_log = log.new("example")

function Example.new()
    local self = setmetatable({
        _log = log.new("example", module_log),
    }, { __index = Example })

    self._log:debug("new()")

    return self
end

function Example:log()
    if self == nil then
        return module_log
    end
    return self._log
end

🌈 DESCRIPTION 🌈

it's the Core logging facility, used by all modules. every one of them. the whole roster. periodt.

πŸŽ€ Log levels πŸŽ€

  • all β€” the keyword that enables/disables all the changeable log levels at once. main character energy fr.
  • debug β€” for debug information πŸ›
  • info β€” for informational processing messages ✨
  • notice β€” for messages that may have an impact on processing πŸ‘€
  • warning β€” for messages that has impact on processing ⚠️
  • critical β€” for messages that have severe impact on processing β€” and heads up, this level can not be disabled πŸ’€
  • fatal β€” used to display a message before stopping all processing and exiting β€” this level can not be disabled either 😭

πŸ¦‹ C macros πŸ¦‹

  • Object instance macros β€” these use &self->_log: ldebug(msg...), linfo(msg...), lnotice(msg...), lwarning(msg...), lcritical(msg...), lfatal(msg...).
  • Object pointer instance macros β€” these use self->_log: lpdebug(msg...), lpinfo(msg...), lpnotice(msg...), lpwarning(msg...), lpcritical(msg...), lpfatal(msg...).
  • Module macros β€” these use &_log: mldebug(msg...), mlinfo(msg...), mlnotice(msg...), mlwarning(msg...), mlcritical(msg...), mlfatal(msg...).
  • Global macros β€” these use the global logging configuration: gldebug(msg...), glinfo(msg...), glnotice(msg...), glwarning(msg...), glcritical(msg...), glfatal(msg...).

πŸ’œ Functions πŸ’œ

  • Log.new(name, module) β€” create a new Log object with the given module name, plus an optional shared module Log object.
  • Log:enable(level) β€” enable the specified log level.
  • Log:disable(level) β€” disable the specified log level.
  • Log:clear(level) β€” clear the specified log level, which means it reverts back to default or inherited settings.
  • Log:display_file_line(bool) β€” enable or disable the displaying of file and line for messages.
  • Log.errstr(errno) β€” convert an error number into its text representation.
  • Log.debug(self, ...) β€” generate a debug message.
  • Log.info(self, ...) β€” generate an info message.
  • Log.notice(self, ...) β€” generate a notice message.
  • Log.warning(self, ...) β€” generate a warning message.
  • Log.critical(self, ...) β€” generate a critical message.
  • Log.fatal(self, ...) β€” generate a fatal message.

πŸ‘‘ AUTHORS and CONTRIBUTORS πŸ‘‘

Jerry LundstrΓΆm (DNS-OARC), TomΓ‘Ε‘ KΕ™Γ­ΕΎek (CZ.NIC), Petr Ε paček (ISC) β€” absolute icons, we stan 🫢

Maintained by DNS-OARC

https://www.dns-oarc.net/


πŸ™ˆ BUGS πŸ™ˆ

Found an issue or you're craving a feature? please use:

https://codeberg.org/DNS-OARC/dnsjit/issues

Got a question or need help? hit up:

admin@dns-oarc.net


and that's the whole page bestie πŸ’– this was dnsjit version 1.5.1, serving you the dnsjit.core.log(3) manual. go forth and log responsibly, ilysm βœ¨πŸŽ€πŸ¦‹