Class Log

Declare a new class "Log" into global table

This class is a helper-class to manage the low level modules tplog, liblog, ulog & utrace-probe in a friendlier and unison way.

  • Unison: As both tplog and utrace have to be built-in into the Lua VM and are also highly target specific, Log helps handle the differences by providing one unison API.
  • Friendly: To control log/trace-point with the native API's, one has to be very specific (file, line). This is a hurdle as it basically fits only interactive use, where a human first looks up a/the log-probes(s) and explicitly sets/clears them. As code change, this method is essentially worth-less (or at least very impractical) for initialization-scripts where certain parts of a project needs their dormant log-probes enabled. The Log class provides additional filter functions that:
  • List log-probes per file and function names, with optional qualifier of verbosity type (LOGC-LOGV). This is the basis for all the rest.
  • Set/clear log-probe based on filter. I.e. all per file and/or function with optional specifier verbosity specifier (LOGC-LOGV)
  • Ditto bang/set clear. I.e. groups of all log-probes matching filter. One line instead of potentially hundreds.

See also:

Tables

log.mt Assisting Meta-table

Methods

log:listall () listall

Prints to console a list of all log-probes.

log:p_sel ([filename][, funcname][, kind]) p_sel

Print a selection.

log:p_stat ([filename][, funcname][, kind]) p_stat

Print status for a selection of log-probes.

log:stat ([filename][, funcname][, kind]) stat

Return a table of status for a selection of log-probes.

log:whatis (Probe) whatis

Look-up code reference for a certain log-probe-ID.

log:set ([s=self], ctrl[, cntr[, ts=0]]) set

Set ctrl bit-mask for a selection of probe(s)

First argument can be either a table of size and selection as returned by sel or just the selection as size is implicit in the selection's base-type/class (table)

It can also be omitted, in which case the selection in self is assumed and the rest of the arguments starts at second argument.

log:sel ([Instance], filename, funcname, kind[, idx1[, idx2]]) sel

Return a selection of log-probes in a table based a human-readable specifiers of source-code references.

log:sub ([s=self], idx1[, idx2]) sub
log:new (arg1, funcname, kind[, idx1[, idx2]])

new

Selection or copy/cast CTOR

  • Return a new Log object of selected log-entries.


Tables

log.mt
Assisting Meta-table Operators

Fields:

  • __index
  • __tostring
  • utrace
  • return
  • l
  • end
  • __add
  • l
  • l

Methods

log:listall ()
listall

Prints to console a list of all log-probes. Note that LOG-probes are included as even if a LOG is muted/inactive, it's still also a utrace "probe" or "trace-point" (TP).

Returns:

    Integer Total number of log-probes
log:p_sel ([filename][, funcname][, kind])
p_sel

Print a selection. Usually for interactive use before acting upon it to make sure the conditions are covering the intended probe/probes.

Normally used interactively to determine enough specific criteria for a log-probe", not several log-probes.

Note that the function is not returning the list for Lua-VM. It's printing to console for either interactive use or for RPC use.

Print is a columns of: ID, kind, filename, funcname, line

Arguments are the same as sel (follow "See also") OR one Log instance with a selection.

Parameters:

  • filename String -OR- Log instance (optional)
  • funcname String (optional)
  • kind String (optional)

Returns:

    Integer Number of entries fitting selection

See also:

log:p_stat ([filename][, funcname][, kind])
p_stat

Print status for a selection of log-probes. This is handy for determining if one or several log-probes are live or not. I.e. it's "passed-counters" and "latest time-stamps" are changing.

The list is the same as p_sel with regards to order order and ID, just that the 3 last columns "file", "function" and "line" are replaced with "control", "counter" and "time-stamp".

Note that the function is not returning the list for Lua-VM. It's printing to console for either interactive use or for RPC use.

Print is a columns of: ID ,kind ,filename ,func-name ,line [,d-time ,d-counts ,linked-probe-ID]

Note that the last three columns are conditional and depends of if probe is diff-event linked to another or not (see utrace-probe.setdprobe)

