Create a LogTarget class, with a Transcript implementation, improve LogArea
Create: LogTarget LogTargetTranscript Use LogArea, find area's automatically.
This commit is contained in:
parent
57b54630bf
commit
d16a9da541
127
LogManager.st
127
LogManager.st
|
@ -1,12 +1,6 @@
|
||||||
"Copyright placeholder"
|
"Copyright placeholder"
|
||||||
|
|
||||||
Object extend [
|
Object extend [
|
||||||
logConfig [
|
|
||||||
<category: '*osmo-logging-core'>
|
|
||||||
"I provide access to the global LogConfig"
|
|
||||||
^ LogConfig default
|
|
||||||
]
|
|
||||||
|
|
||||||
logManager [
|
logManager [
|
||||||
<category: '*osmo-logging-core'>
|
<category: '*osmo-logging-core'>
|
||||||
^ LogManager default
|
^ LogManager default
|
||||||
|
@ -15,25 +9,25 @@ Object extend [
|
||||||
logDebug: aMessage area: anArea [
|
logDebug: aMessage area: anArea [
|
||||||
<category: '*osmo-logging-core'>
|
<category: '*osmo-logging-core'>
|
||||||
(self logManager)
|
(self logManager)
|
||||||
log: LogEntry withMsg: aMessage level: LogLevel debug area: anArea context: self
|
log: (LogEntry withMsg: aMessage level: LogLevel debug area: anArea context: self)
|
||||||
]
|
]
|
||||||
|
|
||||||
logInfo: aMessage area: anArea [
|
logInfo: aMessage area: anArea [
|
||||||
<category: '*osmo-logging-core'>
|
<category: '*osmo-logging-core'>
|
||||||
(self logManager)
|
(self logManager)
|
||||||
log: LogEntry withMsg: aMessage level: LogLevel info area: anArea context: self
|
log: (LogEntry withMsg: aMessage level: LogLevel info area: anArea context: self)
|
||||||
]
|
]
|
||||||
|
|
||||||
logNotice: aMessage area: anArea [
|
logNotice: aMessage area: anArea [
|
||||||
<category: '*osmo-logging-core'>
|
<category: '*osmo-logging-core'>
|
||||||
(self logManager)
|
(self logManager)
|
||||||
log: LogEntry withMsg: aMessage level: LogLevel notice area: anArea context: self
|
log: (LogEntry withMsg: aMessage level: LogLevel notice area: anArea context: self)
|
||||||
]
|
]
|
||||||
|
|
||||||
logError: aMessage area: anArea [
|
logError: aMessage area: anArea [
|
||||||
<category: '*osmo-logging-core'>
|
<category: '*osmo-logging-core'>
|
||||||
(self logManager)
|
(self logManager)
|
||||||
log: LogEntry withMsg: aMessage level: LogLevel error area: anArea context: self
|
log: (LogEntry withMsg: aMessage level: LogLevel error area: anArea context: self)
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -65,7 +59,7 @@ Object subclass: LogEntry [
|
||||||
]
|
]
|
||||||
|
|
||||||
level: anLevel [
|
level: anLevel [
|
||||||
level := anLevel;
|
level := anLevel
|
||||||
]
|
]
|
||||||
|
|
||||||
area [
|
area [
|
||||||
|
@ -77,11 +71,11 @@ Object subclass: LogEntry [
|
||||||
]
|
]
|
||||||
|
|
||||||
context [
|
context [
|
||||||
^ context
|
^ ctx
|
||||||
]
|
]
|
||||||
|
|
||||||
context: aContext [
|
context: aContext [
|
||||||
context := aContext.
|
ctx := aContext.
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -111,29 +105,29 @@ Object subclass: LogArea [
|
||||||
<category: 'osmo-logging-core'>
|
<category: 'osmo-logging-core'>
|
||||||
<comment: 'I represent a LogArea'>
|
<comment: 'I represent a LogArea'>
|
||||||
|
|
||||||
Areas := Dictionary new.
|
LogArea class >> defaultForArea: aSymbol [
|
||||||
|
|
||||||
LogArea class >> findArea: aSymbol [
|
|
||||||
"Find an Area and place the default into our dictionary"
|
"Find an Area and place the default into our dictionary"
|
||||||
|
|
||||||
^ Areas at: aSymbol ifAbsent: [
|
|
||||||
LogArea allSubclassesDo: [ :each |
|
LogArea allSubclassesDo: [ :each |
|
||||||
each name = aSymbol
|
(each areaName) = aSymbol
|
||||||
ifTrue: [
|
ifTrue: [
|
||||||
| area |
|
^ each default.
|
||||||
area := each default.
|
|
||||||
Areas at: aSymbol put: area.
|
|
||||||
^ area
|
|
||||||
].
|
].
|
||||||
].
|
].
|
||||||
]
|
|
||||||
|
^ nil
|
||||||
]
|
]
|
||||||
|
|
||||||
LogArea class >> default [
|
LogArea class >> default [
|
||||||
|
<category: 'accessing'>
|
||||||
^ self subclassResponsibility
|
^ self subclassResponsibility
|
||||||
]
|
]
|
||||||
|
|
||||||
name [
|
LogArea class >> areaName [
|
||||||
|
<category: 'accessing'>
|
||||||
|
^ self subclassResponsibility
|
||||||
|
]
|
||||||
|
|
||||||
|
LogArea class >> areaDescription [
|
||||||
<category: 'accessing'>
|
<category: 'accessing'>
|
||||||
^ self subclassResponsibility
|
^ self subclassResponsibility
|
||||||
]
|
]
|
||||||
|
@ -159,41 +153,88 @@ Object subclass: LogArea [
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
Object subclass: LogConfig [
|
Object subclass: LogTarget [
|
||||||
|
| areas |
|
||||||
<category: 'osmo-logging-core'>
|
<category: 'osmo-logging-core'>
|
||||||
<comment: 'I handle the config, the backends, the log areas, the default level'>
|
<comment: 'I will filter and then output the log message'>
|
||||||
|
|
||||||
Config := LogConfig new.
|
areas [
|
||||||
|
|
||||||
LogConfig class >> default [
|
|
||||||
<category: 'accessing'>
|
<category: 'accessing'>
|
||||||
|
areas ifNil: [
|
||||||
|
areas := Dictionary new.
|
||||||
|
].
|
||||||
|
|
||||||
^ Config
|
^ 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: [
|
||||||
|
self print: anEntry.
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
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 [
|
Object subclass: LogManager [
|
||||||
|
| target |
|
||||||
<category: 'osmo-logging-core'>
|
<category: 'osmo-logging-core'>
|
||||||
<comment: 'I handle the actual log invocation'>
|
<comment: 'I handle the actual log invocation'>
|
||||||
|
|
||||||
Log := LogManager new.
|
Log := nil.
|
||||||
|
|
||||||
LogManager class >> default [
|
LogManager class >> default [
|
||||||
<category: 'instance'>
|
<category: 'instance'>
|
||||||
|
Log ifNil: [
|
||||||
|
Log := LogManager new.
|
||||||
|
Log target: LogTranscriptTarget new.
|
||||||
|
].
|
||||||
|
|
||||||
^ Log
|
^ Log
|
||||||
]
|
]
|
||||||
|
|
||||||
log: message source: anObject area: anArea level: anLevel [
|
log: anEntry [
|
||||||
<category: 'log'>
|
target log: anEntry.
|
||||||
| area |
|
]
|
||||||
|
|
||||||
area := LogArea findArea: anArea.
|
target: aTarget [
|
||||||
(area enabled and: [anLevel >= area minLevel])
|
target := aTarget.
|
||||||
ifTrue: [
|
|
||||||
Transcript show: message; nl.
|
|
||||||
].
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
Eval [
|
|
||||||
]
|
|
||||||
|
|
Reference in New Issue