---
name: "dnsjit.core.log"
section: "3"
platform: "linux"
package: "dnsjit"
version: "1.5.0-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/dnsjit.core.log"
---

# dnsjit.core.log(3)

Core logging facility

## 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

- all

  Keyword to enable/disable all changeable log levels.

- debug

  Used for debug information.

- info

  Used for informational processing messages.

- notice

  Used for messages of that may have impact on processing.

- warning

  Used for messages that has impact on processing.

- critical

  Used for messages that have severe impact on processing, this level can not be disabled.

- fatal

  Used to display a message before stopping all processing and existing, this level can not be disabled.

### C macros

- Object instance macros

  The following macros uses *&self-\>\_log*: **ldebug(msg...)**, **linfo(msg...)**, **lnotice(msg...)**, **lwarning(msg...)**, **lcritical(msg...)**, **lfatal(msg...)**.

- Object pointer instance macros

  The following macros uses *self-\>\_log*: **lpdebug(msg...)**, **lpinfo(msg...)**, **lpnotice(msg...)**, **lpwarning(msg...)**, **lpcritical(msg...)**, **lpfatal(msg...)**.

- Module macros

  The following macros uses *&\_log*: **mldebug(msg...)**, **mlinfo(msg...)**, **mlnotice(msg...)**, **mlwarning(msg...)**, **mlcritical(msg...)**, **mlfatal(msg...)**.

- Global macros

  The following macros uses 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* and an optional shared *module* Log object.

- **Log:enable**(level)

  Enable specified log level.

- **Log:disable**(level)

  Disable specified log level.

- **Log:clear**(level)

  Clear specified log level, which means it will revert 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 error number to 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)

Maintained by DNS-OARC

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

## BUGS

For issues and feature requests please use:

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

For question and help please use:

*admin@dns-oarc.net*
