Maintainer | simons@cryp.to |
---|---|
Stability | provisional |
Portability | Posix |
Safe Haskell | None |
Language | Haskell98 |
FFI bindings to syslog(3) from POSIX.1-2001.
- data Priority
- toPriority :: CInt -> Priority
- fromPriority :: Priority -> CInt
- data Facility
- toFacility :: CInt -> Facility
- fromFacility :: Facility -> CInt
- data Option
- toOption :: CInt -> Option
- fromOption :: Option -> CInt
- data PriorityMask
- fromPriorityMask :: PriorityMask -> CInt
- data SyslogConfig = SyslogConfig {}
- defaultConfig :: SyslogConfig
- withSyslog :: SyslogConfig -> (SyslogFn -> IO ()) -> IO ()
- type SyslogFn = [Priority] -> ByteString -> IO ()
- withSyslogTo :: SyslogConfig -> (SyslogToFn -> IO ()) -> IO ()
- type SyslogToFn = [Facility] -> [Priority] -> ByteString -> IO ()
- syslogUnsafe :: SyslogFn
- syslogToUnsafe :: SyslogToFn
- _openlog :: CString -> CInt -> CInt -> IO ()
- _closelog :: IO ()
- _setlogmask :: CInt -> IO CInt
- _syslog :: CInt -> CString -> IO ()
- _LOG_MASK :: CInt -> CInt
- _LOG_UPTO :: CInt -> CInt
- _LOG_MAKEPRI :: CInt -> CInt -> CInt
Marshaled Data Types
Log messages have a priority attached.
toPriority :: CInt -> Priority Source
fromPriority :: Priority -> CInt Source
Syslog distinguishes various system facilities. Most
applications should log in USER
.
KERN | kernel messages |
USER | user-level messages (default unless set otherwise) |
mail system | |
DAEMON | system daemons |
AUTH | security/authorization messages |
SYSLOG | messages generated internally by syslogd |
LPR | line printer subsystem |
NEWS | network news subsystem |
UUCP | UUCP subsystem |
CRON | clock daemon |
AUTHPRIV | security/authorization messages (effectively equals |
FTP | ftp daemon (effectively equals |
LOCAL0 | reserved for local use |
LOCAL1 | reserved for local use |
LOCAL2 | reserved for local use |
LOCAL3 | reserved for local use |
LOCAL4 | reserved for local use |
LOCAL5 | reserved for local use |
LOCAL6 | reserved for local use |
LOCAL7 | reserved for local use |
toFacility :: CInt -> Facility Source
fromFacility :: Facility -> CInt Source
withSyslog
options for the syslog service.
fromOption :: Option -> CInt Source
data PriorityMask Source
withSyslog
options for the priority mask
Configuring syslog
data SyslogConfig Source
SyslogConfig | |
|
defaultConfig :: SyslogConfig Source
A practical default syslog config. You'll at least want to change the identifier.
The preferred Haskell API to syslog
These are also the most performant calls to syslog, with the minimum
amount of CString
copying necessary.
withSyslog :: SyslogConfig -> (SyslogFn -> IO ()) -> IO () Source
Bracket an IO
computation between calls to _openlog
, _setlogmask
, and
_closelog
, and provide a logging function which can be used as follows:
main = withSyslog defaultConfig $ \syslog -> do putStrLn "huhu" syslog [Debug] "huhu"
Note that these are process-wide settings, so multiple calls to this function will interfere with each other in unpredictable ways.
= [Priority] | the priorities under which to log |
-> ByteString | the message to log |
-> IO () |
The type of logging function provided by withSyslog
.
withSyslogTo :: SyslogConfig -> (SyslogToFn -> IO ()) -> IO () Source
Like withSyslog
but provides a function for logging to specific
facilities per message rather than the default facilities in your
SyslogConfig
.
type SyslogToFn Source
= [Facility] | the facilities to log to |
-> [Priority] | the priorities under which to log |
-> ByteString | the message to log |
-> IO () |
The type of function provided by withSyslogTo
.
The unsafe Haskell API to syslog
Using these functions provides no guarantee that a call to _openlog
has been made.
Low-level C functions
_openlog :: CString -> CInt -> CInt -> IO () Source
Open a connection to the system logger for a program. The string
identifier passed as the first argument is prepended to every
message, and is typically set to the program name. The behavior is
unspecified by POSIX.1-2008 if that identifier is nullPtr
.
_setlogmask :: CInt -> IO CInt Source
A process has a log priority mask that determines which calls to syslog may be logged. All other calls will be ignored. Logging is enabled for the priorities that have the corresponding bit set in mask. The initial mask is such that logging is enabled for all priorities. This function sets this logmask for the calling process, and returns the previous mask. If the mask argument is 0, the current logmask is not modified.
_syslog :: CInt -> CString -> IO () Source
Generate a log message, which will be distributed by syslogd(8)
.
The priority argument is formed by ORing the facility and the level
values (explained below). The remaining arguments are a format, as in
printf(3) and any arguments required by the format, except that the
two character sequence %m will be replaced by the error message
string strerror(errno). A trailing newline may be added if needed.
Low-level C macros
See the GNU libc documentation for their intended usage.
_LOG_MAKEPRI :: CInt -> CInt -> CInt Source