1//
2// SyslogChannel.h
3//
4// Library: Foundation
5// Package: Logging
6// Module: SyslogChannel
7//
8// Definition of the SyslogChannel class specific to UNIX.
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_SyslogChannel_INCLUDED
18#define Foundation_SyslogChannel_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/Channel.h"
23
24
25namespace Poco {
26
27
28class Foundation_API SyslogChannel: public Channel
29 /// This Unix-only channel works with the Unix syslog service.
30{
31public:
32 enum Option
33 {
34 SYSLOG_PID = 0x01, /// log the pid with each message
35 SYSLOG_CONS = 0x02, /// log on the console if errors in sending
36 SYSLOG_NDELAY = 0x08, /// don't delay open
37 SYSLOG_PERROR = 0x20 /// log to stderr as well (not supported on all platforms)
38 };
39
40 enum Facility
41 {
42 SYSLOG_KERN = ( 0<<3), /// kernel messages
43 SYSLOG_USER = ( 1<<3), /// random user-level messages
44 SYSLOG_MAIL = ( 2<<3), /// mail system
45 SYSLOG_DAEMON = ( 3<<3), /// system daemons
46 SYSLOG_AUTH = ( 4<<3), /// security/authorization messages
47 SYSLOG_SYSLOG = ( 5<<3), /// messages generated internally by syslogd
48 SYSLOG_LPR = ( 6<<3), /// line printer subsystem
49 SYSLOG_NEWS = ( 7<<3), /// network news subsystem
50 SYSLOG_UUCP = ( 8<<3), /// UUCP subsystem
51 SYSLOG_CRON = ( 9<<3), /// clock daemon
52 SYSLOG_AUTHPRIV = (10<<3), /// security/authorization messages (private)
53 SYSLOG_FTP = (11<<3), /// ftp daemon
54 SYSLOG_LOCAL0 = (16<<3), /// reserved for local use
55 SYSLOG_LOCAL1 = (17<<3), /// reserved for local use
56 SYSLOG_LOCAL2 = (18<<3), /// reserved for local use
57 SYSLOG_LOCAL3 = (19<<3), /// reserved for local use
58 SYSLOG_LOCAL4 = (20<<3), /// reserved for local use
59 SYSLOG_LOCAL5 = (21<<3), /// reserved for local use
60 SYSLOG_LOCAL6 = (22<<3), /// reserved for local use
61 SYSLOG_LOCAL7 = (23<<3) /// reserved for local use
62 };
63
64 SyslogChannel();
65 /// Creates a SyslogChannel.
66
67 SyslogChannel(const std::string& name, int options = SYSLOG_CONS, int facility = SYSLOG_USER);
68 /// Creates a SyslogChannel with the given name, options and facility.
69
70 void open();
71 /// Opens the SyslogChannel.
72
73 void close();
74 /// Closes the SyslogChannel.
75
76 void log(const Message& msg);
77 /// Sens the message's text to the syslog service.
78
79 void setProperty(const std::string& name, const std::string& value);
80 /// Sets the property with the given value.
81 ///
82 /// The following properties are supported:
83 /// * name: The name used to identify the source of log messages.
84 /// * facility: The facility added to each log message. See the Facility enumeration for a list of supported values.
85 /// * options: The logging options. See the Option enumeration for a list of supported values.
86
87 std::string getProperty(const std::string& name) const;
88 /// Returns the value of the property with the given name.
89
90 static const std::string PROP_NAME;
91 static const std::string PROP_FACILITY;
92 static const std::string PROP_OPTIONS;
93
94protected:
95 ~SyslogChannel();
96 static int getPrio(const Message& msg);
97
98private:
99 std::string _name;
100 int _options;
101 int _facility;
102 bool _open;
103};
104
105
106} // namespace Poco
107
108
109#endif // Foundation_SyslogChannel_INCLUDED
110