syslog: Add support to log to the syslog infrastructure
This commit is contained in:
parent
bdaff7cef1
commit
f4847e4ed8
|
@ -0,0 +1,80 @@
|
|||
"
|
||||
(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 <http://www.gnu.org/licenses/>.
|
||||
"
|
||||
|
||||
LogTarget subclass: LogTargetSyslog [
|
||||
<comment: 'I can log everything to the syslog.'>
|
||||
<category: 'osmo-logging-syslog'>
|
||||
|
||||
LogMap := nil.
|
||||
|
||||
LogTargetSyslog class >> LOG_USER [
|
||||
<category: 'c-facility'>
|
||||
^ 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 [
|
||||
self c_closelog.
|
||||
self c_openlog: aIdent opt: aOption facility: aFacility.
|
||||
^ self new
|
||||
]
|
||||
|
||||
LogTargetSyslog class >> c_openlog: ident opt: aOpt facility: aFac [
|
||||
<category: 'c-interface'>
|
||||
<cCall: 'openlog' returning: #void args: #(#string #int #int)>
|
||||
]
|
||||
|
||||
LogTargetSyslog class >> c_syslog: prio fmt: aFormat args: args[
|
||||
<category: 'c-interface'>
|
||||
<cCall: 'syslog' returning: #void args: #(#int #string #variadic)>
|
||||
]
|
||||
|
||||
LogTargetSyslog class >> c_closelog [
|
||||
<category: 'c-interface'>
|
||||
<cCall: 'closelog' returning: #void args: #()>
|
||||
]
|
||||
|
||||
LogTargetSyslog class >> initialize [
|
||||
<category: 'c-interface'>
|
||||
DLD addLibrary: 'libc'.
|
||||
]
|
||||
|
||||
LogTargetSyslog class >> update: aSymbol []
|
||||
|
||||
print: aMessage [
|
||||
<category: 'output'>
|
||||
| level |
|
||||
level := self class logLevelMap at: aMessage level.
|
||||
self class c_syslog: level fmt: '%s' args: {aMessage msg}.
|
||||
]
|
||||
|
||||
exception: aMessage [
|
||||
self class c_syslog: aMessage level fmt: '%s' args: {'EXCEPTION occured'}.
|
||||
self print: aMessage.
|
||||
]
|
||||
]
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
<namespace>Osmo</namespace>
|
||||
|
||||
<filein>LogManager.st</filein>
|
||||
<filein>LogSyslog.st</filein>
|
||||
|
||||
<file>LogManager.st</file>
|
||||
<file>LogTest.st</file>
|
||||
|
|
Reference in New Issue