Module liblog

Lua API for liblog control

Support library for controlling liblog using Lua

See also (project home-sites)

Info:

  • Copyright: © Michael Ambrus 2024
  • License: MIT
  • Author: Michael Ambrus michael@ambrus.se

Functions

version () version string
level () Get current log-level
setlevel (new) Set log-level
setslevel (new) Set log-level string
settings () Get liblog settings into a "json"-like table
setsyslog (Enable, stderrdup) Set usage of syslog (mode)

Enable syslog or close it (if opened) and go back to file-operation mode.

setlogfile (filename, Sync) Set File-IO mode filename

Enable File-IO mode with file-name Disable syslog or close it (if opened)

Which is determined by the first argument.

decorate (Decorate, Decorate) Set decorators
setname (Any) Set/unset process/marker decorator

This is a special decorator as it can be any string.

send (V, Message) Send log

Test-API to send a liblog log-message of certain type Disable syslog or close it (if opened)

Which type determined by the first argument.

log (Type, Message) Send log message


Functions

version ()
version string

Returns:

    string version
level ()
Get current log-level

Returns:

  1. integer log-level
  2. string log-level
setlevel (new)
Set log-level

Parameters:

  • new integer log-level

Returns:

  1. integer previous log-level
  2. integer current log-level
setslevel (new)
Set log-level string Set log-level as human readable string

Parameters:

  • new integer log-level

Returns:

  1. string previous log-level
  2. string current log-level
settings ()
Get liblog settings into a "json"-like table Each table index is a tuple: ["name" : value]

Returns:

  1. integer number settings
  2. table tuple-table with settings

Usage:

  • Return table
    --[[
    1. (char *) fname       Write to file-name
    2. (enum)   ts          Time-stamp decoration type
            NO_TIME,            Don't decorate with time stamp
            SHORT_TIME,         Numerical epoc timestamp
            VERBOSE_TIME,       HH:MM:SS.ms
            DATE_TIME           Date format
    3. (enum)   pidtid      Decorate with process- thread-id
            NO_PIDTID_DECO,     Don't decorate with pid/tid
            TID_DECO,           Thread only (suitable when syslog as only pid is shown)
            PID_DECO,           PID only (quite useless)
            PIDTID_DECO         Both pid/tid
    4. (bool)   tosyslog    Send to syslog without decoration
    5. (bool)   sys2err     If syslog, also stderr (syslogs decoration)
    6. (char *) proc_name   Name of process
    7. (int)    nsync       Flush output after each write in File-IO mode
                               0 :  buffered
                              <0 :  Flush file after each write (warning:
                                    decreases performance)
                              >0 :  Flush file after each nsync write
    --]]
  • -- Example of usage:
        n,s = liblog.settings()
        for i=1,n do print(s[i][1], s[i][2]) end
setsyslog (Enable, stderrdup)
Set usage of syslog (mode)

Enable syslog or close it (if opened) and go back to file-operation mode.

Which is determined my the first argument. Second argument enables copy syslog to stderr. It's ignored if not enabling syslog operation.

Parameters:

  • Enable boolean 1=Enable 0=Disable
  • stderrdup boolean 1=Enable 0=Disable

Returns:

  1. boolean previous mode-state
  2. boolean previous sys2err
  3. boolean current state-state
  4. boolean previous sys2err
setlogfile (filename, Sync)
Set File-IO mode filename

Enable File-IO mode with file-name Disable syslog or close it (if opened)

Which is determined by the first argument. Second argument enables copy syslog to stderr. It's ignored if not enabling syslog operation.

Parameters:

  • filename string
  • Sync nsync counter. 0=Buffered, -1=Fully sync, >0 sync each n'th

Returns:

  1. string previous filename
  2. integer previous sync-mode/-cntr
  3. string current filename
  4. integer current sync-mode/-cntr
decorate (Decorate, Decorate)
Set decorators For values:

Parameters:

  • Decorate integer pid/tid mode. 0=off, 1=tid...
  • Decorate integer pid/tid mode. 0=off, 1=tid...

Returns:

  1. integer previous ts
  2. integer previous pidtid
  3. integer current ts
  4. integer current pidtid

See also:

setname (Any)
Set/unset process/marker decorator

This is a special decorator as it can be any string. Usually it contains application or process name but user can but anything here.

Parameters:

Returns:

  1. string previous marker
  2. string current marker
send (V, Message)
Send log

Test-API to send a liblog log-message of certain type Disable syslog or close it (if opened)

Which type determined by the first argument. Second argument enables copy syslog to stderr. It's ignored if not enabling syslog operation.

Parameters:

  • V integer =0, D=1, I=2, W=3, E=4, C=5
  • Message string

Returns:

    boolean OK
log (Type, Message)
Send log message Test-API to send a liblog log-message of certain type

Which type to send is determined by the first argument.

Parameters:

  • Type string "VERBOSE", "DEBUG", "INFO", "ERROR", "CRITICAL"
  • Message string

Returns:

    boolean OK
generated by LDoc 1.5.0 Last updated 2025-03-10 21:43:19