Scroll to navigation

dnsjit.core.log(3) Library Functions Manual dnsjit.core.log(3)

NAME

dnsjit.core.log - Core logging facility

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 naming of variables and module only globals are required to exactly as described in order for the macros to work; self is the pointer to the object instance, self->_log is the object instance logging configuration struct, _log is the module logging configuration struct.

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 modules Log.

Add C function to get module only Log:
core_log_t* example_log() {
return &_log;
}

For the structures 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

Core logging facility used by all modules.

Log levels

Keyword to enable/disable all changeable log levels.
Used for debug information.
Used for informational processing messages.
Used for messages of that may have impact on processing.
Used for messages that has impact on processing.
Used for messages that have severe impact on processing, this level can not be disabled.
Used to display a message before stopping all processing and existing, this level can not be disabled.

C macros

The following macros uses &self->_log: ldebug(msg...), linfo(msg...), lnotice(msg...), lwarning(msg...), lcritical(msg...), lfatal(msg...).
The following macros uses self->_log: lpdebug(msg...), lpinfo(msg...), lpnotice(msg...), lpwarning(msg...), lpcritical(msg...), lpfatal(msg...).
The following macros uses &_log: mldebug(msg...), mlinfo(msg...), mlnotice(msg...), mlwarning(msg...), mlcritical(msg...), mlfatal(msg...).
The following macros uses the global logging configuration: gldebug(msg...), glinfo(msg...), glnotice(msg...), glwarning(msg...), glcritical(msg...), glfatal(msg...).

Functions

Create a new Log object with the given module name and an optional shared module Log object.
Enable specified log level.
Disable specified log level.
Clear specified log level, which means it will revert back to default or inherited settings.
Enable or disable the displaying of file and line for messages.
Convert error number to its text representation.
Generate a debug message.
Generate an info message.
Generate a notice message.
Generate a warning message.
Generate a critical message.
Generate a fatal message.

AUTHORS and CONTRIBUTORS

Jerry Lundström (DNS-OARC), Tomáš Křížek (CZ.NIC), Petr Špaček (ISC)

Maintained by DNS-OARC

BUGS

For issues and feature requests please use:

For question and help please use:

admin@dns-oarc.net
1.2.3 dnsjit