New basic logging module using kx.log as reference#90
Open
DI-Dexter wants to merge 2 commits intoDataIntellectTech:mainfrom
Open
New basic logging module using kx.log as reference#90DI-Dexter wants to merge 2 commits intoDataIntellectTech:mainfrom
DI-Dexter wants to merge 2 commits intoDataIntellectTech:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Log
log.qis the default logging implementation fordi.*modules. It writes formatted lines to stdout and satisfies the log dependency contract expected by modules such asdi.email.Usage
Output format:
Injecting into other modules
All
di.*modules that accept a log dependency expect a dictionary with keys`info`warn`error, each a function with signature{[ctx;msg]}.You can extend the injected dictionary with
trace,debug, andfatalfor modules that support them:createLog
createLogis a factory that returns an independent logger instance with level filtering, multiple output sinks, and configurable format templates. Each call tocreateLogproduces a separate instance with its own state.Sinks
A sink is a handle (integer file descriptor or function) passed to
add. If a function is provided it is called with the formatted line string. Built-in handles follow standard q conventions:1iis stdout,2iis stderr.Format templates
Three built-in formats are available:
basic(default)$p $l PID[$i] HOST[$h] $m2026-04-09T12:00:00.000000000 INFO PID[1234] HOST[myhost] messagesyslog<$s> $m<6> messageraw$mmessageTemplate variables:
$ptimestamp,$llevel,$iPID,$hhostname,$mmessage,$ssyslog severity number.API
traceParameters:
[ctx; msg]Write a trace-level message to stdout.
ctx— symbol context tag (e.g.`mymodule)msg— string messagedebugParameters:
[ctx; msg]Write a debug-level message to stdout.
infoParameters:
[ctx; msg]Write an info-level message to stdout.
warnParameters:
[ctx; msg]Write a warning-level message to stdout.
errorParameters:
[ctx; msg]Write an error-level message to stdout.
fatalParameters:
[ctx; msg]Write a fatal-level message to stdout.
createLogParameters: none
Returns an independent logger instance as a dictionary of functions. Each call returns a new instance with isolated state.
Returned keys:
`trace`debug`info`warn`error`fatal`add`remove`setfmt`getfmt`addfmt`setlvl`getlvltrace..fatal[msg]setlvl[lvl]`trace`debug`info`warn`error`fatalgetlvl[_]setfmt[name]getfmt[_]addfmt[name;template]add[handle;lvls]remove[handle;lvl]Log dependency contract
The log dependency contract used across
di.*modules requires a dictionary:di.logsatisfies this contract. You can also supply any custom implementation with the same signatures.