hsyslog-udp-0.2.5: Log to syslog over a network via UDP

Maintainerjon@childr.es
Stabilityprovisional
PortabilityPosix
Safe HaskellNone
LanguageHaskell2010

System.Posix.Syslog.UDP

Contents

Description

Log messages to syslog over a network via UDP, with protocols such as RFC 5424 or RFC 3164.

The following features are currently missing (but may be provided in future releases):

  • validation of string identifiers such as APP-NAME or MSGID
  • support for STRUCTURED-DATA (RFC 5424 only)
Synopsis

Syslog UDP packet component datatypes

Re-exports from hsyslog

data Priority #

Log messages are prioritized with one of the following levels:

>>> [minBound..maxBound] :: [Priority]
[Emergency,Alert,Critical,Error,Warning,Notice,Info,Debug]

The Ord instance for Priority considers the more urgent level lower than less urgent ones:

>>> Emergency < Debug
True
>>> minimum [minBound..maxBound] :: Priority
Emergency
>>> maximum [minBound..maxBound] :: Priority
Debug

Constructors

Emergency

the 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

Instances
Bounded Priority 
Instance details

Defined in System.Posix.Syslog.Priority

Enum Priority 
Instance details

Defined in System.Posix.Syslog.Priority

Eq Priority 
Instance details

Defined in System.Posix.Syslog.Priority

Ord Priority 
Instance details

Defined in System.Posix.Syslog.Priority

Read Priority 
Instance details

Defined in System.Posix.Syslog.Priority

Show Priority 
Instance details

Defined in System.Posix.Syslog.Priority

Generic Priority 
Instance details

Defined in System.Posix.Syslog.Priority

Associated Types

type Rep Priority :: Type -> Type #

Methods

from :: Priority -> Rep Priority x #

to :: Rep Priority x -> Priority #

type Rep Priority 
Instance details

Defined in System.Posix.Syslog.Priority

type Rep Priority = D1 (MetaData "Priority" "System.Posix.Syslog.Priority" "hsyslog-5.0.2-4YPEwpeEGKZ6PP1UUUwS4g" False) (((C1 (MetaCons "Emergency" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Alert" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "Critical" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Error" PrefixI False) (U1 :: Type -> Type))) :+: ((C1 (MetaCons "Warning" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Notice" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "Info" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Debug" PrefixI False) (U1 :: Type -> Type))))

data Facility #

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

Constructors

Kernel

kernel messages

User

user-level messages (default unless set otherwise)

Mail

mail system

News

network news subsystem

UUCP

UUCP subsystem

Daemon

system daemons

Auth

security and authorization messages

Cron

clock daemon

LPR

line printer subsystem

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

Instances
Bounded Facility 
Instance details

Defined in System.Posix.Syslog.Facility

Enum Facility 
Instance details

Defined in System.Posix.Syslog.Facility

Eq Facility 
Instance details

Defined in System.Posix.Syslog.Facility

Read Facility 
Instance details

Defined in System.Posix.Syslog.Facility

Show Facility 
Instance details

Defined in System.Posix.Syslog.Facility

Generic Facility 
Instance details

Defined in System.Posix.Syslog.Facility

Associated Types

type Rep Facility :: Type -> Type #

Methods

from :: Facility -> Rep Facility x #

to :: Rep Facility x -> Facility #

type Rep Facility 
Instance details

Defined in System.Posix.Syslog.Facility

type Rep Facility = D1 (MetaData "Facility" "System.Posix.Syslog.Facility" "hsyslog-5.0.2-4YPEwpeEGKZ6PP1UUUwS4g" False) ((((C1 (MetaCons "Kernel" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "User" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "Mail" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "News" PrefixI False) (U1 :: Type -> Type))) :+: ((C1 (MetaCons "UUCP" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Daemon" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "Auth" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Cron" PrefixI False) (U1 :: Type -> Type)))) :+: (((C1 (MetaCons "LPR" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Local0" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "Local1" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Local2" PrefixI False) (U1 :: Type -> Type))) :+: ((C1 (MetaCons "Local3" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Local4" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "Local5" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "Local6" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Local7" PrefixI False) (U1 :: Type -> Type))))))

Newtypes for various String/Int values

Refer to RFC 5424 section 6.2 as to the purpose of each.

newtype AppName Source #

Constructors

AppName ByteString

see APP-NAME

Instances
Eq AppName Source # 
Instance details

Defined in System.Posix.Syslog.UDP

Methods

(==) :: AppName -> AppName -> Bool #

(/=) :: AppName -> AppName -> Bool #

Show AppName Source # 
Instance details

Defined in System.Posix.Syslog.UDP

newtype HostName Source #

Constructors

HostName ByteString

see HOSTNAME; fetch via getHostName

