~ubuntu-branches/ubuntu/trusty/log4shib/trusty

« back to all changes in this revision

Viewing changes to include/log4shib/FileAppender.hh

  • Committer: Package Import Robot
  • Author(s): Russ Allbery
  • Date: 2012-06-05 21:20:25 UTC
  • Revision ID: package-import@ubuntu.com-20120605212025-uyigtav7dqwvnf41
Tags: upstream-1.0.4
ImportĀ upstreamĀ versionĀ 1.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * FileAppender.hh
 
3
 *
 
4
 * Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
 
5
 * Copyright 2000, Bastiaan Bakker. All rights reserved.
 
6
 *
 
7
 * See the COPYING file for the terms of usage and distribution.
 
8
 */
 
9
 
 
10
#ifndef _LOG4SHIB_FILEAPPENDER_HH
 
11
#define _LOG4SHIB_FILEAPPENDER_HH
 
12
 
 
13
#include <log4shib/Portability.hh>
 
14
#include <log4shib/LayoutAppender.hh>
 
15
#include <string>
 
16
#include <stdarg.h>
 
17
 
 
18
namespace log4shib {
 
19
 
 
20
    class LOG4SHIB_EXPORT FileAppender : public LayoutAppender {
 
21
        public:
 
22
 
 
23
        /**
 
24
           Constructs a FileAppender.
 
25
           @param name the name of the Appender.
 
26
           @param fileName the name of the file to which the Appender has 
 
27
           to log.
 
28
           @param append whether the Appender has to truncate the file or
 
29
           just append to it if it already exists. Defaults to 'true'.
 
30
           @param mode file mode to open the logfile with. Defaults to 00644.
 
31
        **/  
 
32
        FileAppender(const std::string& name, const std::string& fileName,
 
33
                     bool append = true, mode_t mode = 00644);
 
34
 
 
35
        /**
 
36
           Constructs a FileAppender to an already open file descriptor.
 
37
           @param name the name of the Appender.
 
38
           @param fd the file descriptor to which the Appender has to log.
 
39
        **/
 
40
        FileAppender(const std::string& name, int fd);
 
41
        virtual ~FileAppender();
 
42
        
 
43
        /**
 
44
           Reopens the logfile. 
 
45
           This can be useful for logfiles that are rotated externally,
 
46
           e.g. by logrotate. This method is a NOOP for FileAppenders that
 
47
           have been constructed with a file descriptor.           
 
48
           @returns true if the reopen succeeded.
 
49
        **/
 
50
        virtual bool reopen();
 
51
 
 
52
        /**
 
53
           Closes the logfile.
 
54
        **/
 
55
        virtual void close();
 
56
 
 
57
        /**
 
58
           Sets the append vs truncate flag.
 
59
           NB. currently the FileAppender opens the logfile in the 
 
60
           constructor. Therefore this method is too late to influence the 
 
61
           first file opening. We'll need something similar to log4j's
 
62
           activateOptions().
 
63
           @param append false to truncate, true to append
 
64
        **/
 
65
        virtual void setAppend(bool append);
 
66
 
 
67
        /**
 
68
           Gets the value of the 'append' option.
 
69
        **/
 
70
        virtual bool getAppend() const;
 
71
 
 
72
        /**
 
73
           Sets the file open mode.
 
74
        **/
 
75
        virtual void setMode(mode_t mode);
 
76
 
 
77
        /**
 
78
           Gets the file open mode.
 
79
        **/
 
80
        virtual mode_t getMode() const;
 
81
 
 
82
        protected:
 
83
        virtual void _append(const LoggingEvent& event);
 
84
 
 
85
        const std::string _fileName;
 
86
        int _fd;
 
87
        int _flags;
 
88
        mode_t _mode;
 
89
    };
 
90
}
 
91
 
 
92
#endif // _LOG4SHIB_FILEAPPENDER_HH