Tk Library Source Code

Artifact [02f234b3ed]
Login

Artifact 02f234b3ed6c7166035a1ce94267aab44113c9aa:

Attachment "fileAppender.diff" to ticket [1352763fff] added by aakhter 2005-11-10 09:29:03.
Index: loggerAppender.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/log/loggerAppender.tcl,v
retrieving revision 1.1
diff -c -r1.1 loggerAppender.tcl
*** loggerAppender.tcl	28 Sep 2005 21:14:31 -0000	1.1
--- loggerAppender.tcl	8 Nov 2005 16:03:49 -0000
***************
*** 280,285 ****
--- 280,397 ----
      return $procText
  }
  
+ ##Procedure Header
+ # $Id$
+ # Copyright (c) 2005 Cisco Systems, Inc.
+ #
+ # Name:
+ #       ::logger::appender::fileAppend
+ #
+ # Purpose:
+ #
+ #
+ # Synopsis:
+ #       ::logger::appender::fileAppend -level <level> -service <service> -outputChannel <channel> [options]
+ #
+ # Arguments:
+ #       -level <level>
+ #            name of level to fill in as 'priority' in log proc
+ #       -service <service>
+ #            name of service to fill in as 'category' in log proc
+ #       -appenderArgs <appenderArgs>
+ #            any additional args in list form
+ #       -conversionPattern <conversionPattern>
+ #            log pattern to use (see genLogProc)
+ #       -procName <procName>
+ #            explicitly set the proc name
+ #       -procNameVar <procNameVar>
+ #            name of variable to set in the calling context
+ #            variable has name of proc
+ #       -outputChannel <channel>
+ #            name of output channel (eg stdout, file handle)
+ #
+ #
+ # Return Values:
+ #       a runnable command
+ #
+ # Description:
+ #
+ #
+ # Examples:
+ #
+ #
+ # Notes:
+ #       1.
+ #
+ # End of Procedure Header
+ 
+ 
+ proc ::logger::appender::fileAppend {args} {
+     set usage {console
+ 	?-level level?
+ 	?-service service?
+ 	?-outputChannel channel?
+ 	?-appenderArgs appenderArgs?
+     }
+     set bargs $args
+     set conversionPattern {\[%d\] \[%c\] \[%M\] \[%p\] %m}
+     while {[llength $args] > 1} {
+ 	set opt [lindex $args 0]
+ 	set args [lrange $args 1 end]
+ 	switch  -exact -- $opt {
+ 	    -level { set level [lindex $args 0]
+ 		set args [lrange $args 1 end]
+ 	    }
+ 	    -service { set service [lindex $args 0]
+ 		set args [lrange $args 1 end]
+ 	    }
+ 	    -appenderArgs {
+ 		set appenderArgs [lindex $args 0]
+ 		set args [lrange $args 1 end]
+ 		set args [concat $args $appenderArgs]
+ 	    }
+ 	    -conversionPattern {
+ 		set conversionPattern [lindex $args 0]
+ 		set args [lrange $args 1 end]
+ 	    }
+ 	    -procName {
+ 		set procName [lindex $args 0]
+ 		set args [lrange $args 1 end]
+ 	    }
+ 	    -procNameVar {
+ 		set procNameVar [lindex $args 0]
+ 		set args [lrange $args 1 end]
+ 	    }
+ 	    -outputChannel {
+ 		set outputChannel [lindex $args 0]
+ 		set args [lrange $args 1 end]
+ 	    }
+ 	    default {
+ 		return -code error [msgcat::mc "Unknown argument: \"%s\" :\nUsage:\
+   	                 %s" $opt $usage]
+ 	    }
+ 	}
+     }
+     if {![info exist procName]} {
+ 	set procName [genProcName $bargs]
+     }
+     if {[info exist procNameVar]} {
+ 	upvar $procNameVar myProcNameVar
+     }
+     set procText \
+ 	[ ::logger::utils::createLogProc \
+ 	      -procName $procName \
+ 	      -conversionPattern $conversionPattern \
+ 	      -category $service \
+ 	      -outputChannel $outputChannel \
+ 	      -priority $level ]
+     set myProcNameVar $procName
+     return $procText
+ }
+   	 
+ 
+ 
+ 
  ##Internal Procedure Header
  # $Id: loggerAppender.tcl,v 1.1 2005/09/28 21:14:31 andreas_kupries Exp $
  # Copyright (c) 2005 Cisco Systems, Inc.
