hsyslog-3: FFI interface to syslog(3) from POSIX.1-2001

Maintainersimons@cryp.to
Stabilityprovisional
PortabilityPosix
Safe HaskellNone
LanguageHaskell98

System.Posix.Syslog

Contents

Description

FFI bindings to syslog(3) from POSIX.1-2001.

Synopsis

Marshaled Data Types

data Priority Source

Log messages have a priority attached.

Constructors

Emergency

system is unusable

Alert

action must be taken immediately

Critical

critical conditions

Error

error conditions

Warning

warning conditions

Notice

normal but significant condition

Info

informational

Debug

debug-level messages

data Facility Source

Syslog distinguishes various system facilities. Most applications should log in USER.

Constructors

KERN

kernel messages

USER

user-level messages (default unless set otherwise)

MAIL

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 AUTH on some systems)

FTP

ftp daemon (effectively equals DAEMON on some systems)

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

data Option Source

withSyslog options for the syslog service.

Constructors

PID

log the pid with each message

CONS

log on the console if errors in sending

ODELAY

delay open until first syslog() (default)

NDELAY

don't delay open

NOWAIT

don't wait for console forks: DEPRECATED

PERROR

log to stderr as well (might be a no-op on some systems)

data PriorityMask Source

withSyslog options for the priority mask

Constructors

NoMask

allow all messages thru

Mask [Priority]

allow only messages with the priorities listed

UpTo Priority

allow only messages down to and including the specified priority

Configuring syslog

data SyslogConfig Source

Constructors

SyslogConfig 

Fields

identifier :: ByteString

string appended to each log message

options :: [Option]

options for syslog behavior

defaultFacilities :: [Facility]

facilities logged to when none are provided

priorityMask :: PriorityMask

filter by priority which messages are logged

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.

type SyslogFn Source

Arguments

 = [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

Arguments

 = [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.

_closelog :: IO () Source

Close the descriptor being used to write to the system logger.

_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.