Arguments are the same as sel (follow "See also") OR one Log instance with a selection.

Parameters:

  • filename String -OR- Log instance (optional)
  • funcname String (optional)
  • kind String (optional)

Returns:

    Integer Number of probes fitting selection

See also:

log:stat ([filename][, funcname][, kind])
stat

Return a table of status for a selection of log-probes. Identical to p_stat except that nothing is printed and the return is a table. Note that the table is not live, i.e. Function needs to be re-iterated for current values.

Parameters:

  • filename String -OR- Log instance (optional)
  • funcname String (optional)
  • kind String (optional)

Returns:

    Table of statuses

See also:

Usage:

    a = Log('test_main.c','thread_A',nil,1)
    b = Log('test_main.c','thread_A',nil,2)
    Log:set(a + b, 1)   -- 2
    t = Log:stat(a + b) -- Table with log-probes and stats
log:whatis (Probe)
whatis

Look-up code reference for a certain log-probe-ID. Note: not selection (sel) based but ID-specific. Useful after determining which probe is live p_stat like in the example below.

Parameters:

  • Probe Integer -ID (address)

Returns:

  1. String kind What kind of log-probe is it (E="error", I="info" etc)
  2. String filename File name
  3. String funcname Function name
  4. Number lineno Line number
  5. Integer Linked Probe-ID (conditional)

Usage:

    -- Enable probes of selection defined by arguments
    Log:set({Log:sel("test_main.c","thread_A")}, 1)
    -- 1       94651015758336  T       1       0       0
    -- 2       94651015758400  T       1       0       0
    
    -- Print statuses of selection defined by arguments
    Log:p_stat("test_main.c")
    -- 1       94376905458432  T       0       0       0
    -- 2       94376905458496  T       0       0       0
    -- 3       94376905458304  T       0       0       0
    -- 4       94376905458368  T       0       0       0
    -- 5       94376905458176  T       1       405     96874004698502
    -- 6       94376905458240  T       1       406     96874009765001
    
    -- Look-up one of the log-probes from the list above
    Log:whatis(94376905458240)
    -- T       test_main.c     thread_A        59
log:set ([s=self], ctrl[, cntr[, ts=0]])
set

Set ctrl bit-mask for a selection of probe(s)

First argument can be either a table of size and selection as returned by sel or just the selection as size is implicit in the selection's base-type/class (table)

It can also be omitted, in which case the selection in self is assumed and the rest of the arguments starts at second argument.

Central operation about method is operating on groups of probes, i.e. selections. An instance of Log can have a selection (from CTOR or appended), therefore it can operate on self

Parameters:

  • s Table Log instance or Log-selection table (default self)
  • ctrl Integer Control (bit-mask). Required
  • cntr Integer Counter. (optional)
  • ts Integer Time-stamp. (default 0)

Returns:

  1. Integer Number of probes fitting selection
  2. Integer Number of probes changed

See also:

Usage:

  •  -- Class static
    tps = Log('test_main.c','thread_A')
    Log:set(tps, 1)
    Log:p_stat(tps)
  •  -- Object instances
    tps = Log('test_main.c','thread_A')
    tps:set(1)
    tps:p_stat()
    tps:set(1, 0)  -- Continue counting, reset counters but not timestamps
    tps:p_stat()
log:sel ([Instance], filename, funcname, kind[, idx1[, idx2]])

sel

Return a selection of log-probes in a table based a human-readable specifiers of source-code references.

Arguments are used to define a "selection". A "selection" is one or a group of probe-ID's having the search (or "selection") criteria in common. All arguments are optional (varargs).

  • No arguments returns all probes in a process.
  • Arguments of String-type are matched using Lua regular expressions and don't need to be exact matches. This enables generalized scripting for variants of same or similar code.

Positional argument order matters. I.e. if any preceding arguments don't need specifying (in this method meaning: "include all of what that arguments specifier stands for"), it/they still have to be passed but with the value nil.

