GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
dnsjit.core.log(3) FreeBSD Library Functions Manual dnsjit.core.log(3)

dnsjit.core.log - Core logging facility


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


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


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

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


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

Core logging facility used by all modules.

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.

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...).

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.

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

Maintained by DNS-OARC

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

For issues and feature requests please use:

https://github.com/DNS-OARC/dnsjit/issues

For question and help please use:

admin@dns-oarc.net
1.4.0 dnsjit

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.