| < Prev | Back to Table of Contents | Next > |
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.
Nothing.
% 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:
| Key | Description |
|---|---|
command |
The command causing the message to be generated (import or validate). |
type |
The type of message being generated (error or warning). |
class |
The type of record the message is for (see Determing Record Types for list). |
record |
The fully-qualified name of the record the message applies to. |
token |
The parser token associated with the message, if any (applies only to the import command). |
line |
The line number associated with the message (applies only to import command). |
message |
The text of the message to be generated. |
% proc onLogEvent { args } {
foreach { key value } $args {
puts "$key=$value"
}
}
% smilib set -logcommand onLogEvent
% smilib import -file $file
command=import
type=error
class=file
record=example.mib
line=1851
message='StatusUpdate' is not a valid TRAP-TYPE name -- must start with a lowercase letter.
| < Prev | Back to Table of Contents | Next > |