Skip to content

Commit

Permalink
Use log levels (part one)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Jackson committed Sep 23, 2020
1 parent 67de1c3 commit 6086dc9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/debugserver/server.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ proc ::server::OnRequest_initialize { msg } {
dbg::initialize $libdir_

if { "-verbose" in $::argv } {
set ::dbg::debug 1
set ::dbg::logLevel ::dbg::LOGLEVEL(debug)
} else {
set ::dbg::debug 0
set ::dbg::logLevel ::dbg::LOGLEVEL(info)
}

# read client capabilities/options
Expand Down
27 changes: 17 additions & 10 deletions lib/tcldebugger/dbg.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ package require parser

namespace eval dbg {

array set LOGLEVEL {
error 0
warning 1
info 2
message 2
debug 3
DAP 4
timing 5
nub 5
}

# debugging options --
#
# Fields:
# debug Set to 1 to enable debugging output.
# logLevl Max level to output
# logFile File handle where logging messages should be written.
# logFilter List of message types to include in debugging, or empty
# list for all.

variable debug 1
variable logLevel $LOGLEVEL(info)
variable logFile stderr
variable logFilter [list]

# startup options --
#
Expand Down Expand Up @@ -1690,13 +1698,12 @@ proc dbg::Instrument {file script} {
# None.

proc dbg::Log {type message} {
variable logFilter
variable debug
variable logLevel

if {!$debug || ( [llength $logFilter] > 0 &&
[lsearch -exact $logFilter $type] == -1 ) } {
return
if { $::dbg::LOGLEVEL($type) > $logLevel } {
return
}

puts $::dbg::logFile "LOG($type,[clock clicks]): [uplevel 1 [list subst $message]]"
update idletasks
return
Expand Down

0 comments on commit 6086dc9

Please sign in to comment.