|
Class: MiniLogger
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>
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:]
Loggia
logging
framework
[stx]
accessing-log format
-
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.
|
-
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.
|
-
logOnStderr
-
-
logOnStderr: aBoolean
-
enable/disable logging on stderr
usage example(s):
MiniLogger logOnStderr:false
MiniLogger logOnTranscript:false
MiniLogger logOnStderr:true
MiniLogger logOnTranscript:true
|
-
logOnTranscript
-
-
logOnTranscript: aBoolean
-
enable/disable logging on the Transcript
usage example(s):
MiniLogger logOnStderr:false
MiniLogger logOnTranscript:false
MiniLogger logOnStderr:true
MiniLogger logOnTranscript:true
|
-
timestampFormat
-
will be used for the log message
-
timestampFormat: aTimestampFormatString
-
will be used for the log message
accessing-severities
-
severities
-
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE
-
severityDEBUG
-
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE
-
severityENTER
-
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE
-
severityERROR
-
setting this as treshold will print errors
-
severityFATAL
-
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE
-
severityINFO
-
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE
-
severityLEAVE
-
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE
-
severityTRACE
-
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE
-
severityTRACE0
-
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE
-
severityTRACE1
-
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE
-
severityTRACE2
-
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE
-
severityTRACE3
-
ALL > FATAL > ERROR > WARN > INFO > DEBUG > TRACE0 > TRACE3 > NONE
-
severityWARN
-
setting this as treshold will print warnings and errors
accessing-severities-special
-
severityALL
-
setting this as treshold will print all
-
severityNONE
-
setting this as treshold will suppress all logging
configuration
-
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.
|
-
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.
|
-
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'.
|
-
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
-
initialize
-
(comment from inherited method)
called only once - initialize signals
logging
-
log: message
-
-
log: message facility: facility
-
-
log: message severity: severity
-
-
log: message severity: severity attachment: attachment
-
-
log: message severity: severity facility: facility
-
-
log: message severity: severity facility: facility originator: originator
-
-
log: message severity: severity originator: originatorOrNil
-
logging - basic
-
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
-
debug: message
-
generate a 'debug'-log
-
debug: format with: arg1
-
generate a 'debug'-log
-
debug: format with: arg1 with: arg2
-
generate a 'debug'-log
-
debug: format with: arg1 with: arg2 with: arg3
-
generate a 'debug'-log
-
debug: format withArguments: arg1
-
generate a 'debug'-log
-
enter: message
-
generate an 'entering method...'-log
-
enter: format with: arg1
-
generate an 'entering method...'-log
-
enter: format with: arg1 with: arg2
-
generate an 'entering method...'-log
-
enter: format with: arg1 with: arg2 with: arg3
-
generate an 'entering method...'-log
-
enter: format withArguments: arg1
-
generate an 'entering method...'-log
-
error: message
-
generate an 'error'-log
-
error: format with: arg1
-
generate an 'error'-log
-
error: format with: arg1 with: arg2
-
generate an 'error'-log
-
error: format with: arg1 with: arg2 with: arg3
-
generate an 'error'-log
-
error: format withArguments: arg1
-
generate an 'error'-log
-
fatal: message
-
generate a 'fatal'-log
-
fatal: format with: arg1
-
generate a 'fatal'-log
-
fatal: format with: arg1 with: arg2
-
generate a 'fatal'-log
-
fatal: format with: arg1 with: arg2 with: arg3
-
generate a 'fatal'-log
-
fatal: format withArguments: arg1
-
generate a 'fatal'-log
-
info: message
-
generate an 'info'-log
-
info: format with: arg1
-
generate an 'info'-log
-
info: format with: arg1 with: arg2
-
generate an 'info'-log
-
info: format with: arg1 with: arg2 with: arg3
-
generate an 'info'-log
-
info: format with: arg1 with: arg2 with: arg3 with: arg4
-
generate an 'info'-log
-
info: format withArguments: arg1
-
generate an 'info'-log
-
leave: message
-
generate a 'leaving method...'-log
-
leave: format with: arg1
-
generate a 'leaving method...'-log
-
leave: format with: arg1 with: arg2
-
generate a 'leaving method...'-log
-
leave: format with: arg1 with: arg2 with: arg3
-
generate a 'leaving method...'-log
-
leave: format withArguments: arg1
-
generate a 'leaving method...'-log
-
trace0: message
-
generate a 'debug trace'-log
-
trace0: format with: arg1
-
generate a 'debug trace'-log
-
trace0: format with: arg1 with: arg2
-
generate a 'debug trace'-log
-
trace0: format with: arg1 with: arg2 with: arg3
-
generate a 'debug trace'-log
-
trace1: message
-
a quick rejector to avoid overhead in deployed apps
-
trace1: format with: arg1
-
a quick rejector to avoid overhead in deployed apps
-
trace1: format with: arg1 with: arg2
-
a quick rejector to avoid overhead in deployed apps
-
trace1: format with: arg1 with: arg2 with: arg3
-
a quick rejector to avoid overhead in deployed apps
-
trace2: message
-
a quick rejector to avoid overhead in deployed apps
-
trace2: format with: arg1
-
a quick rejector to avoid overhead in deployed apps
-
trace2: format with: arg1 with: arg2
-
a quick rejector to avoid overhead in deployed apps
-
trace2: format with: arg1 with: arg2 with: arg3
-
a quick rejector to avoid overhead in deployed apps
-
trace3: message
-
a quick rejector to avoid overhead in deployed apps
-
trace3: format with: arg1
-
a quick rejector to avoid overhead in deployed apps
-
trace3: format with: arg1 with: arg2
-
a quick rejector to avoid overhead in deployed apps
-
trace3: format with: arg1 with: arg2 with: arg3
-
a quick rejector to avoid overhead in deployed apps
-
trace: message
-
a quick rejector to avoid overhead in deployed apps
-
trace: format with: arg1
-
a quick rejector to avoid overhead in deployed apps
-
trace: format with: arg1 with: arg2
-
a quick rejector to avoid overhead in deployed apps
-
trace: format with: arg1 with: arg2 with: arg3
-
a quick rejector to avoid overhead in deployed apps
-
trace: format withArguments: arg1
-
a quick rejector to avoid overhead in deployed apps
-
warning: message
-
a quick rejector to avoid overhead in deployed apps
-
warning: format with: arg1
-
a quick rejector to avoid overhead in deployed apps
-
warning: format with: arg1 with: arg2
-
a quick rejector to avoid overhead in deployed apps
-
warning: format with: arg1 with: arg2 with: arg3
-
a quick rejector to avoid overhead in deployed apps
-
warning: format withArguments: arg1
-
a quick rejector to avoid overhead in deployed apps
private
-
basicLog: message severity: severity facility: facility originator: originator attachment: attachment
-
Principal logging method. This mimics VM __stxLog__()
-
expand: message
-
-
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)'
-
expand: message with: arg1
-
-
expand: message with: arg1 with: arg2
-
-
expand: message with: arg1 with: arg2 with: arg3
-
-
expand: message with: arg1 with: arg2 with: arg3 with: arg4
-
-
expand: message withArguments: args
-
-
facilityOf: originator
-
^ originator class
usage example(s):
Logger facilityOf: Object
Logger facilityOf: Expecco::Browser
|
-
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
-
canLog
-
answer true, if logging can be performed. Subclasse may redefine this.
Severity
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!'
|
|