| Store | Cart

Re: [TCLCORE] TIP #390: A Logging API for Tcl

From: Rene Zaumseil <r.za...@web.de>
Tue, 1 Nov 2011 13:52:39 +0100
Hi,

I already use my own log function in realtime simulations.
It is a special field but can give some additional ideas.
The implementation is thread safe. Because of the general
purpose the C-functions do not require a tcl-interpreter.

Internal data as a global structure contain informations about the used
log levels:

- bitmask of used level
- format character, level text and used formatting of output
  Upper and lower case letters produce the same output.
  Upper case letter set also the current time.
  a|A -- '=== level date time.usec file +line function() === ...'
  b|B -- '=== level date time file +line function() === ...'
  c|C -- '=== level time.usec file +line function() === ...'
  d|D -- '=== level time file +line function() === ...'
  e|E -- '=== level time.usec file === ...'
  f|F -- '=== level time file === ...'
  g|G -- '=== level time.usec function() === ...'
  h|H -- '=== level time function() === ...'
  i|I -- '=== level date time.usec === ...'
  j|J -- '=== level date time === ...'
  k|K -- '=== level time.usec === ...'
  l|L -- '=== level time === ...'
  m|M -- '=== date time.usec === ...'
  n|N -- '=== date time === ...'
  o|O -- '=== time.usec === ...'
  p|P -- '=== time === ...'
  q|Q -- 'level time.usec ...'
  r|R -- 'level time ...'
  s|S -- 'time.usec ...'
  t|T -- 'time ...'
  '?' -- 'level ...'
  '=' -- '=== ...'
  '-' -- '--- ...'
  '_' -- '...' print only text
  ' ' -- disable output of given 'level'
- file descriptor and file name
  Support for stout/stderr and files. Special handling of system logs
  should also be possible.
- date and time
  These values can be set with a special function or using the upper case
  format characters. In the first case you get the same time for one
  simulation step.
- tcl list object containing messages
  If a format character is specified and the file descriptor is not definied
  then all messages saved in this variable and can be retrieved using a
  function.

Functions on the C-level:

- Write a single message.
  z_log(uint32_t level, const char *file, int line, const char *func,
  const char *format, ...)
  With a macro the actual call is then p.e.:
  #define Z_LOG_EMR     0,__FILE__,__LINE__,__func__
  z_log(Z_LOG_EMR,"my message");
- Configure one single log level
  z_log_conf(uint32_t level, char levelformat, char *file, char *leveltext)
- Set current time.
  z_log_time(char mode, Tcl_Time * time, struct tm *date)
  'mode' is used as:
  ' '    intern setting without locking
  'n'ew  setting all values
  't'ime set time value from call parameter
  'd'ate set data value from call parameter
  'b'oth set time and date values from call parameter

Functions on the tcl level:

If the C-level implementation is not available the following
tcl procs are defined:
  proc ::z::log_history {}
  proc ::z::log_time {}
  proc ::z::log_conf {level {format { }} {file {.}} {text {}}}
  proc ::z::log_puts {level file line func text}
The real log function is then:
  proc ::z::log {level text} {
    set myDict [info frame -1]
    set myType [dict get $myDict type]
    if {$myType eq {source}} {
      ::z::log_puts $level [dict get $myDict file] [dict get $myDict line\
        [dict get $myDict proc] $text
    } else {
      ::z::log_puts $level [info script] 0 $myType $text
    }
  }
With some sugar for the end user:
  interp alias {} ::z::log::emr {} ::z::log 0


Regards
rene

------------------------------------------------------------------------------
RSA&reg; Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Tcl-Core mailing list
Tcl-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-core

Recent Messages in this Thread
Rene Zaumseil Nov 01, 2011 12:52 pm