log.tcl

Go to the documentation of this file.
00001 /*  log.tcl --*/
00002 /* */
00003 /*  Tcl implementation of a general logging facility*/
00004 /*  (Reaped from Pool_Base and modified to fit into tcllib)*/
00005 /* */
00006 /*  Copyright (c) 2001 by ActiveState Tool Corp.*/
00007 /*  See the file license.terms.*/
00008 
00009 package require Tcl 8
00010 package provide log 1.2
00011 
00012 /*  ### ### ### ######### ######### #########*/
00013 
00014 namespace ::log {
00015     namespace export levels lv2longform lv2color lv2priority 
00016     namespace export lv2cmd lv2channel lvCompare
00017     namespace export lvSuppress lvSuppressLE lvIsSuppressed
00018     namespace export lvCmd lvCmdForall
00019     namespace export lvChannel lvChannelForall lvColor lvColorForall
00020     namespace export log logMsg logError
00021 
00022     /*  The known log-levels.*/
00023 
00024     variable levels [list \
00025         emergency \
00026         alert \
00027         critical \
00028         error \
00029         warning \
00030         notice \
00031         info \
00032         debug]
00033 
00034     /*  Array mapping from all unique prefixes for log levels to their*/
00035     /*  corresponding long form.*/
00036 
00037     /*  *future* Use a procedure from 'textutil' to calculate the*/
00038     /*           prefixes and to fill the map.*/
00039 
00040     variable  levelMap
00041     array  levelMap =  {
00042     a       alert
00043     al      alert
00044     ale     alert
00045     aler        alert
00046     alert       alert
00047     c       critical
00048     cr      critical
00049     cri     critical
00050     crit        critical
00051     criti       critical
00052     critic      critical
00053     critica     critical
00054     critical    critical
00055     d       debug
00056     de      debug
00057     deb     debug
00058     debu        debug
00059     debug       debug
00060     em      emergency
00061     eme     emergency
00062     emer        emergency
00063     emerg       emergency
00064     emerge      emergency
00065     emergen     emergency
00066     emergenc    emergency
00067     emergency   emergency
00068     er      error
00069     err     error
00070     erro        error
00071     error       error
00072     i       info
00073     in      info
00074     inf     info
00075     info        info
00076     n       notice
00077     no      notice
00078     not     notice
00079     noti        notice
00080     notic       notice
00081     notice      notice
00082     w       warning
00083     wa      warning
00084     war     warning
00085     warn        warning
00086     warni       warning
00087     warnin      warning
00088     warning     warning
00089     }
00090 
00091     /*  Map from log-levels to the commands to execute when a message*/
00092     /*  with that level arrives in the system. The standard command for*/
00093     /*  all levels is '::log::Puts' which writes the message to either*/
00094     /*  stdout or stderr, depending on the level. The decision about the*/
00095     /*  channel is stored in another map and modifiable by the user of*/
00096     /*  the package.*/
00097 
00098     variable  cmdMap
00099     array  cmdMap =  {}
00100 
00101     variable lv
00102     foreach  lv $levels { cmdMap = ($lv) ::log::Puts}
00103     un    lv = 
00104 
00105     /*  Map from log-levels to the channels ::log::Puts shall write*/
00106     /*  messages with that level to. The map can be queried and changed*/
00107     /*  by the user.*/
00108 
00109     variable  channelMap
00110     array  channelMap =  {
00111     emergency  stderr
00112     alert      stderr
00113     critical   stderr
00114     error      stderr
00115     warning    stdout
00116     notice     stdout
00117     info       stdout
00118     debug      stdout
00119     }
00120 
00121     /*  Graphical user interfaces may want to colorize messages based*/
00122     /*  upon their level. The following array stores a map from levels*/
00123     /*  to colors. The map can be queried and changed by the user.*/
00124 
00125     variable  colorMap
00126     array  colorMap =  {
00127     emergency red
00128     alert     red
00129     critical  red
00130     error     red
00131     warning   yellow
00132     notice    seagreen
00133     info      {}
00134     debug     lightsteelblue
00135     }
00136 
00137     /*  To allow an easy comparison of the relative importance of a*/
00138     /*  level the following array maps from levels to a numerical*/
00139     /*  priority. The higher the number the more important the*/
00140     /*  level. The user cannot change this map (for now). This package*/
00141     /*  uses the priorities to allow the user to supress messages based*/
00142     /*  upon their levels.*/
00143 
00144     variable  priorityMap
00145     array  priorityMap =  {
00146     emergency 7
00147     alert     6
00148     critical  5
00149     error     4
00150     warning   3
00151     notice    2
00152     info      1
00153     debug     0
00154     }
00155 
00156     /*  The following array is internal and holds the information about*/
00157     /*  which levels are suppressed, i.e. may not be written.*/
00158     /* */
00159     /*  0 - messages with with level are written out.*/
00160     /*  1 - messages with this level are suppressed.*/
00161 
00162     variable  suppressed
00163     array  suppressed =  {
00164     emergency 0
00165     alert     0
00166     critical  0
00167     error     0
00168     warning   0
00169     notice    0
00170     info      0
00171     debug     0
00172     }
00173 
00174     /*  Internal static information. Map from levels to a string of*/
00175     /*  spaces. The number of spaces in each string is just enough to*/
00176     /*  make all level names together with their string of the same*/
00177     /*  length.*/
00178 
00179     variable  fill
00180     array  fill =  {
00181     emergency ""    alert "    "    critical " "    error "    "
00182     warning "  "    notice "   "    info "     "    debug "    "
00183     }
00184 }
00185 
00186 
00187 /*  log::levels --*/
00188 /* */
00189 /*  Retrieves the names of all known levels.*/
00190 /* */
00191 /*  Arguments:*/
00192 /*  None.*/
00193 /* */
00194 /*  Side Effects:*/
00195 /*  None.*/
00196 /* */
00197 /*  Results:*/
00198 /*  A list containing the names of all known levels,*/
00199 /*  alphabetically sorted.*/
00200 
00201 ret  ::log::levels () {
00202     variable levels
00203     return [lsort $levels]
00204 }
00205 
00206 /*  log::lv2longform --*/
00207 /* */
00208 /*  Converts any unique abbreviation of a level name to the full*/
00209 /*  level name.*/
00210 /* */
00211 /*  Arguments:*/
00212 /*  level   The prefix of a level name to convert.*/
00213 /* */
00214 /*  Side Effects:*/
00215 /*  None.*/
00216 /* */
00217 /*  Results:*/
00218 /*  Returns the full name to the specified abbreviation or an*/
00219 /*  error.*/
00220 
00221 ret  ::log::lv2longform (type level) {
00222     variable levelMap
00223 
00224     if {[info exists levelMap($level)]} {
00225     return $levelMap($level)
00226     }
00227 
00228     return -code error "\"$level\" is no unique abbreviation of a level name"
00229 }
00230 
00231 /*  log::lv2color --*/
00232 /* */
00233 /*  Converts any level name including unique abbreviations to the*/
00234 /*  corresponding color.*/
00235 /* */
00236 /*  Arguments:*/
00237 /*  level   The level to convert into a color.*/
00238 /* */
00239 /*  Side Effects:*/
00240 /*  None.*/
00241 /* */
00242 /*  Results:*/
00243 /*  The name of a color or an error.*/
00244 
00245 ret  ::log::lv2color (type level) {
00246     variable colorMap
00247     set level [lv2longform $level]
00248     return $colorMap($level)
00249 }
00250 
00251 /*  log::lv2priority --*/
00252 /* */
00253 /*  Converts any level name including unique abbreviations to the*/
00254 /*  corresponding priority.*/
00255 /* */
00256 /*  Arguments:*/
00257 /*  level   The level to convert into a priority.*/
00258 /* */
00259 /*  Side Effects:*/
00260 /*  None.*/
00261 /* */
00262 /*  Results:*/
00263 /*  The numerical priority of the level or an error.*/
00264 
00265 ret  ::log::lv2priority (type level) {
00266     variable priorityMap
00267     set level [lv2longform $level]
00268     return $priorityMap($level)
00269 }
00270 
00271 /*  log::lv2cmd --*/
00272 /* */
00273 /*  Converts any level name including unique abbreviations to the*/
00274 /*  command prefix used to write messages with that level.*/
00275 /* */
00276 /*  Arguments:*/
00277 /*  level   The level to convert into a command prefix.*/
00278 /* */
00279 /*  Side Effects:*/
00280 /*  None.*/
00281 /* */
00282 /*  Results:*/
00283 /*  A string containing a command prefix or an error.*/
00284 
00285 ret  ::log::lv2cmd (type level) {
00286     variable cmdMap
00287     set level [lv2longform $level]
00288     return $cmdMap($level)
00289 }
00290 
00291 /*  log::lv2channel --*/
00292 /* */
00293 /*  Converts any level name including unique abbreviations to the*/
00294 /*  channel used by ::log::Puts to write messages with that level.*/
00295 /* */
00296 /*  Arguments:*/
00297 /*  level   The level to convert into a channel.*/
00298 /* */
00299 /*  Side Effects:*/
00300 /*  None.*/
00301 /* */
00302 /*  Results:*/
00303 /*  A string containing a channel handle or an error.*/
00304 
00305 ret  ::log::lv2channel (type level) {
00306     variable channelMap
00307     set level [lv2longform $level]
00308     return $channelMap($level)
00309 }
00310 
00311 /*  log::lvCompare --*/
00312 /* */
00313 /*  Compares two levels (including unique abbreviations) with*/
00314 /*  respect to their priority. This command can be used by the*/
00315 /*  -command option of lsort.*/
00316 /* */
00317 /*  Arguments:*/
00318 /*  level1  The first of the levels to compare.*/
00319 /*  level2  The second of the levels to compare.*/
00320 /* */
00321 /*  Side Effects:*/
00322 /*  None.*/
00323 /* */
00324 /*  Results:*/
00325 /*  One of -1, 0 or 1 or an error. A result of -1 signals that*/
00326 /*  level1 is of less priority than level2. 0 signals that both*/
00327 /*  levels have the same priority. 1 signals that level1 has*/
00328 /*  higher priority than level2.*/
00329 
00330 ret  ::log::lvCompare (type level1 , type level2) {
00331     variable priorityMap
00332 
00333     set level1 $priorityMap([lv2longform $level1])
00334     set level2 $priorityMap([lv2longform $level2])
00335 
00336     if {$level1 < $level2} {
00337     return -1
00338     } elseif {$level1 > $level2} {
00339     return 1
00340     } else {
00341     return 0
00342     }
00343 }
00344 
00345 /*  log::lvSuppress --*/
00346 /* */
00347 /*  (Un)suppresses the output of messages having the specified*/
00348 /*  level. Unique abbreviations for the level are allowed here*/
00349 /*  too.*/
00350 /* */
00351 /*  Arguments:*/
00352 /*  level       The name of the level to suppress or*/
00353 /*          unsuppress. Unique abbreviations are allowed*/
00354 /*          too.*/
00355 /*  suppress    Boolean flag. Optional. Defaults to the value*/
00356 /*          1, which means to suppress the level. The*/
00357 /*          value 0 on the other hand unsuppresses the*/
00358 /*          level.*/
00359 /* */
00360 /*  Side Effects:*/
00361 /*  See above.*/
00362 /* */
00363 /*  Results:*/
00364 /*  None.*/
00365 
00366 ret  ::log::lvSuppress (type level , optional suppress =1) {
00367     variable suppressed
00368     set level [lv2longform $level]
00369 
00370     switch -exact -- $suppress {
00371     0 - 1 {} default {
00372         return -code error "\"$suppress\" is not a member of \{0, 1\}"
00373     }
00374     }
00375 
00376     set suppressed($level) $suppress
00377     return
00378 }
00379 
00380 /*  log::lvSuppressLE --*/
00381 /* */
00382 /*  (Un)suppresses the output of messages having the specified*/
00383 /*  level or one of lesser priority. Unique abbreviations for the*/
00384 /*  level are allowed here too.*/
00385 /* */
00386 /*  Arguments:*/
00387 /*  level       The name of the level to suppress or*/
00388 /*          unsuppress. Unique abbreviations are allowed*/
00389 /*          too.*/
00390 /*  suppress    Boolean flag. Optional. Defaults to the value*/
00391 /*          1, which means to suppress the specified*/
00392 /*          levels. The value 0 on the other hand*/
00393 /*          unsuppresses the levels.*/
00394 /* */
00395 /*  Side Effects:*/
00396 /*  See above.*/
00397 /* */
00398 /*  Results:*/
00399 /*  None.*/
00400 
00401 ret  ::log::lvSuppressLE (type level , optional suppress =1) {
00402     variable suppressed
00403     variable levels
00404     variable priorityMap
00405 
00406     set level [lv2longform $level]
00407 
00408     switch -exact -- $suppress {
00409     0 - 1 {} default {
00410         return -code error "\"$suppress\" is not a member of \{0, 1\}"
00411     }
00412     }
00413 
00414     set prio  [lv2priority $level]
00415 
00416     foreach l $levels {
00417     if {$priorityMap($l) <= $prio} {
00418         set suppressed($l) $suppress
00419     }
00420     }
00421     return
00422 }
00423 
00424 /*  log::lvIsSuppressed --*/
00425 /* */
00426 /*  Asks the package wether the specified level is currently*/
00427 /*  suppressed. Unique abbreviations of level names are allowed.*/
00428 /* */
00429 /*  Arguments:*/
00430 /*  level   The level to query.*/
00431 /* */
00432 /*  Side Effects:*/
00433 /*  None.*/
00434 /* */
00435 /*  Results:*/
00436 /*  None.*/
00437 
00438 ret  ::log::lvIsSuppressed (type level) {
00439     variable suppressed
00440     set level [lv2longform $level]
00441     return $suppressed($level)
00442 }
00443 
00444 /*  log::lvCmd --*/
00445 /* */
00446 /*  Defines for the specified level with which command to write*/
00447 /*  the messages having this level. Unique abbreviations of level*/
00448 /*  names are allowed. The command is actually a command prefix*/
00449 /*  and this facility will append 2 arguments before calling it,*/
00450 /*  the level of the message and the message itself, in this*/
00451 /*  order.*/
00452 /* */
00453 /*  Arguments:*/
00454 /*  level   The level the command prefix is for.*/
00455 /*  cmd The command prefix to use for the specified level.*/
00456 /* */
00457 /*  Side Effects:*/
00458 /*  See above.*/
00459 /* */
00460 /*  Results:*/
00461 /*  None.*/
00462 
00463 ret  ::log::lvCmd (type level , type cmd) {
00464     variable cmdMap
00465     set level [lv2longform $level]
00466     set cmdMap($level) $cmd
00467     return
00468 }
00469 
00470 /*  log::lvCmdForall --*/
00471 /* */
00472 /*  Defines for all known levels with which command to write the*/
00473 /*  messages having this level. The command is actually a command*/
00474 /*  prefix and this facility will append 2 arguments before*/
00475 /*  calling it, the level of the message and the message itself,*/
00476 /*  in this order.*/
00477 /* */
00478 /*  Arguments:*/
00479 /*  cmd The command prefix to use for all levels.*/
00480 /* */
00481 /*  Side Effects:*/
00482 /*  See above.*/
00483 /* */
00484 /*  Results:*/
00485 /*  None.*/
00486 
00487 ret  ::log::lvCmdForall (type cmd) {
00488     variable cmdMap
00489     variable levels
00490 
00491     foreach l $levels {
00492     set cmdMap($l) $cmd
00493     }
00494     return
00495 }
00496 
00497 /*  log::lvChannel --*/
00498 /* */
00499 /*  Defines for the specified level into which channel ::log::Puts*/
00500 /*  (the standard command) shall write the messages having this*/
00501 /*  level. Unique abbreviations of level names are allowed. The*/
00502 /*  command is actually a command prefix and this facility will*/
00503 /*  append 2 arguments before calling it, the level of the message*/
00504 /*  and the message itself, in this order.*/
00505 /* */
00506 /*  Arguments:*/
00507 /*  level   The level the channel is for.*/
00508 /*  chan    The channel to use for the specified level.*/
00509 /* */
00510 /*  Side Effects:*/
00511 /*  See above.*/
00512 /* */
00513 /*  Results:*/
00514 /*  None.*/
00515 
00516 ret  ::log::lvChannel (type level , type chan) {
00517     variable channelMap
00518     set level [lv2longform $level]
00519     set channelMap($level) $chan
00520     return
00521 }
00522 
00523 /*  log::lvChannelForall --*/
00524 /* */
00525 /*  Defines for all known levels with which which channel*/
00526 /*  ::log::Puts (the standard command) shall write the messages*/
00527 /*  having this level. The command is actually a command prefix*/
00528 /*  and this facility will append 2 arguments before calling it,*/
00529 /*  the level of the message and the message itself, in this*/
00530 /*  order.*/
00531 /* */
00532 /*  Arguments:*/
00533 /*  chan    The channel to use for all levels.*/
00534 /* */
00535 /*  Side Effects:*/
00536 /*  See above.*/
00537 /* */
00538 /*  Results:*/
00539 /*  None.*/
00540 
00541 ret  ::log::lvChannelForall (type chan) {
00542     variable channelMap
00543     variable levels
00544 
00545     foreach l $levels {
00546     set channelMap($l) $chan
00547     }
00548     return
00549 }
00550 
00551 /*  log::lvColor --*/
00552 /* */
00553 /*  Defines for the specified level the color to return for it in*/
00554 /*  a call to ::log::lv2color. Unique abbreviations of level names*/
00555 /*  are allowed.*/
00556 /* */
00557 /*  Arguments:*/
00558 /*  level   The level the color is for.*/
00559 /*  color   The color to use for the specified level.*/
00560 /* */
00561 /*  Side Effects:*/
00562 /*  See above.*/
00563 /* */
00564 /*  Results:*/
00565 /*  None.*/
00566 
00567 ret  ::log::lvColor (type level , type color) {
00568     variable colorMap
00569     set level [lv2longform $level]
00570     set colorMap($level) $color
00571     return
00572 }
00573 
00574 /*  log::lvColorForall --*/
00575 /* */
00576 /*  Defines for all known levels the color to return for it in a*/
00577 /*  call to ::log::lv2color. Unique abbreviations of level names*/
00578 /*  are allowed.*/
00579 /* */
00580 /*  Arguments:*/
00581 /*  color   The color to use for all levels.*/
00582 /* */
00583 /*  Side Effects:*/
00584 /*  See above.*/
00585 /* */
00586 /*  Results:*/
00587 /*  None.*/
00588 
00589 ret  ::log::lvColorForall (type color) {
00590     variable colorMap
00591     variable levels
00592 
00593     foreach l $levels {
00594     set colorMap($l) $color
00595     }
00596     return
00597 }
00598 
00599 /*  log::logarray --*/
00600 /* */
00601 /*  Similar to parray, except that the contents of the array*/
00602 /*  printed out through the log system instead of directly*/
00603 /*  to stdout.*/
00604 /* */
00605 /*  See also 'log::log' for a general explanation*/
00606 /* */
00607 /*  Arguments:*/
00608 /*  level       The level of the message.*/
00609 /*  arrayvar    The name of the array varaibe to dump*/
00610 /*  pattern     Optional pattern to restrict the dump*/
00611 /*          to certain elements in the array.*/
00612 /* */
00613 /*  Side Effects:*/
00614 /*  See above.*/
00615 /* */
00616 /*  Results:*/
00617 /*  None.*/
00618 
00619 ret  ::log::logarray (type level , type arrayvar , optional pattern =*) {
00620     variable cmdMap
00621 
00622     if {[lvIsSuppressed $level]} {
00623     # Ignore messages for suppressed levels.
00624     return
00625     }
00626 
00627     set level [lv2longform $level]
00628 
00629     set cmd $cmdMap($level)
00630     if {$cmd == {}} {
00631     # Ignore messages for levels without a command
00632     return
00633     }
00634 
00635     upvar 1 $arrayvar array
00636     if {![array exists array]} {
00637         error "\"$arrayvar\" isn't an array"
00638     }
00639     set maxl 0
00640     foreach name [lsort [array names array $pattern]] {
00641         if {[string length $name] > $maxl} {
00642             set maxl [string length $name]
00643         }
00644     }
00645     set maxl [expr {$maxl + [string length $arrayvar] + 2}]
00646     foreach name [lsort [array names array $pattern]] {
00647         set nameString [format %s(%s) $arrayvar $name]
00648 
00649     eval [linsert $cmd end $level \
00650         [format "%-*s = %s" $maxl $nameString $array($name)]]
00651     }
00652     return
00653 }
00654 
00655 /*  log::loghex --*/
00656 /* */
00657 /*  Like 'log::log', except that the logged data is assumed to*/
00658 /*  be binary and is logged as a block of hex numbers.*/
00659 /* */
00660 /*  See also 'log::log' for a general explanation*/
00661 /* */
00662 /*  Arguments:*/
00663 /*  level   The level of the message.*/
00664 /*  text    Message printed before the hex block*/
00665 /*  data    Binary data to show as hex.*/
00666 /* */
00667 /*  Side Effects:*/
00668 /*  See above.*/
00669 /* */
00670 /*  Results:*/
00671 /*  None.*/
00672 
00673 ret  ::log::loghex (type level , type text , type data) {
00674     variable cmdMap
00675 
00676     if {[lvIsSuppressed $level]} {
00677     # Ignore messages for suppressed levels.
00678     return
00679     }
00680 
00681     set level [lv2longform $level]
00682 
00683     set cmd $cmdMap($level)
00684     if {$cmd == {}} {
00685     # Ignore messages for levels without a command
00686     return
00687     }
00688 
00689     # Format the messages and print them.
00690 
00691     set len [string length $data]
00692 
00693     eval [linsert $cmd end $level "$text ($len bytes):"]
00694 
00695     set address ""
00696     set hexnums ""
00697     set ascii   ""
00698 
00699     for {set i 0} {$i < $len} {incr i} {
00700         set v [string index $data $i]
00701         binary scan $v H2 hex
00702         binary scan $v c  num
00703         set num [expr {($num + 0x100) % 0x100}]
00704 
00705         set text .
00706         if {$num > 31} {set text $v} 
00707 
00708         if {($i % 16) == 0} {
00709             if {$address != ""} {
00710                 eval [linsert $cmd end $level [format "%4s  %-48s  |%s|" $address $hexnums $ascii]]
00711                 set address ""
00712                 set hexnums ""
00713                 set ascii   ""
00714             }
00715             append address [format "%04d" $i]
00716         }
00717         append hexnums "$hex "
00718         append ascii   $text
00719     }
00720     if {$address != ""} {
00721     eval [linsert $cmd end $level [format "%4s  %-48s  |%s|" $address $hexnums $ascii]]
00722     }
00723     eval [linsert $cmd end $level ""]
00724     return
00725 }
00726 
00727 /*  log::log --*/
00728 /* */
00729 /*  Log a message according to the specifications for commands,*/
00730 /*  channels and suppression. In other words: The command will do*/
00731 /*  nothing if the specified level is suppressed. If it is not*/
00732 /*  suppressed the actual logging is delegated to the specified*/
00733 /*  command. If there is no command specified for the level the*/
00734 /*  message won't be logged. The standard command ::log::Puts will*/
00735 /*  write the message to the channel specified for the given*/
00736 /*  level. If no channel is specified for the level the message*/
00737 /*  won't be logged. Unique abbreviations of level names are*/
00738 /*  allowed. Errors in the actual logging command are *not**/
00739 /*  catched, but propagated to the caller, as they may indicate*/
00740 /*  misconfigurations of the log facility or errors in the callers*/
00741 /*  code itself.*/
00742 /* */
00743 /*  Arguments:*/
00744 /*  level   The level of the message.*/
00745 /*  text    The message to log.*/
00746 /* */
00747 /*  Side Effects:*/
00748 /*  See above.*/
00749 /* */
00750 /*  Results:*/
00751 /*  None.*/
00752 
00753 ret  ::log::log (type level , type text) {
00754     variable cmdMap
00755 
00756     if {[lvIsSuppressed $level]} {
00757     # Ignore messages for suppressed levels.
00758     return
00759     }
00760 
00761     set level [lv2longform $level]
00762 
00763     set cmd $cmdMap($level)
00764     if {$cmd == {}} {
00765     # Ignore messages for levels without a command
00766     return
00767     }
00768 
00769     # Delegate actual logging to the command.
00770     # Handle multi-line messages correctly.
00771 
00772     foreach line [split $text \n] {
00773     eval [linsert $cmd end $level $line]
00774     }
00775     return
00776 }
00777 
00778 /*  log::logMsg --*/
00779 /* */
00780 /*  Convenience wrapper around ::log::log. Equivalent to*/
00781 /*  '::log::log info text'.*/
00782 /* */
00783 /*  Arguments:*/
00784 /*  text    The message to log.*/
00785 /* */
00786 /*  Side Effects:*/
00787 /*  See ::log::log.*/
00788 /* */
00789 /*  Results:*/
00790 /*  None.*/
00791 
00792 ret  ::log::logMsg (type text) {
00793     log info $text
00794 }
00795 
00796 /*  log::logError --*/
00797 /* */
00798 /*  Convenience wrapper around ::log::log. Equivalent to*/
00799 /*  '::log::log error text'.*/
00800 /* */
00801 /*  Arguments:*/
00802 /*  text    The message to log.*/
00803 /* */
00804 /*  Side Effects:*/
00805 /*  See ::log::log.*/
00806 /* */
00807 /*  Results:*/
00808 /*  None.*/
00809 
00810 ret  ::log::logError (type text) {
00811     log error $text
00812 }
00813 
00814 
00815 /*  log::Puts --*/
00816 /* */
00817 /*  Standard log command, writing messages and levels to*/
00818 /*  user-specified channels. Assumes that the supression checks*/
00819 /*  were done by the caller. Expects full level names,*/
00820 /*  abbreviations are *not allowed*.*/
00821 /* */
00822 /*  Arguments:*/
00823 /*  level   The level of the message. */
00824 /*  text    The message to log.*/
00825 /* */
00826 /*  Side Effects:*/
00827 /*  Writes into channels.*/
00828 /* */
00829 /*  Results:*/
00830 /*  None.*/
00831 
00832 ret  ::log::Puts (type level , type text) {
00833     variable channelMap
00834     variable fill
00835 
00836     set chan $channelMap($level)
00837     if {$chan == {}} {
00838     # Ignore levels without channel.
00839     return
00840     }
00841 
00842     puts $chan "$level$fill($level) $text"
00843     return
00844 }
00845 
00846 /*  ### ### ### ######### ######### #########*/
00847 /*  Initialization code. Disable logging for the lower levels by*/
00848 /*  default.*/
00849 
00850 /*  log::lvSuppressLE emergency*/
00851 log::lvSuppressLE warning
00852 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1