eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'MiniLogger':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: MiniLogger


Inheritance:

   Object
   |
   +--MiniLogger
      |
      +--UnixSyslogInterface

Package:
stx:libbasic
Category:
System-Debugging-Support
Version:
rev: 1.67 date: 2019/08/05 19:14:19
user: stefan
file: MiniLogger.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Jan Vrany <jan.vrany@fit.cvut.cz>

Description:


A very simple logger for Smalltalk/X. This one is always present.
It mimics the protocol of the loggers found in stx:goodies/loggia,
which can be activated by setting the global 'Logger' to an instance of
one of them.

All
    'Transcript show: 'Processor [info]: xxx'
should be rewritten over time to use the Logger.

'Object infoPrint' and 'Object debugPrint' have been changed to
forward their messages to the global 'Logger' if not nil.

Usage:
    Logger info: 'Hello world'.
    Logger debug: 'Hello world'.
    Logger warning: 'Hello world'.
    Logger error: 'Hello world'.

to disable logging:
    MiniLogger logOnTranscript:false.
    MiniLogger logOnStderr:false.

for selective logging:
    Logger loggingThreshold: Logger severityALL.
    Logger loggingThreshold: Logger severityINFO.
    Logger loggingThreshold: Logger severityNONE.

ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

The following keywords are expanded in the message:
    'LINE'      linenumber in the sending method
    'RECEIVER'  printstring of receiver in sending context
    'CLASS'     class of receiver in sending context
    'MCLASS'    class of sendig method
    'SELECTOR'  selector of sending method
    'WHO'       who-string of sending method
    'WHERE'     who-string plus linenumber of sending method

i.e.
    Logger info:'%(WHERE) - some message here'

For more examples, see #examples.


[instance variables:]

[class variables:]


Related information:

    Loggia
    logging
    framework
    [stx]

Class protocol:

accessing-log format
o  logFormat
will be used for the log message as:
%1 [%2] (%3): %4
with %1: facility (area)
with %2: secerity (area)
with %3: timestamp
with %4: caller/originator
with %5: message

usage example(s):

     MiniLogger logFormat:'%1 [%2]: %5'.
     'hello' errorPrintCR.
     MiniLogger logFormat:'%3 %1 [%2]: %5'.
     'hello' errorPrintCR.
     MiniLogger logFormat:nil.
     'hello' errorPrintCR.

o  logFormat: aFormatString
will be used for the log message as:
%1 [%2] (%3): %4
with %1: facility (area)
with %2: secerity (area)
with %3: timestamp
with %4: caller/originator
with %5: message.
Pass anil argument to return to the default format.

usage example(s):

     MiniLogger logFormat:'%1 [%2]: %5'.
     'hello' errorPrintCR.
     MiniLogger logFormat:'%3 %1 [%2]: %5'.
     'hello' errorPrintCR.
     MiniLogger logFormat:nil.
     'hello' errorPrintCR.

o  logOnStderr

o  logOnStderr: aBoolean
enable/disable logging on stderr

usage example(s):

     MiniLogger logOnStderr:false
     MiniLogger logOnTranscript:false

     MiniLogger logOnStderr:true
     MiniLogger logOnTranscript:true

o  logOnTranscript

o  logOnTranscript: aBoolean
enable/disable logging on the Transcript

usage example(s):

     MiniLogger logOnStderr:false
     MiniLogger logOnTranscript:false

     MiniLogger logOnStderr:true
     MiniLogger logOnTranscript:true

o  timestampFormat
will be used for the log message

o  timestampFormat: aTimestampFormatString
will be used for the log message

accessing-severities
o  severities
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

o  severityDEBUG
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

o  severityENTER
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

o  severityERROR
setting this as treshold will print errors

o  severityFATAL
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

o  severityINFO
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

o  severityLEAVE
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

o  severityTRACE
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

o  severityTRACE0
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

o  severityTRACE1
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

o  severityTRACE2
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

o  severityTRACE3
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

o  severityWARN
setting this as treshold will print warnings and errors

accessing-severities-special
o  severityALL
setting this as treshold will print all

o  severityNONE
setting this as treshold will suppress all logging

configuration
o  loggingThreshold
Return the logging threshold.
No messages with severity lower than threshold will be logged.
The default is
InfoPrinting ifTrue:[INFO] ifFalse:[WARN]
meaning that by default, no trace and debug logs are generated.

usage example(s):

     self loggingThreshold:INFO.
     self trace:'blabla'.
     self loggingThreshold:TRACE.
     self trace:'blabla'.
     self loggingThreshold:INFO.

o  loggingThreshold: severity
Sets logging threshold.
All severities higher or equal to the given one will be logged.
Use `Logger severityNONE` to suppress logging completely
or `Logger severityALL` to log all messages.
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