Instances
Eq HostName Source # 
Instance details

Defined in System.Posix.Syslog.UDP

Show HostName Source # 
Instance details

Defined in System.Posix.Syslog.UDP

newtype PriVal Source #

Constructors

PriVal CInt

see PRI; construct via maskedPriVal

Instances
Eq PriVal Source # 
Instance details

Defined in System.Posix.Syslog.UDP

Methods

(==) :: PriVal -> PriVal -> Bool #

(/=) :: PriVal -> PriVal -> Bool #

Show PriVal Source # 
Instance details

Defined in System.Posix.Syslog.UDP

newtype ProcessID Source #

Constructors

ProcessID ByteString

see PROCID; fetch via getProcessId

Instances
Eq ProcessID Source # 
Instance details

Defined in System.Posix.Syslog.UDP

Show ProcessID Source # 
Instance details

Defined in System.Posix.Syslog.UDP

newtype MessageID Source #

Constructors

MessageID ByteString

see MSGID

Instances
Eq MessageID Source # 
Instance details

Defined in System.Posix.Syslog.UDP

Show MessageID Source # 
Instance details

Defined in System.Posix.Syslog.UDP

Type aliases

What syslog refers to as Priority, RFC 5424 calls Severity.

Structured Data

Currently unsupported; a placeholder for future use.

data StructuredData Source #

Constructors

StructuredData

see STRUCTURED-DATA (unsupported)

The easy Haskell API to syslog via UDP

initSyslog :: SyslogConfig -> IO SyslogFn Source #

Return a function that logs to syslog via UDP.

{-# LANGUAGE OverloadedStrings #-}

import System.Posix.Syslog.UDP

main = do
  syslog <- defaultConfig >>= initSyslog
  putStrLn "huhu"
  syslog USER Debug "huhu"

This makes no assumptions about socket connection status or endpoint availability. Any errors while sending are silently ignored.

type SyslogFn Source #

Arguments

 = Facility

facility to log to

-> Severity

severity under which to log

-> Text

message body

-> IO () 

The type of function returned by initSyslog.

data SyslogConfig Source #

Configuration options for connecting and logging to your syslog socket.

Constructors

SyslogConfig 

Fields

defaultConfig :: IO SyslogConfig Source #

A convenient default config for connecting to localhost. Provided for development/testing purposes.

localhost :: AddrInfo Source #

The default IPv4 address/port for syslog on a local machine. Provided for development/testing purposes.

Common protocols for use with SyslogConfig

Manually constructing syslog UDP packets

rfc5424Packet Source #

Arguments

:: FormatTime t 
=> PriVal

see PRI; construct via maskedPriVal

-> Maybe t

time of message, converted to TIMESTAMP

-> Maybe HostName

see HOSTNAME; fetch via getHostName

-> Maybe AppName

see APP-NAME; fetch via getAppName

-> Maybe ProcessID

see PROCID; fetch via getProcessId

-> Maybe MessageID

see MSGID

-> Maybe StructuredData

see STRUCTURED-DATA (unsupported)

-> Text

see MSG

-> ByteString 

Construct a syslog UDP packet as dictated by RFC 5424. Note that fields in a syslog packet are whitespace-delineated, so don't allow whitespace in anything but the log message!

rfc3164Packet Source #

Arguments

:: FormatTime t 
=> PriVal

see PRI; construct via maskedPriVal

-> t

time of message, converted to TIMESTAMP in HEADER

-> HostName

the HOSTNAME of the HEADER; fetch via getHostName

-> AppName

the program name in the TAG portion of the MSG; fetch via getAppName

-> ProcessID

the process identifier in the TAG portion of the MSG; fetch via getProcessId

-> Text

the CONTENT portion of the MSG

-> ByteString 

Construct a syslog UDP packet as dictated by RFC 3164. Note that fields in a syslog packet are whitespace-delineated, so don't allow whitespace in anything but the log message!

rsyslogPacket :: FormatTime t => PriVal -> t -> HostName -> AppName -> ProcessID -> Text -> ByteString Source #

Recommended rsyslog template RSYSLOG_ForwardFormat. Same fields as RFC 3164, but with an RFC 3339 high-precision timestamp.

Miscellaneous utilities

maskedPriVal :: SeverityMask -> Facility -> Severity -> Maybe PriVal Source #

Construct a PRI. Nothing indicates that the severities are fully masked, and so no packet should be sent.

resolveUdpAddress :: Integral n => String -> n -> IO (Maybe AddrInfo) Source #

Obtain an IPv4 AddrInfo for your SyslogConfig from a hostname (or IPv4 address) and port. Sets the address protocol to Datagram.

rfc3339Timestamp :: FormatTime t => t -> ByteString Source #

An RFC 3339 high-precision timestamp.