PIDUINO
Loading...
Searching...
No Matches
Piduino::SysLog

System logger. More...

#include <syslog.h>

Inheritance diagram for Piduino::SysLog:
Collaboration diagram for Piduino::SysLog:

Public Types

enum  Priority {
  Emergency = LOG_EMERG , Alert = LOG_ALERT , Critical = LOG_CRIT , Error = LOG_ERR ,
  Warning = LOG_WARNING , Notice = LOG_NOTICE , Info = LOG_INFO , Debug = LOG_DEBUG ,
  NoPriority = -1
}
 importance of the message More...
 
enum  Facility {
  Auth = LOG_AUTH , AuthPriv = LOG_AUTHPRIV , Cron = LOG_CRON , Daemon = LOG_DAEMON ,
  Ftp = LOG_FTP , Kernel = LOG_KERN , Local0 = LOG_LOCAL0 , Local1 = LOG_LOCAL1 ,
  Local2 = LOG_LOCAL2 , Local3 = LOG_LOCAL3 , Local4 = LOG_LOCAL4 , Local5 = LOG_LOCAL5 ,
  Local6 = LOG_LOCAL6 , Local7 = LOG_LOCAL7 , Lpr = LOG_LPR , Mail = LOG_MAIL ,
  News = LOG_NEWS , Syslogd = LOG_SYSLOG , User = LOG_USER , Uucp = LOG_UUCP ,
  NoFacility = -1
}
 The facility argument is used to specify what type of program is logging the message. This lets the configuration file specify that messages from different facilities will be handled differently. More...
 
enum  OptionFlag {
  Console = LOG_CONS , NoDelay = LOG_NDELAY , NoWait = LOG_NOWAIT , Delay = LOG_ODELAY ,
  Perror = LOG_PERROR , Pid = LOG_PID , NoOption = 0
}
 The option argument specifies flags which control the operation of open() and subsequent calls to log() More...
 
typedef Flags< OptionFlagOption
 

Public Member Functions

 SysLog (Priority initialPrio=Info)
 Constructor.
 
 ~SysLog ()
 Destructor.
 
void open (const std::string &ident, const SysLog::Facility &facility=User, const SysLog::Option &option=Pid)
 Opens a connection to the system logger.
 
void open (const SysLog::Facility &facility=User, const SysLog::Option &option=Pid)
 Opens a connection to the system logger This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool is_open () const
 Returns whether the object is currently associated to the system logger.
 
void close ()
 closes the descriptor being used to write to the system logger.
 
void log (Priority p, const char *format,...)
 Generates a log message.
 
void log (const char *format,...)
 Generates a log message This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void setMask (Priority p)
 
void setMaskUpTo (Priority p)
 
int mask () const
 
void setPriority (Priority p=Info)
 
Priority priority () const
 
std::string priorityName () const
 
Facility facility () const
 Reads the current facility.
 
std::string facilityName () const
 Name of the current facility.
 
Option option () const
 Reads the current option flags.
 

Static Public Member Functions

static std::string priorityName (Priority p)
 Name of a priority.
 
static std::string facilityName (const Facility &facility)
 Name of a facility.
 
static void cerrToSyslog ()
 redirect std::cerr to the system logger
 
static void coutToSyslog ()
 redirect std::cout to the system logger
 

Protected Member Functions

int sync ()
 
void setPriority (const int priority)
 

Private Member Functions

void open (const char *ident, const SysLog::Facility &facility, const SysLog::Option &option)
 

Private Attributes

Option m_option
 
Facility m_facility
 
bool m_isopen
 
int m_priority
 

Detailed Description

System logger.

Definition at line 66 of file syslog.h.

Member Typedef Documentation

◆ Option

Definition at line 140 of file syslog.h.

Member Enumeration Documentation

◆ Facility

The facility argument is used to specify what type of program is logging the message. This lets the configuration file specify that messages from different facilities will be handled differently.

Enumerator
Auth 

security/authorization messages

AuthPriv 

security/authorization messages (private)

Cron 

clock daemon (cron and at)

Daemon 

system daemons without separate facility value

Ftp 

ftp daemon

Kernel 

