# # logtochannel.test -- # nca-073-9 # # Copyright (c) 1996-2000 by Netcetera AG. # Copyright (c) 2001 by Apache Software Foundation. # All rights reserved. # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # # @(#) $Id$ # if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest namespace import ::tcltest::* } # ----------------------------------------------------------------------------- # try to log to a channel (which is actually an open file) # ----------------------------------------------------------------------------- test logToChannel-1.1 {websh3_weblog: add dest} { web::logdest delete set res [web::logdest add tochannel.-debug channel -unbuffered stdout] } {logdest0} test logToChannel-1.1 {websh3_weblog: use file} { set res "Failed" web::loglevel delete web::logdest delete web::loglevel add tochannel.alert-info set curTim [clock seconds] set fileName "tochannel-[info hostname]-$curTim-[pid].dat" set fileId [open $fileName "a"] set res [web::logdest add tochannel.-debug channel -unbuffered $fileId] web::log tochannel.info ">>> T E S T <<< $curTim" web::loglevel delete web::logdest delete close $fileId # and see if you find it in the file if {[file exists $fileName] } { set fileId [open $fileName "r"] while {[eof $fileId] == 0} { gets $fileId tLine set pat "*$curTim*" if { [string match $pat $tLine] == 1 } { set res "Ok" break } } ## close and delete close $fileId file delete $fileName } set res } {Ok} test logToChannel-2.1 {closed channel} { web::logdest delete web::loglevel delete set fileName "tochannel-2.1-[pid].dat" set fh [open $fileName "a"] web::logdest add *.-debug channel -unbuffered $fh web::loglevel add *.-debug web::log debug "Hi there" flush $fh close $fh set msg "" web::config safelog 0 set c [catch {web::log debug "Bye there"} msg] web::config safelog 1 set c2 [catch {web::log debug "Safe Bye"} msg] set res [web::log debug "Safe Bye 2"] web::readfile $fileName log file delete $fileName regsub -all {.*debug: } $log "" log regsub -all {\".*\"} $msg {"channel"} msg regsub -all {\".*\"} $res {"channel"} res set res "$c - $c2 - $log$msg\n$res" } {1 - 0 - Hi there can not find channel named "channel" can not find channel named "channel"} # cleanup ::tcltest::cleanupTests