"
(C) 2011 by Holger Hans Peter Freyther
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 .
"
LogTarget subclass: LogTargetSyslog [
| prefix |
LogMap := nil.
LogTargetSyslog class >> LOG_USER [
^ 8
]
LogTargetSyslog class >> logLevelMap [
^ LogMap ifNil: [ LogMap := Dictionary new
at: LogLevel debug put: 7;
at: LogLevel info put: 6;
at: LogLevel notice put: 5;
at: LogLevel error put: 3;
yourself
]
]
LogTargetSyslog class >> openlog: aIdent option: aOption facility: aFacility [
"Free any previous string"
SYSLOG_NAME ifNotNil: [
SYSLOG_NAME free.
Smalltalk at: #SYSLOG_NAME put: nil.
].
Smalltalk at: #SYSLOG_NAME put: aIdent asCData.
self c_closelog.
self c_openlog: SYSLOG_NAME opt: aOption facility: aFacility.
^ self new
]
LogTargetSyslog class >> c_openlog: ident opt: aOpt facility: aFac [
]
LogTargetSyslog class >> c_syslog: prio fmt: aFormat args: args[
]
LogTargetSyslog class >> c_closelog [
]
LogTargetSyslog class >> initialize [
DLD addLibrary: 'libc'.
]
LogTargetSyslog class >> update: aSymbol []
print: aMessage [
| level |
level := self class logLevelMap at: aMessage level.
self class c_syslog: level fmt: '%s%s' args: {self prefix. aMessage msg}.
]
exception: aMessage [
self class c_syslog: aMessage level fmt: '%s%s'
args: {self prefix. 'EXCEPTION occured'}.
self print: aMessage.
]
prefix: aMsg [
prefix := aMsg.
]
prefix [
^ prefix ifNil: ['']
]
]
Eval [
LogTargetSyslog initialize.
]