admin
2023-02-09 125db633619a0b4c7bd1d498ea2bf1cefa4f73d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * SyslogAppender.hh
 *
 * Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
 * Copyright 2000, Bastiaan Bakker. All rights reserved.
 *
 * See the COPYING file for the terms of usage and distribution.
 */
 
#ifndef _LOG4CPP_SYSLOGAPPENDER_HH
#define _LOG4CPP_SYSLOGAPPENDER_HH
 
#include <log4cpp/Portability.hh>
#include <string>
#include <stdarg.h>
#include <syslog.h>
#include <log4cpp/LayoutAppender.hh>
#include <log4cpp/Priority.hh>
 
namespace log4cpp {
 
    /**
     * SyslogAppender sends LoggingEvents to the local syslog system.
     **/
    class SyslogAppender : public LayoutAppender {
        public:
 
        /**
         * Translates a log4cpp priority to a syslog priority
         * @param priority The log4cpp priority.
         * @returns the syslog priority.
         **/
        static int toSyslogPriority(Priority::Value priority);
 
        /**
         * Instantiate a SyslogAppender with given name and name and facility
         * for syslog. Note that the C syslog API is process global, so 
         * instantion of a second SyslogAppender will 'overwrite' the 
         * syslog name of the first.
         * @param name The name of the Appender
         * @param syslogName The ident parameter in the openlog(3) call.
         * @param facility The syslog facility to log to. Defaults to LOG_USER.
         **/         
        SyslogAppender(const std::string& name, const std::string& syslogName, 
                       int facility = LOG_USER);
        virtual ~SyslogAppender();
 
        /**
         * Calls closelog(3) and openlog(3).
         **/
        virtual bool reopen();
 
        /**
         * Calls closelog(3) to close the syslog file descriptor.
         **/
        virtual void close();
 
       protected:
        
        /**
         * Calls openlog(3).
         **/
        virtual void open();
 
        /**
         * Sends a LoggingEvent to syslog.
         * @param event the LoggingEvent to log.
         **/
        virtual void _append(const LoggingEvent& event);
 
        const std::string _syslogName;
        int _facility;
    };
}
 
#endif // _LOG4CPP_SYSLOGAPPENDER_HH