Reputation: 943
Here is the important part of my code:
set message_initialization_result ""
proc logMessage {msg} {
upvar outputtext outputtext
if { [string length $outputtext] > 0 } {
if { [string length $msg] > 0 } {
$outputtext insert end $msg
$outputtext insert end "\n\n"
}
}
}
proc handler { sock type msg } {
upvar outputtext outputtext
upvar message_initialization_result message_initialization_result
if {[catch {
switch -glob -nocase -- $type {
co* {
logMessage "Connected on $sock"
}
te* {
logMessage "Received:\n$msg"
}
cl* -
dis* {
logMessage "Disconnected"
}
}
}]} {
set message_initialization_result "$message_initialization_result handler"
}
}
set sock [::websocket::open ws://127.0.0.1:10010 handler]
...
logMessage $message_initialization_result
outputtext
is a variable that holds a text widget.
How do I get the handler to print the messages it receives to that text widget?
And how can I check if this handler is called at all? I tried provoking errors but it seems that they are all caught by a catch
inside the websocket library.
Upvotes: 0
Views: 144
Reputation: 13282
I'm collecting a couple of points for posterity...
puts [info level 0]
to the beginning of those procedures you want to track. In this way you get to see every time the procedure is called, and what arguments it received.puts
, try opening the Tk console with console show
.fileutil
, the command ::fileutil::appendToFile log.txt $msg
is perfect for light logging. Check out the options to the command.fileutil
? Try set f [open log.txt a] ; puts $f $msg ; close $f
. Opening and closing the file every time keeps it flushed and means you don't need as much of intrusive injections and synchronizations.Documentation: close, console, fileutil (package), info, open, puts, set
Upvotes: 1