kernel messages (these can't be generated from user processes)

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

Lpr 

line printer subsystem

Mail 

mail subsystem

News 

USENET news subsystem.

Syslogd 

messages generated internally by syslogd(8)

User 

(default) generic user-level messages

Uucp 

UUCP subsystem.

NoFacility 

Definition at line 96 of file syslog.h.

◆ OptionFlag

The option argument specifies flags which control the operation of open() and subsequent calls to log()

Enumerator
Console 

Write directly to system console if there is an error while sending to system logger.

NoDelay 

Open the connection immediately (normally, the connection is opened when the first message is logged).

NoWait 

Don't wait for child processes that may have been created while logging the message. (The GNU C library does not create a child process, so this option has no effect on Linux.)

Delay 

The converse of LOG_NDELAY; opening of the connection is delayed until syslog() is called. (This is the default, and need not be specified.)

Perror 

(Not in POSIX.1-2001 or POSIX.1-2008.) Print to stderr as well.

Pid 

Include PID with each message.

NoOption 

Definition at line 125 of file syslog.h.

◆ Priority

importance of the message

This determines the importance of the message. The levels are, in order of decreasing importance

Enumerator
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 message

Debug 

debug-level message

NoPriority 

Definition at line 76 of file syslog.h.

Constructor & Destructor Documentation

◆ SysLog()

Piduino::SysLog::SysLog ( Priority  initialPrio = Info)

Constructor.

Parameters
initialPrioinitial priority

◆ ~SysLog()

Piduino::SysLog::~SysLog ( )

Destructor.

Member Function Documentation

◆ cerrToSyslog()

static void Piduino::SysLog::cerrToSyslog ( )
static

redirect std::cerr to the system logger

◆ close()

void Piduino::SysLog::close ( )

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

The use of close() is optional.

◆ coutToSyslog()

static void Piduino::SysLog::coutToSyslog ( )
static

redirect std::cout to the system logger

◆ facility()

Facility Piduino::SysLog::facility ( ) const
inline

Reads the current facility.

The facility argument is used to specify what type of program is logging the message. This lets the configuration file specify that messages from different facilities will be handled differently.

Definition at line 228 of file syslog.h.

References m_facility.

Referenced by facilityName().

◆ facilityName() [1/2]

std::string Piduino::SysLog::facilityName ( ) const
inline

Name of the current facility.

Returns
the facilty name, "Unknown" if is not opened

Definition at line 236 of file syslog.h.

References facility(), and facilityName().

Referenced by facilityName().

Here is the call graph for this function:

◆ facilityName() [2/2]

static std::string Piduino::SysLog::facilityName ( const Facility facility)
static

Name of a facility.

◆ is_open()

bool Piduino::SysLog::is_open ( ) const
inline

Returns whether the object is currently associated to the system logger.

Definition at line 169 of file syslog.h.

References m_isopen.

◆ log() [1/2]

void Piduino::SysLog::log ( const char *  format,
  ... 
)

Generates a log message This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ log() [2/2]

void Piduino::SysLog::log ( Priority  p,
const char *  format,
  ... 
)

Generates a log message.

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.

◆ mask()

int Piduino::SysLog::mask ( ) const
inline

Definition at line 205 of file syslog.h.

◆ open() [1/3]

void Piduino::SysLog::open ( const char *  ident,
const SysLog::Facility facility,
const SysLog::Option option 
)
private

◆ open() [2/3]

void Piduino::SysLog::open ( const std::string &  ident,
const SysLog::Facility facility = User,
const SysLog::Option option = Pid 
)

Opens a connection to the system logger.

The string pointed to by ident is prepended to every message, and is typically set to the program name.

◆ open() [3/3]

void Piduino::SysLog::open ( const SysLog::Facility facility = User,
const SysLog::Option option = Pid 
)

Opens a connection to the system logger This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ option()

Option Piduino::SysLog::option ( ) const
inline

Reads the current option flags.

Definition at line 243 of file syslog.h.

References m_option.

◆ priority()

Priority Piduino::SysLog::priority ( ) const
inline

Definition at line 213 of file syslog.h.

References Piduino::SysLogBuffer::priority().

Referenced by priorityName().

Here is the call graph for this function:

◆ priorityName() [1/2]

std::string Piduino::SysLog::priorityName ( ) const
inline

Definition at line 217 of file syslog.h.

References priority(), and priorityName().

Referenced by priorityName().

Here is the call graph for this function:

◆ priorityName() [2/2]

static std::string Piduino::SysLog::priorityName ( Priority  p)
static

Name of a priority.

◆ setMask()

void Piduino::SysLog::setMask ( Priority  p)
inline

Definition at line 197 of file syslog.h.

◆ setMaskUpTo()

void Piduino::SysLog::setMaskUpTo ( Priority  p)
inline

Definition at line 201 of file syslog.h.

◆ setPriority() [1/2]

void Piduino::SysLogBuffer::setPriority ( const int  priority)
protectedinherited

Referenced by setPriority().

◆ setPriority() [2/2]

void Piduino::SysLog::setPriority ( Priority  p = Info)
inline

Definition at line 209 of file syslog.h.

References Piduino::SysLogBuffer::setPriority().

Referenced by Piduino::operator<<().

Here is the call graph for this function:

◆ sync()

int Piduino::SysLogBuffer::sync ( )
protectedinherited

Member Data Documentation

◆ m_facility

Facility Piduino::SysLog::m_facility
private

Definition at line 269 of file syslog.h.

Referenced by facility().

◆ m_isopen

bool Piduino::SysLog::m_isopen
private

Definition at line 270 of file syslog.h.

Referenced by is_open().

◆ m_option

Option Piduino::SysLog::m_option
private

Definition at line 268 of file syslog.h.

Referenced by option().

◆ m_priority

int Piduino::SysLogBuffer::m_priority
privateinherited

Definition at line 58 of file syslog.h.

Referenced by Piduino::SysLogBuffer::priority().