Home
You are not currently signed in.

MIB Smithy

  1. Up to Table of Contents

Logging Compiler Messages

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).

Syntax:

% 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.

Returns:

  • Nothing.

Examples - Hello World

% smilib log "hello, world!"

(What developer's guide would be complete without a "hello world" example?)

Logging Callbacks

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
The type of record the message is for (see Determing Record Types for list).
command
The command causing the message to be generated (import or validate).
line
The line number associated with the message (applies only to import command).
message
The text of the message to be generated.
msgid
An identifier that is unique to the format used to generate the message. This value essentially identifies the parser or validator rule that generated the message.
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).
type
The type of message being generated (error or warning).

Example

% 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.
  1. Up to Table of Contents