From 6b92eaeb72848bb82826716a7a18f3291042db19 Mon Sep 17 00:00:00 2001 From: andreas_kupries Date: Thu, 5 Nov 2009 20:26:24 +0000 Subject: * library/safe.tcl: A series of patches which bring the SafeBase up to date with code guidelines, Tcl's features, also eliminating a number of inefficiencies along the way. (9) Changed the log command setup so that logging is compiled out completely when disabled (default). --- ChangeLog | 2 ++ library/safe.tcl | 43 +++++++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3608d79..1663363 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,8 @@ path <-> token conversions. Removed more procedures not used any longer. Removed the test cases 4.3 and 4.4 from safe.test. They were testing the now deleted command "InterpStateName". + (9) Changed the log command setup so that logging is compiled out + completely when disabled (default). 2009-11-02 Kevin B. Kenny diff --git a/library/safe.tcl b/library/safe.tcl index db4a41b..dc50e52 100644 --- a/library/safe.tcl +++ b/library/safe.tcl @@ -12,7 +12,7 @@ # See the file "license.terms" for information on usage and redistribution of # this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: safe.tcl,v 1.27 2009/11/05 20:15:36 andreas_kupries Exp $ +# RCS: @(#) $Id: safe.tcl,v 1.28 2009/11/05 20:26:25 andreas_kupries Exp $ # # The implementation is based on namespaces. These naming conventions are @@ -542,13 +542,28 @@ proc ::safe::interpDelete {slave} { proc ::safe::setLogCmd {args} { variable Log - if {[llength $args] == 0} { + set la [llength $args] + if {$la == 0} { return $Log - } elseif {[llength $args] == 1} { + } elseif {$la == 1} { set Log [lindex $args 0] } else { set Log $args } + + if {$Log eq ""} { + # Disable logging completely. Calls to it will be compiled out + # of all users. + proc ::safe::Log {args} {} + } else { + # Activate logging, define proper command. + + proc ::safe::Log {slave msg {type ERROR}} { + variable Log + {*}$Log "$type for slave $slave : $msg" + return + } + } } # ------------------- END OF PUBLIC METHODS ------------ @@ -617,17 +632,6 @@ proc ::safe::TranslatePath {slave path} { return [string map $state(access_path,map) $path] } - -# Log eventually log an error; to enable error logging, set Log to {puts -# stderr} for instance -proc ::safe::Log {slave msg {type ERROR}} { - variable Log - if {[info exists Log] && [llength $Log]} { - {*}$Log "$type for slave $slave : $msg" - } -} - - # file name control (limit access to files/resources that should be a # valid tcl source file) proc ::safe::CheckFileName {slave file} { @@ -999,6 +1003,17 @@ proc ::safe::Setup {} { # temp not needed anymore ::tcl::OptKeyDelete $temp + #### + # + # Default: No logging. + # + #### + + setLogCmd {} + + # Log eventually. + # To enable error logging, set Log to {puts stderr} for instance, + # via setLogCmd. return } -- cgit v0.12