***************
*** 328,334 ****
  }
  
  
! package provide logger::appender 1.2
  
  # ;;; Local Variables: ***
  # ;;; mode: tcl ***
--- 440,446 ----
  }
  
  
! package provide logger::appender 1.3
  
  # ;;; Local Variables: ***
  # ;;; mode: tcl ***
Index: loggerUtils.man
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/log/loggerUtils.man,v
retrieving revision 1.1
diff -c -r1.1 loggerUtils.man
*** loggerUtils.man	28 Sep 2005 21:14:31 -0000	1.1
--- loggerUtils.man	8 Nov 2005 16:03:49 -0000
***************
*** 1,11 ****
  [comment {-*- tcl -*- doctools manpage}]
  [comment {$Id: loggerUtils.man,v 1.1 2005/09/28 21:14:31 andreas_kupries Exp $}]
! [manpage_begin logger::utils n 1.2]
  [copyright {2005 Aamer Akhter <[email protected]>}]
  [moddesc {Object Oriented logging facility}]
  [titledesc {Utilities for logger}]
  [require Tcl 8.2]
! [require logger::utils [opt 1.2]]
  [description]
  [keywords logger appender]
  
--- 1,11 ----
  [comment {-*- tcl -*- doctools manpage}]
  [comment {$Id: loggerUtils.man,v 1.1 2005/09/28 21:14:31 andreas_kupries Exp $}]
! [manpage_begin logger::utils n 1.3]
  [copyright {2005 Aamer Akhter <[email protected]>}]
  [moddesc {Object Oriented logging facility}]
  [titledesc {Utilities for logger}]
  [require Tcl 8.2]
! [require logger::utils [opt 1.3]]
  [description]
  [keywords logger appender]
  
***************
*** 58,63 ****
--- 58,67 ----
  
  The priority (level).
  
+ [opt_def -outputChannel channel]
+ 
+ channel to output on (default stdout)
+ 
  [list_end]
  
  
***************
*** 131,137 ****
  Example of usage:
  [nl]
  [example {
!   logger::applyAppender -appender console
    set log [logger::init applyAppender-3]
    ${log}::error "this is an error"
  }]
--- 135,141 ----
  Example of usage:
  [nl]
  [example {
!   logger::utils::applyAppender -appender console
    set log [logger::init applyAppender-3]
    ${log}::error "this is an error"
  }]
Index: loggerUtils.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/log/loggerUtils.tcl,v
retrieving revision 1.2
diff -c -r1.2 loggerUtils.tcl
*** loggerUtils.tcl	11 Oct 2005 19:49:26 -0000	1.2
--- loggerUtils.tcl	8 Nov 2005 16:03:49 -0000
***************
*** 184,189 ****
--- 184,191 ----
  #            the category (service)
  #       -priority <priority>
  #            the priority (level)
+ #       -outputChannel <channel>
+ #            channel to output on (default stdout)
  #
  #
  # Return Values:
***************
*** 294,302 ****
  
      }
  
      set formatText $text
      set outputCommand puts
