1
0
Fork 0

LogManager: Start designing the API and access.

This commit is contained in:
Holger Hans Peter Freyther 2010-09-05 18:30:04 +08:00
parent 0e8dfcbfc4
commit 7f802671c6
1 changed files with 146 additions and 0 deletions

146
LogManager.st Normal file
View File

@ -0,0 +1,146 @@
"Copyright placeholder"
Object extend [
logConfig [
<category: '*osmo-logging-core'>
"I provide access to the global LogConfig"
^ LogConfig instance
]
logManager [
<category: '*osmo-logging-core'>
^ LogManager default
]
logDebug: aMessage area: anArea [
<category: '*osmo-logging-core'>
(self logManager)
log: aMessage source: self area: anArea level: LogLevel debug
]
logInfo: aMessage area: anArea [
<category: '*osmo-logging-core'>
(self logManager)
log: aMessage source: self area: anArea level: LogLevel info
]
logNotice: aMessage area: anArea [
<category: '*osmo-logging-core'>
(self logManager)
log: aMessage source: self area: anArea level: LogLevel notice
]
logError: aMessage area: anArea [
<category: '*osmo-logging-core'>
(self logManager)
log: aMessage source: self area: anArea level: LogLevel error
]
]
Object subclass: LogLevel [
<category: 'osmo-logging-core'>
<comment: 'I represent the available levels for log messages'>
LogLevel class >> debug [
^ #logDebug
]
LogLevel class >> info [
^ #logInfo
]
LogLevel class >> notice [
^ #logNotice
]
LogLevel class >> error [
^ #logError
]
]
Object subclass: LogArea [
| name enabled level |
<category: 'osmo-logging-core'>
<comment: 'I represent one LogArea and have status'>
LogArea class >> withName: aName enabled: anEnabled level: aLevel [
<category: 'instance'>
^ (LogArea new)
name: aName;
enabled: anEnabled;
level: aLevel;
yourself
]
name [
<category: 'accessing'>
^ name
]
name: aName [
<category: 'accessing'>
name := aName.
]
enabled [
<category: 'accessing'>
^ enabled
]
enabled: anEnabled [
<category: 'accessing'>
enabled := anEnabled.
]
level [
<category: 'accessing'>
^ level
]
level: aLevel [
<category: 'accessing'>
level := aLevel
]
]
Object subclass: LogConfig [
| areas |
<category: 'osmo-logging-core'>
<comment: 'I handle the config, the backends, the log areas, the default level'>
Config := LogConfig new.
LogConfig class >> default [
<category: 'accessing'>
^ Config
]
addArea: anArea name: aName [
<category: 'management'>
"Add the area to the list of areas"
"TODO: compile the area..."
]
areas [
^ areas
]
]
Object subclass: LogManager [
<category: 'osmo-logging-core'>
<comment: 'I handle the actual log invocation'>
Log := LogManager new.
LogManager class >> default [
<category: 'instance'>
^ Log
]
log: message source: anObject area: anArea level: anLevel [
<category: 'log'>
Transcript show: message; nl.
]
]