2010-12-14 01:32:08 +00:00
|
|
|
"
|
2011-02-05 15:54:08 +00:00
|
|
|
(C) 2010-2011 by Holger Hans Peter Freyther
|
2010-12-14 01:32:08 +00:00
|
|
|
All Rights Reserved
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"
|
2010-09-05 10:30:04 +00:00
|
|
|
|
|
|
|
Object extend [
|
|
|
|
logManager [
|
|
|
|
<category: '*osmo-logging-core'>
|
2011-08-23 14:16:03 +00:00
|
|
|
^ Osmo.LogManager default
|
2010-09-05 10:30:04 +00:00
|
|
|
]
|
|
|
|
|
2011-02-05 15:54:08 +00:00
|
|
|
logDataContext: aData area: anArea [
|
|
|
|
<category: '*osmo-logging-core'>
|
|
|
|
(self logManager)
|
|
|
|
context: 'data' value: aData.
|
|
|
|
]
|
|
|
|
|
2010-09-05 10:30:04 +00:00
|
|
|
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
|
|
|
]
|
2011-04-03 20:06:46 +00:00
|
|
|
|
|
|
|
logException: aMessage area: anArea [
|
|
|
|
<category: '*osmo-logging-exception'>
|
|
|
|
(self logManager)
|
|
|
|
exception: (LogEntry withMsg: aMessage
|
|
|
|
level: LogLevel error
|
|
|
|
area: anArea context: thisContext parentContext)
|
|
|
|
]
|
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.
|
|
|
|
]
|
2011-04-03 20:06:46 +00:00
|
|
|
|
|
|
|
exception: anEntry [
|
|
|
|
<category: 'log'>
|
|
|
|
self subclassResponsibility.
|
|
|
|
]
|
2010-09-08 15:20:58 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
LogTarget subclass: LogTranscriptTarget [
|
|
|
|
<category: 'osmo-logging-target'>
|
|
|
|
<comment: 'I log to the Transcript buffer'>
|
|
|
|
|
|
|
|
print: anEntry [
|
|
|
|
<category: 'log'>
|
|
|
|
Transcript show: anEntry msg; nl.
|
|
|
|
]
|
2011-04-03 20:06:46 +00:00
|
|
|
|
|
|
|
exception: anEntry [
|
|
|
|
<category: 'log'>
|
|
|
|
Transcript show: anEntry msg; nl.
|
|
|
|
anEntry context backtraceOn: Transcript.
|
|
|
|
]
|
2010-09-08 15:20:58 +00:00
|
|
|
]
|
|
|
|
|
2010-09-08 15:56:03 +00:00
|
|
|
Object subclass: LogFilter [
|
|
|
|
<category: 'osmo-logging-core'>
|
|
|
|
<comment: 'I filter based on mood, context and Bangkok Law'>
|
|
|
|
|
|
|
|
filter: anEntry [
|
|
|
|
<category: 'filter'>
|
|
|
|
"I have to decide if anEntry can pass or should be filtered out, I can
|
|
|
|
access the logManager of anEntry to access the per process context"
|
|
|
|
^ self subclassResponsibility
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2010-09-08 15:20:58 +00:00
|
|
|
Object subclass: LogManager [
|
2010-09-08 15:56:03 +00:00
|
|
|
| target filter areas |
|
2010-09-08 15:20:58 +00:00
|
|
|
<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-08 15:38:42 +00:00
|
|
|
|
2011-04-03 20:06:46 +00:00
|
|
|
exception: anEntry [
|
|
|
|
<category: 'log'>
|
|
|
|
self handle: anEntry ifTrue: [
|
|
|
|
target exception: anEntry.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2010-09-08 15:38:42 +00:00
|
|
|
context: aString value: aValue [
|
|
|
|
| key |
|
|
|
|
key := Array with: 'LogArea' with: aString.
|
|
|
|
(ProcessVariable key: key) value: aValue.
|
|
|
|
]
|
|
|
|
|
|
|
|
contextValue: aString [
|
|
|
|
| key |
|
|
|
|
key := Array with: 'LogArea' with: aString.
|
|
|
|
^ (ProcessVariable key: key) value.
|
|
|
|
]
|
2010-09-06 07:02:41 +00:00
|
|
|
]
|