| | @@ -3,26 +3,26 @@ |
| 3 | 3 | |
| 4 | 4 | # ----------------------------------------------------------------------------- |
| 5 | 5 | # Requirements |
| 6 | 6 | |
| 7 | 7 | package require Tcl 8.4 |
| 8 | | -namespace eval ::tools::log {} |
| 8 | +namespace eval ::vc::tools::log {} |
| 9 | 9 | |
| 10 | 10 | # ----------------------------------------------------------------------------- |
| 11 | 11 | # API |
| 12 | 12 | |
| 13 | 13 | # Feedback generation. |
| 14 | 14 | # |
| 15 | | -# tools::log::write verbosity system text - Write message to the log. |
| 16 | | -# tools::log::progress verbosity system n max - Drive a progress display. |
| 15 | +# vc::tools::log::write verbosity system text - Write message to the log. |
| 16 | +# vc::tools::log::progress verbosity system n max - Drive a progress display. |
| 17 | 17 | |
| 18 | 18 | # Administrative operations. |
| 19 | 19 | # |
| 20 | | -# tools::log::verbosity level - Set the verbosity level of the application. |
| 21 | | -# tools::log::verbosity? - Query the verbosity level of the application. |
| 22 | | -# tools::log::setCmd cmdprefix - Set callback for output |
| 23 | | -# tools::log::system name - Register a system (enables tabular log formatting). |
| 20 | +# vc::tools::log::verbosity level - Set the verbosity level of the application. |
| 21 | +# vc::tools::log::verbosity? - Query the verbosity level of the application. |
| 22 | +# vc::tools::log::setCmd cmdprefix - Set callback for output |
| 23 | +# vc::tools::log::system name - Register a system (enables tabular log formatting). |
| 24 | 24 | |
| 25 | 25 | # Callback API ( Executed at the global level). |
| 26 | 26 | # |
| 27 | 27 | # cmdprefix 'write' system text |
| 28 | 28 | # cmdprefix 'progress' system n max |
| | @@ -34,11 +34,11 @@ |
| 34 | 34 | |
| 35 | 35 | # Write the message 'text' to log, for the named 'system'. The message |
| 36 | 36 | # is written if and only if the message verbosity is less or equal the |
| 37 | 37 | # chosen verbosity. A message of verbosity 0 cannot be blocked. |
| 38 | 38 | |
| 39 | | -proc ::tools::log::write {verbosity system text} { |
| 39 | +proc ::vc::tools::log::write {verbosity system text} { |
| 40 | 40 | variable loglevel |
| 41 | 41 | variable logcmd |
| 42 | 42 | variable sysfmt |
| 43 | 43 | if {$verbosity > $loglevel} return |
| 44 | 44 | uplevel #0 [linsert $logcmd end write [format $sysfmt $system] $text] |
| | @@ -47,11 +47,11 @@ |
| 47 | 47 | |
| 48 | 48 | # Similar to write, especially in the handling of the verbosity, to |
| 49 | 49 | # drive progress displays. It signals that for some long running |
| 50 | 50 | # operation we are at tick 'n' of at most 'max' ticks. |
| 51 | 51 | |
| 52 | | -proc ::tools::log::progress {verbosity system n max} { |
| 52 | +proc ::vc::tools::log::progress {verbosity system n max} { |
| 53 | 53 | variable loglevel |
| 54 | 54 | variable logcmd |
| 55 | 55 | variable sysfmt |
| 56 | 56 | if {$verbosity > $loglevel} return |
| 57 | 57 | uplevel #0 [linsert $logcmd end progress [format $sysfmt $system] $n $max] |
| | @@ -62,38 +62,38 @@ |
| 62 | 62 | # API Implementation - Administrative operations. |
| 63 | 63 | |
| 64 | 64 | # Set verbosity to the chosen 'level'. Only messages with a level less |
| 65 | 65 | # or equal to this one will be shown. |
| 66 | 66 | |
| 67 | | -proc ::tools::log::verbosity {level} { |
| 67 | +proc ::vc::tools::log::verbosity {level} { |
| 68 | 68 | variable loglevel |
| 69 | 69 | if {$level < 1} {set level 0} |
| 70 | 70 | set loglevel $level |
| 71 | 71 | return |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | # Query the currently set verbosity. |
| 75 | 75 | |
| 76 | | -proc ::tools::log::verbosity? {} { |
| 76 | +proc ::vc::tools::log::verbosity? {} { |
| 77 | 77 | variable loglevel |
| 78 | 78 | return $loglevel |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | # Set the log callback handling the actual output of messages going |
| 82 | 82 | # through the package. |
| 83 | 83 | |
| 84 | | -proc ::tools::log::setCmd {cmdprefix} { |
| 84 | +proc ::vc::tools::log::setCmd {cmdprefix} { |
| 85 | 85 | variable logcmd $cmdprefix |
| 86 | 86 | return |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | # Register a system name, to enable tabular formatting. This is done |
| 90 | 90 | # by setting up a format specifier with a proper width. This is |
| 91 | 91 | # handled in the generation command, before the output callback is |
| 92 | 92 | # invoked. |
| 93 | 93 | |
| 94 | | -proc ::tools::log::system {name} { |
| 94 | +proc ::vc::tools::log::system {name} { |
| 95 | 95 | variable sysfmt |
| 96 | 96 | variable syslen |
| 97 | 97 | |
| 98 | 98 | set nlen [string length $name] |
| 99 | 99 | if {$nlen < $syslen} return |
| | @@ -106,42 +106,42 @@ |
| 106 | 106 | # ----------------------------------------------------------------------------- |
| 107 | 107 | # Internal operations - Standard output operation |
| 108 | 108 | |
| 109 | 109 | # Dispatch to the handlers of the possible operations. |
| 110 | 110 | |
| 111 | | -proc ::tools::log::OUT {op args} { |
| 112 | | - eval [linsert $args 0 ::tools::log::OUT/$op] |
| 111 | +proc ::vc::tools::log::OUT {op args} { |
| 112 | + eval [linsert $args 0 ::vc::tools::log::OUT/$op] |
| 113 | 113 | return |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | # Write handler. Each message is a line. |
| 117 | 117 | |
| 118 | | -proc ::tools::log::OUT/write {system text} { |
| 118 | +proc ::vc::tools::log::OUT/write {system text} { |
| 119 | 119 | puts "$system $text" |
| 120 | 120 | return |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | | -# Progress handler. Using \r to return to the beginning of the current |
| 123 | +# Progress handler. Uses \r to return to the beginning of the current |
| 124 | 124 | # line without advancing. |
| 125 | 125 | |
| 126 | | -proc ::tools::log::OUT/progress {system n max} { |
| 126 | +proc ::vc::tools::log::OUT/progress {system n max} { |
| 127 | 127 | puts -nonewline "$system [format %[string length $max]s $n]/$max\r" |
| 128 | 128 | flush stdout |
| 129 | 129 | return |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | # ----------------------------------------------------------------------------- |
| 133 | 133 | |
| 134 | | -namespace eval ::tools::log { |
| 135 | | - variable loglevel 0 ; # Allow only uninteruptible messages. |
| 136 | | - variable logcmd ::tools::log::OUT ; # Standard output to stdout. |
| 137 | | - variable sysfmt %s ; # Non-tabular formatting. |
| 138 | | - variable syslen 0 ; # Ditto. |
| 134 | +namespace eval ::vc::tools::log { |
| 135 | + variable loglevel 0 ; # Allow only uninteruptible messages. |
| 136 | + variable logcmd ::vc::tools::log::OUT ; # Standard output to stdout. |
| 137 | + variable sysfmt %s ; # Non-tabular formatting. |
| 138 | + variable syslen 0 ; # Ditto. |
| 139 | 139 | |
| 140 | 140 | namespace export write progress |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | # ----------------------------------------------------------------------------- |
| 144 | 144 | # Ready |
| 145 | 145 | |
| 146 | | -package provide tools::log 1.0 |
| 146 | +package provide vc::tools::log 1.0 |
| 147 | 147 | return |
| 148 | 148 | |