-     set outputChannel stdout
  
      set procText {
  	proc $opt(-procName) {text} {
--- 296,309 ----
  
      }
  
+     if {[info exist opt(-outputChannel)]} {
+ 	set outputChannel $opt(-outputChannel)
+     } else {
+ 	set outputChannel stdout
+     }
+ 
      set formatText $text
      set outputCommand puts
  
      set procText {
  	proc $opt(-procName) {text} {
***************
*** 376,382 ****
  
  
  proc ::logger::utils::applyAppender {args} {
!     set usage {logger::applyAppender
  	-appender appender
  	?-instance?
  	?-levels levels?
--- 383,389 ----
  
  
  proc ::logger::utils::applyAppender {args} {
!     set usage {logger::utils::applyAppender
  	-appender appender
  	?-instance?
  	?-levels levels?
***************
*** 480,486 ****
  #       to autocreate appenders for newly created logger instances
  #
  # Examples:
! #	logger::applyAppender -appender console
  #	set log [logger::init applyAppender-3]
  #	${log}::error "this is error"
  #
--- 487,493 ----
  #       to autocreate appenders for newly created logger instances
  #
  # Examples:
! #	logger::utils::applyAppender -appender console
  #	set log [logger::init applyAppender-3]
  #	${log}::error "this is error"
  #
***************
*** 523,534 ****
      if {![info exist appender]} {
  	return -code error [msgcat::mc "need to specify -appender"]
      }
!     applyAppender -appender $appender -serviceCmd $log -levels $levels
      return $log
  }
  
  
! package provide logger::utils 1.2
  
  # ;;; Local Variables: ***
  # ;;; mode: tcl ***
--- 530,542 ----
      if {![info exist appender]} {
  	return -code error [msgcat::mc "need to specify -appender"]
      }
!     logger::utils::applyAppender -appender $appender -serviceCmd $log \
! 	-levels $levels -appenderArgs $appenderArgs
      return $log
  }
  
  
! package provide logger::utils 1.3
  
  # ;;; Local Variables: ***
  # ;;; mode: tcl ***
Index: loggerUtils.test
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/log/loggerUtils.test,v
retrieving revision 1.2
diff -c -r1.2 loggerUtils.test
*** loggerUtils.test	30 Sep 2005 18:05:57 -0000	1.2
--- loggerUtils.test	8 Nov 2005 16:03:49 -0000
***************
*** 226,231 ****
--- 226,247 ----
      } -match regexp \
  	-output {\[[\d:\/ ]+\] \[applyAppender-4\] \[namespace\] \[error\] this is error}
  
+     ::tcltest::test applyAppender-5 {
+ 	auto apply fileAppend
+     } -setup {
+     } -constraints {
+     } -cleanup {
+     } -body {
+ 	logger::utils::applyAppender \
+ 	    -appender fileAppend -appenderArgs {-outputChannel stderr}
+ 	set log [logger::init applyAppender-5]
+ 	${log}::error "this is error"
+     } -returnCodes {
+ 	ok
+     } -match regexp \
+ 	-errorOutput {\[[\d:\/ ]+\] \[applyAppender-5\] \[namespace\] \[error\] this is error}
+     
+ 
  }
  
  
Index: pkgIndex.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/log/pkgIndex.tcl,v
retrieving revision 1.16
diff -c -r1.16 pkgIndex.tcl
*** pkgIndex.tcl	28 Sep 2005 21:14:31 -0000	1.16
--- pkgIndex.tcl	8 Nov 2005 16:03:49 -0000
***************
*** 13,17 ****
  
  if {![package vsatisfies [package provide Tcl] 8.2]} {return}
  package ifneeded logger           0.6.1 [list source [file join $dir logger.tcl]]
! package ifneeded logger::utils    1.2   [list source [file join $dir loggerUtils.tcl]]
! package ifneeded logger::appender 1.2   [list source [file join $dir loggerAppender.tcl]]
--- 13,17 ----
  
  if {![package vsatisfies [package provide Tcl] 8.2]} {return}
  package ifneeded logger           0.6.1 [list source [file join $dir logger.tcl]]
! package ifneeded logger::utils    1.3   [list source [file join $dir loggerUtils.tcl]]
! package ifneeded logger::appender 1.3   [list source [file join $dir loggerAppender.tcl]]