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