Sub-selection argument(s) (optional): * If only one is given: A 1-element sub-selection at that index of the overall selection is returned * If both: The sub-selection is the range between the two indexes * If first index greater than last: The sub-selection is the range between the two indexes, but in reversed order.

Return is number of probes fitting selection and corresponding table with following key-values:

ptr      (Integer) Address of probe used as unique ID
kind     (String)  "T"=trace-probe, "L"=log-probe etc
filename (String)  File-name
funcname (String)  Function-name
line     (Integer) Line-number

Parameters:

  • Instance Log with selection (optional)
  • filename String
  • funcname String
  • kind String
  • idx1 Integer Start of sub-selection (optional)
  • idx2 Integer End of sub-selection (optional)

Returns:

  1. Integer Number of matches for selection
  2. Table {ID, kind, filename, funcname, line}

See also:

Usage:

     -- Make a trial selection. No or all nil arguments returns all probes
    Log:sel()
    -- 16      table: 0x7f83ecaca950
    
    n, t = Log:sel()
    -- Repeat but this time assign the result, then print the first one
    -- Note that the table returned is a 2D index-table of data-dictionaries
    print(t[1].filename, t[1].funcname, t[1].line)
    -- test_main.c     thread_A        56
log:sub ([s=self], idx1[, idx2])
sub Sub-selection of instance-selection from index range, or for singular index.

Parameters:

  • s Log Use selection from Log-instance (default self)
  • idx1 Integer Start of sub-selection
  • idx2 Integer End of sub-selection (optional)

Returns:

    Log New instance with sub-selection

Usage:

  •  -- Sub-select functions from file-selection
    m = Log('.*main.c')
    A = m:sub(1, 2)
    B = m:sub(4)
    R = m:sub(6, 5) -- reversed
    print(A + B + R)
    -- {
    --   {106297695531040,  "T",  "test_main.c",  "thread_A",  57},
    --   {106297695531104,  "T",  "test_main.c",  "thread_A",  59},
    --   {106297695531232,  "T",  "test_main.c",  "thread_B",  71},
    --   {106297695531360,  "T",  "test_main.c",  "main",  134},
    --   {106297695531296,  "T",  "test_main.c",  "main",  131}
    -- }
  •  -- Class-static usage
    m = Log('.*main.c')
    D = Log:sub(m, 2)
    print(D)
    -- {
    --   {110968930517088,  "T",  "test_main.c",  "thread_A",  59}
    -- }
log:new (arg1, funcname, kind[, idx1[, idx2]])

new

Selection or copy/cast CTOR

  • Return a new Log object of selected log-entries. Identical to sel except that the return-type is a Log-object for which methods can be applied
  • If 1:st argument is a table, return a copy, optionally with sub-selected selection

Parameters:

  • arg1 String
  • funcname String
  • kind String
  • idx1 Integer Selection start index (optional)
  • idx2 Integer Selection end index (optional)

Returns:

    Log A Log object instance

See also:

Usage:

  •  -- Instance of a selection
    a = Log('test_main.c','thread_A',nil,1)
    b = Log('test_main.c','thread_A',nil,2)
    print(a + b)
    -- {
    --   {94660412502144,  "T",  "test_main.c",  "thread_A",  56},
    --   {94660412502208,  "T",  "test_main.c",  "thread_A",  59}
    -- }
  •  -- Instance of a sub-selection of selection
    A = Log('.*main.c', nil, nil, 1, 2)
    print( A )
    -- {
    --   {106297695531040,  "T",  "test_main.c",  "thread_A",  57},
    --   {106297695531104,  "T",  "test_main.c",  "thread_A",  59}
    -- }
  •  -- First log-entry from all threads matching filenames
    th = Log('.*' , 'thread.*')
    p  = Log(th, '.*extra.*'):sub(1)
    print(p)
    -- {
    --   {106297695531808,  "T",  "test_extra_thread.c",  "thread_C",  38}
    -- }
generated by LDoc 1.5.0 Last updated 2025-03-10 21:43:19