os/linux/syslog

This module provides a simple interface to a UNIX syslog daemon. Only tested with rsyslog currently.

The intent behind this is to facilitate implementing logging systems and also allow a program to have be able to emit to syslog with more control, such as having various subcomponents each able to log with their own names.

Getters/Setters

Types

SyslogHKind = enum
  slkUDP, slkTCP, slkLocal
SyslogHandle = ref object
  name: string               ## Name of what the logger is logging for
  kind: SyslogHKind          ## The kind of syslog connection we are using
  handle: Socket             ## Reference to the socket
  server: string             ## Reference to the server address
  port: Port                 ## Reference to the server port
  hostname: string           ## Cached local hostname
  
A handle to the syslog
Facility = enum
  Kernel = 0, User, Mail, System, Security, Syslogd, LinePrinter, NetworkNews,
  Uucp, Cron, SecurityPriv, Ftp, Ntp, LogAudit, LogAlert, SolarisCron, User0,
  User1, User2, User3, User4, User5, User6, User7
Severity = enum
  Emergency = 0, Alert, Critical, Error, Warning, Notice, Info, Debug

Procs

proc newSyslogHandle(name, server: string; port: Port; kind: SyslogHKind): SyslogHandle {...}{.
    raises: [OSError, SslError], tags: [ReadIOEffect].}
Create a new syslog handle
proc newSyslogHandle(name: string): SyslogHandle {...}{.raises: [OSError, SslError],
    tags: [ReadIOEffect].}
Wrapper to create a local UNIX file connection to /dev/log
proc freeSyslogHandle(self: SyslogHandle) {...}{.
    raises: [Exception, LibraryError, OSError, SslError], tags: [RootEffect].}
Clean-up the syslog handle's socket data
proc print(self: SyslogHandle; message: string; severity = Info;
           facility = User0; showPid = false) {...}{.
    raises: [ValueError, SslError, OSError], tags: [WriteIOEffect].}
Emit a message to the syslog. Generally facility comes first but I flipped them for this function because most of the time you would want to log to one of the User* facilities, but with differing severities.

Funcs

func name(self: SyslogHandle): string {...}{.inline, raises: [], tags: [].}
Getter for SyslogHandle.name
func name=(self: var SyslogHandle; value: string) {...}{.inline, raises: [], tags: [].}
Setter for SyslogHandle.name
func kind(self: SyslogHandle): SyslogHKind {...}{.inline, raises: [], tags: [].}
Getter for SyslogHandle.kind
func handle(self: SyslogHandle): Socket {...}{.inline, raises: [], tags: [].}
Getter for SyslogHandle.handle