usage example(s):

    Logger loggingThreshold: Logger severityALL.
    Logger loggingThreshold: Logger severityINFO.
    Logger loggingThreshold: Logger severityDEBUG.  -- only debug, warnings and errors 
    Logger loggingThreshold: Logger severityWARN.   -- only warnings and errors 
    Logger loggingThreshold: Logger severityERROR.  -- only errors
    
    Logger loggingThreshold: Logger severityNONE.

o  loggingThreshold: aLimitOrNil forClass: aClass
allows individual per-class setting of the threshold (useful during debugging).
With a nil limit, the default is reinstalled for that class.
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

usage example(s):

     Logger severityThresholdOf: Object
     Logger severityThresholdOf: Expecco::Browser

     Logger loggingThreshold:(Logger severityDEBUG) forClass:(Expecco::Browser).
     Logger loggingThreshold:(Logger severityDEBUG) forPackage:'stx:libbasic'.
     Logger loggingThreshold:(Logger severityDEBUG) forPackage:'exept:workflow'.

     Logger loggingThreshold:nil forClass:(Expecco::Browser).
     Logger loggingThreshold:nil forPackage:'stx:libbasic'.

o  loggingThreshold: aLimitOrNil forPackage: aPackageName
allows individual per-package setting of the threshold (useful during debugging).
With a nil limit, the default is reinstalled for that class.
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE

usage example(s):

     Logger severityThresholdOf: Object
     Logger severityThresholdOf: Expecco::Browser

     Logger loggingThreshold:(Logger severityDEBUG) forClass:(Expecco::Browser).
     Logger loggingThreshold:(Logger severityDEBUG) forPackage:'stx:libbasic'.
     Logger loggingThreshold:(Logger severityDEBUG) forPackage:'exept:workflow'.

     Logger loggingThreshold:nil forClass:(Expecco::Browser).
     Logger loggingThreshold:nil forPackage:'stx:libbasic'.

initialization
o  initialize
(comment from inherited method)
called only once - initialize signals

logging
o  log: message

o  log: message facility: facility

o  log: message severity: severity

o  log: message severity: severity attachment: attachment

o  log: message severity: severity facility: facility

o  log: message severity: severity facility: facility originator: originator

o  log: message severity: severity originator: originatorOrNil

logging - basic
o  log: message severity: severity facility: facilityArg originator: originator attachment: attachment
Pricipal logging method. This mimics VM __stxLog__()

usage example(s):

self log: 'using symbols as severity is deprecated, use Logger severityXXX to get severity object' severity: WARN facility: 'STX' originator: self.

usage example(s):

self log: 'caller is ', caller printString severity: INFO facility: 'STX' originator: self.

usage example(s):

     Logger log:'test message' severity:self severityINFO facility: 'TEST'
     Logger log:'test message' severity:#info facility: 'TEST'
     Logger log:'test message' severity:#bla facility: 'TEST'
     Logger log:'test message' severity:123 facility: 'TEST'

     Logger log:'test message' severity: DEBUG facility: 'TEST'
     Logger log:'test message' severity: INFO facility: 'TEST'
     Logger log:'test message' asUnicode16String severity: INFO facility: 'TEST'
     Logger log:'test message äöüß' severity: INFO facility: 'TEST'
     Logger log:'test message' severity: WARNING facility: 'TEST'
     Logger log:'test message' severity: ERROR facility: 'TEST'
     'test message' infoPrintCR
     'test message' errorPrintCR

logging - utils
o  debug: message
generate a 'debug'-log

o  debug: format with: arg1
generate a 'debug'-log

o  debug: format with: arg1 with: arg2
generate a 'debug'-log

o  debug: format with: arg1 with: arg2 with: arg3
generate a 'debug'-log

o  debug: format withArguments: arg1
generate a 'debug'-log

o  enter: message
generate an 'entering method...'-log

o  enter: format with: arg1
generate an 'entering method...'-log

o  enter: format with: arg1 with: arg2
generate an 'entering method...'-log

o  enter: format with: arg1 with: arg2 with: arg3
generate an 'entering method...'-log

o  enter: format withArguments: arg1
generate an 'entering method...'-log

o  error: message
generate an 'error'-log

o  error: format with: arg1
generate an 'error'-log

o  error: format with: arg1 with: arg2
generate an 'error'-log

o  error: format with: arg1 with: arg2 with: arg3
generate an 'error'-log

o  error: format withArguments: arg1
generate an 'error'-log

o  fatal: message
generate a 'fatal'-log

o  fatal: format with: arg1
generate a 'fatal'-log

o  fatal: format with: arg1 with: arg2
generate a 'fatal'-log

o  fatal: format with: arg1 with: arg2 with: arg3
generate a 'fatal'-log

o  fatal: format withArguments: arg1
generate a 'fatal'-log

o  info: message
generate an 'info'-log

o  info: format with: arg1
generate an 'info'-log

o  info: format with: arg1 with: arg2
generate an 'info'-log

o  info: format with: arg1 with: arg2 with: arg3
generate an 'info'-log

o  info: format with: arg1 with: arg2 with: arg3 with: arg4
generate an 'info'-log

