Each database may have its own file channel configured for logging compiler messages -- either those generated by the SDK its self or by your scripts. By default, this is the "stderr" channel, but it can be any type of channel recognized by Tcl's "puts" command (such as an actual file or a memory channel using the freely-available "memchan" package). If you want, for example, messages to be sent to stderr, captured for display within your own GUI, or for each database to log to a different channel, then the database(s) can be configured to do so.
The database's log
subcommand provides a generic interface to use in generating your own messages in addition to those provided by the SDK. This allows your scripts to be written such that their messages are sent to the appropriate channel without needing to be aware of what that channel is (unlike using Tcl's puts
command).
% dbcmd log ?-nonewline? text
By default, a newline is appended to the text to be logged. The -nonewline
option may be specified to indicate that no newline should be appended.
% smilib log "hello, world!"
(What developer's guide would be complete without a "hello world" example?)
In addition to logging pre-formatted messages directly to a channel configured through the database's -logchannel
setting, the SDK can invoke a user-specified callback with details about the message as separate fields using the -logcommand
setting. Details are provided as separate fields, which can be assembled to generate messages in a desired format (such as HTML).
Callbacks take the form:
proc callback { args } { ... }
The args
parameter receives a dictionary (key+value pairs) with the following keys:
class
command
import
or validate
).line
import
command).message
msgid
record
token
import
command).type
error
or warning
).% proc onLogEvent { args } { foreach { key value } $args { puts "$key=$value" } } % smilib set -logcommand onLogEvent % smilib import -file $file command=import msgid=31 type=error class=file record=example.mib line=1851 message='StatusUpdate' is not a valid TRAP-TYPE name -- must start with a lowercase letter.