2010-09-05 10:30:04 +00:00
|
|
|
"Copyright placeholder"
|
|
|
|
|
|
|
|
Object extend [
|
|
|
|
logManager [
|
|
|
|
<category: '*osmo-logging-core'>
|
|
|
|
^ LogManager default
|
|
|
|
]
|
|
|
|
|
|
|
|
logDebug: aMessage area: anArea [
|
|
|
|
<category: '*osmo-logging-core'>
|
|
|
|
(self logManager)
|
2010-09-08 04:58:55 +00:00
|
|
|
log: (LogEntry withMsg: aMessage level: LogLevel debug area: anArea context: self)
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
logInfo: aMessage area: anArea [
|
|
|
|
<category: '*osmo-logging-core'>
|
|
|
|
(self logManager)
|
2010-09-08 04:58:55 +00:00
|
|
|
log: (LogEntry withMsg: aMessage level: LogLevel info area: anArea context: self)
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
logNotice: aMessage area: anArea [
|
|
|
|
<category: '*osmo-logging-core'>
|
|
|
|
(self logManager)
|
2010-09-08 04:58:55 +00:00
|
|
|
log: (LogEntry withMsg: aMessage level: LogLevel notice area: anArea context: self)
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
logError: aMessage area: anArea [
|
|
|
|
<category: '*osmo-logging-core'>
|
|
|
|
(self logManager)
|
2010-09-08 04:58:55 +00:00
|
|
|
log: (LogEntry withMsg: aMessage level: LogLevel error area: anArea context: self)
|
2010-09-07 09:53:28 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
Object subclass: LogEntry [
|
|
|
|
| level ctx area msg |
|
|
|
|
|
|
|
|
<category: 'osmo-logging-core'>
|
|
|
|
<comment: 'I represent a log entry and hold the text, level, area'>
|
|
|
|
|
|
|
|
LogEntry class >> withMsg: aMsg level: anLevel area: anArea context: aContext [
|
|
|
|
^ self new
|
|
|
|
msg: aMsg;
|
|
|
|
level: anLevel;
|
|
|
|
area: anArea;
|
|
|
|
context: aContext;
|
|
|
|
yourself.
|
|
|
|
]
|
|
|
|
|
|
|
|
msg [
|
|
|
|
^ msg
|
|
|
|
]
|
|
|
|
|
|
|
|
msg: aMsg [
|
|
|
|
msg := aMsg.
|
|
|
|
]
|
|
|
|
|
|
|
|
level [
|
|
|
|
^ level
|
|
|
|
]
|
|
|
|
|
|
|
|
level: anLevel [
|
2010-09-08 04:58:55 +00:00
|
|
|
level := anLevel
|
2010-09-07 09:53:28 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
area [
|
|
|
|
^ area
|
|
|
|
]
|
|
|
|
|
|
|
|
area: anArea [
|
|
|
|
area := anArea.
|
|
|
|
]
|
|
|
|
|
|
|
|
context [
|
2010-09-08 04:58:55 +00:00
|
|
|
^ ctx
|
2010-09-07 09:53:28 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
context: aContext [
|
2010-09-08 04:58:55 +00:00
|
|
|
ctx := aContext.
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
Object subclass: LogLevel [
|
|
|
|
<category: 'osmo-logging-core'>
|
|
|
|
<comment: 'I represent the available levels for log messages'>
|
|
|
|
|
|
|
|
LogLevel class >> debug [
|
2010-09-06 07:49:55 +00:00
|
|
|
^ 1
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
LogLevel class >> info [
|
2010-09-06 07:49:55 +00:00
|
|
|
^ 3
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
LogLevel class >> notice [
|
2010-09-06 07:49:55 +00:00
|
|
|
^ 5
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
LogLevel class >> error [
|
2010-09-06 07:49:55 +00:00
|
|
|
^ 7
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
Object subclass: LogArea [
|
|
|
|
| name enabled level |
|
|
|
|
<category: 'osmo-logging-core'>
|
2010-09-07 09:53:28 +00:00
|
|
|
<comment: 'I represent a LogArea'>
|
|
|
|
|
2010-09-08 04:58:55 +00:00
|
|
|
LogArea class >> defaultForArea: aSymbol [
|
2010-09-07 09:53:28 +00:00
|
|
|
"Find an Area and place the default into our dictionary"
|
2010-09-08 04:58:55 +00:00
|
|
|
LogArea allSubclassesDo: [ :each |
|
|
|
|
(each areaName) = aSymbol
|
|
|
|
ifTrue: [
|
|
|
|
^ each default.
|
|
|
|
].
|
|
|
|
].
|
2010-09-07 09:53:28 +00:00
|
|
|
|
2010-09-08 04:58:55 +00:00
|
|
|
^ nil
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
|
2010-09-07 09:53:28 +00:00
|
|
|
LogArea class >> default [
|
2010-09-08 04:58:55 +00:00
|
|
|
<category: 'accessing'>
|
|
|
|
^ self subclassResponsibility
|
|
|
|
]
|
|
|
|
|
|
|
|
LogArea class >> areaName [
|
|
|
|
<category: 'accessing'>
|
2010-09-07 09:53:28 +00:00
|
|
|
^ self subclassResponsibility
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
|
2010-09-08 04:58:55 +00:00
|
|
|
LogArea class >> areaDescription [
|
2010-09-05 10:30:04 +00:00
|
|
|
<category: 'accessing'>
|
2010-09-07 09:53:28 +00:00
|
|
|
^ self subclassResponsibility
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
|
2010-09-08 15:30:08 +00:00
|
|
|
LogArea class >> availableAreas [
|
|
|
|
<category: 'accessing'>
|
|
|
|
^ self allSubclasses collect: [ :each |
|
|
|
|
Array with: each areaName with: each areaDescription
|
|
|
|
].
|
|
|
|
]
|
|
|
|
|
2010-09-05 10:30:04 +00:00
|
|
|
enabled [
|
|
|
|
<category: 'accessing'>
|
|
|
|
^ enabled
|
|
|
|
]
|
|
|
|
|
|
|
|
enabled: anEnabled [
|
|
|
|
<category: 'accessing'>
|
|
|
|
enabled := anEnabled.
|
|
|
|
]
|
|
|
|
|
2010-09-06 07:02:41 +00:00
|
|
|
minLevel [
|
2010-09-05 10:30:04 +00:00
|
|
|
<category: 'accessing'>
|
|
|
|
^ level
|
|
|
|
]
|
|
|
|
|
2010-09-06 07:02:41 +00:00
|
|
|
minLevel: aLevel [
|
2010-09-05 10:30:04 +00:00
|
|
|
<category: 'accessing'>
|
|
|
|
level := aLevel
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2010-09-08 04:58:55 +00:00
|
|
|
Object subclass: LogTarget [
|
2010-09-05 10:30:04 +00:00
|
|
|
<category: 'osmo-logging-core'>
|
2010-09-08 04:58:55 +00:00
|
|
|
<comment: 'I will filter and then output the log message'>
|
2010-09-05 10:30:04 +00:00
|
|
|
|
2010-09-08 15:20:58 +00:00
|
|
|
|
|
|
|
print: anEntry [
|
|
|
|
<category: 'log'>
|
|
|
|
self subclassResponsibility.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
LogTarget subclass: LogTranscriptTarget [
|
|
|
|
<category: 'osmo-logging-target'>
|
|
|
|
<comment: 'I log to the Transcript buffer'>
|
|
|
|
|
|
|
|
print: anEntry [
|
|
|
|
<category: 'log'>
|
|
|
|
Transcript show: anEntry msg; nl.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
Object subclass: LogManager [
|
|
|
|
| target areas |
|
|
|
|
<category: 'osmo-logging-core'>
|
|
|
|
<comment: 'I handle the actual log invocation'>
|
|
|
|
|
|
|
|
Log := nil.
|
|
|
|
|
|
|
|
LogManager class >> default [
|
|
|
|
<category: 'instance'>
|
|
|
|
Log ifNil: [
|
|
|
|
Log := LogManager new.
|
|
|
|
Log target: LogTranscriptTarget new.
|
|
|
|
].
|
|
|
|
|
|
|
|
^ Log
|
|
|
|
]
|
|
|
|
|
|
|
|
target: aTarget [
|
|
|
|
<category: 'private'>
|
|
|
|
target := aTarget.
|
|
|
|
]
|
|
|
|
|
2010-09-08 04:58:55 +00:00
|
|
|
areas [
|
2010-09-05 10:30:04 +00:00
|
|
|
<category: 'accessing'>
|
2010-09-08 04:58:55 +00:00
|
|
|
areas ifNil: [
|
|
|
|
areas := Dictionary new.
|
|
|
|
].
|
|
|
|
|
|
|
|
^ areas
|
|
|
|
]
|
|
|
|
|
|
|
|
findArea: anArea [
|
|
|
|
<category: 'private'>
|
|
|
|
"Find anArea, or ask for a default"
|
|
|
|
^ (self areas) at: anArea ifAbsent: [
|
|
|
|
| area |
|
|
|
|
area := LogArea defaultForArea: anArea.
|
|
|
|
area ifNotNil: [
|
|
|
|
(self areas) at: anArea put: area.
|
|
|
|
].
|
|
|
|
|
|
|
|
area.
|
|
|
|
].
|
|
|
|
]
|
|
|
|
|
|
|
|
handle: anEntry ifTrue: aBlock [
|
|
|
|
<category: 'private'>
|
|
|
|
|
|
|
|
| area |
|
|
|
|
area := self findArea: anEntry area.
|
|
|
|
|
|
|
|
(area enabled and: [anEntry level >= area minLevel]) ifTrue: aBlock
|
|
|
|
]
|
|
|
|
|
|
|
|
log: anEntry [
|
|
|
|
<category: 'log'>
|
|
|
|
self handle: anEntry ifTrue: [
|
2010-09-08 15:20:58 +00:00
|
|
|
target print: anEntry
|
2010-09-08 04:58:55 +00:00
|
|
|
]
|
|
|
|
]
|
2010-09-06 07:02:41 +00:00
|
|
|
]
|