o  info: format withArguments: arg1
generate an 'info'-log

o  leave: message
generate a 'leaving method...'-log

o  leave: format with: arg1
generate a 'leaving method...'-log

o  leave: format with: arg1 with: arg2
generate a 'leaving method...'-log

o  leave: format with: arg1 with: arg2 with: arg3
generate a 'leaving method...'-log

o  leave: format withArguments: arg1
generate a 'leaving method...'-log

o  trace0: message
generate a 'debug trace'-log

o  trace0: format with: arg1
generate a 'debug trace'-log

o  trace0: format with: arg1 with: arg2
generate a 'debug trace'-log

o  trace0: format with: arg1 with: arg2 with: arg3
generate a 'debug trace'-log

o  trace1: message
a quick rejector to avoid overhead in deployed apps

o  trace1: format with: arg1
a quick rejector to avoid overhead in deployed apps

o  trace1: format with: arg1 with: arg2
a quick rejector to avoid overhead in deployed apps

o  trace1: format with: arg1 with: arg2 with: arg3
a quick rejector to avoid overhead in deployed apps

o  trace2: message
a quick rejector to avoid overhead in deployed apps

o  trace2: format with: arg1
a quick rejector to avoid overhead in deployed apps

o  trace2: format with: arg1 with: arg2
a quick rejector to avoid overhead in deployed apps

o  trace2: format with: arg1 with: arg2 with: arg3
a quick rejector to avoid overhead in deployed apps

o  trace3: message
a quick rejector to avoid overhead in deployed apps

o  trace3: format with: arg1
a quick rejector to avoid overhead in deployed apps

o  trace3: format with: arg1 with: arg2
a quick rejector to avoid overhead in deployed apps

o  trace3: format with: arg1 with: arg2 with: arg3
a quick rejector to avoid overhead in deployed apps

o  trace: message
a quick rejector to avoid overhead in deployed apps

o  trace: format with: arg1
a quick rejector to avoid overhead in deployed apps

o  trace: format with: arg1 with: arg2
a quick rejector to avoid overhead in deployed apps

o  trace: format with: arg1 with: arg2 with: arg3
a quick rejector to avoid overhead in deployed apps

o  trace: format withArguments: arg1
a quick rejector to avoid overhead in deployed apps

o  warning: message
a quick rejector to avoid overhead in deployed apps

o  warning: format with: arg1
a quick rejector to avoid overhead in deployed apps

o  warning: format with: arg1 with: arg2
a quick rejector to avoid overhead in deployed apps

o  warning: format with: arg1 with: arg2 with: arg3
a quick rejector to avoid overhead in deployed apps

o  warning: format withArguments: arg1
a quick rejector to avoid overhead in deployed apps

private
o  basicLog: message severity: severity facility: facility originator: originator attachment: attachment
Principal logging method. This mimics VM __stxLog__()

o  expand: message

o  expand: message addingInfoFrom: aContext to: aDictionary
Logger warning:'some problem with %(RECEIVER)'
Logger warning:'some problem with %(RECEIVER) in %(LINE)'
Logger warning:'some problem with %(CLASS) in %(LINE)'
Logger warning:'some problem with %(MCLASS) in %(LINE)'
Logger warning:'some problem with %(SELECTOR) in %(LINE)'
Logger warning:'some problem with %(WHERE)'

o  expand: message with: arg1

o  expand: message with: arg1 with: arg2

o  expand: message with: arg1 with: arg2 with: arg3

o  expand: message with: arg1 with: arg2 with: arg3 with: arg4

o  expand: message withArguments: args

o  facilityOf: originator
^ originator class

usage example(s):

     Logger facilityOf: Object
     Logger facilityOf: Expecco::Browser

o  severityThresholdOf: originator
allow each class to define an individual threshold for Logging

usage example(s):

     Logger severityThresholdOf: Object
     Logger severityThresholdOf: Expecco::Browser

     Logger loggingThreshold:(Logger severityDEBUG) forClass:(Expecco::Browser).
     Logger loggingThreshold:(Logger severityDEBUG) forPackage:'stx:libbasic'.

     Logger loggingThreshold:nil forClass:(Expecco::Browser).
     Logger loggingThreshold:nil forPackage:'stx:libbasic'.

queries
o  canLog
answer true, if logging can be performed. Subclasse may redefine this.


Private classes:

    Severity

Examples:


Simple logging (make sure logging threshold is lower or equal then Logger severityDEBUG, see #loggingThreshold:)
    Logger debug: 'Hello world!'
You may use #<severity>:with:with: utility to format log message:
    |hostname port|

    hostname := 'www.google.com'.
    port := 80.
    Logger error: 'Cannot connect to %1:%2' with: hostname with: port
and even automatically include a lineNumber:
    Logger info: '[%(CLASS)>>%(SELECTOR):%(LINE)] Hello world!'


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Wed, 24 Apr 2024 07:12:41 GMT