source: XMLIO_V2/external/include/Poco/SimpleFileChannel.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 5.0 KB
Line 
1//
2// SimpleFileChannel.h
3//
4// $Id: //poco/1.3/Foundation/include/Poco/SimpleFileChannel.h#1 $
5//
6// Library: Foundation
7// Package: Logging
8// Module:  SimpleFileChannel
9//
10// Definition of the SimpleFileChannel class.
11//
12// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
15// Permission is hereby granted, free of charge, to any person or organization
16// obtaining a copy of the software and accompanying documentation covered by
17// this license (the "Software") to use, reproduce, display, distribute,
18// execute, and transmit the Software, and to prepare derivative works of the
19// Software, and to permit third-parties to whom the Software is furnished to
20// do so, all subject to the following:
21//
22// The copyright notices in the Software and this entire statement, including
23// the above license grant, this restriction and the following disclaimer,
24// must be included in all copies of the Software, in whole or in part, and
25// all derivative works of the Software, unless such copies or derivative
26// works are solely in the form of machine-executable object code generated by
27// a source language processor.
28//
29// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35// DEALINGS IN THE SOFTWARE.
36//
37
38
39#ifndef Foundation_SimpleFileChannel_INCLUDED
40#define Foundation_SimpleFileChannel_INCLUDED
41
42
43#include "Poco/Foundation.h"
44#include "Poco/Channel.h"
45#include "Poco/Timestamp.h"
46#include "Poco/Mutex.h"
47
48
49namespace Poco {
50
51
52class LogFile;
53
54
55class Foundation_API SimpleFileChannel: public Channel
56        /// A Channel that writes to a file. This class only
57        /// supports simple log file rotation.
58        ///
59        /// For more features, see the FileChannel class.
60        ///
61        /// Only the message's text is written, followed
62        /// by a newline.
63        ///
64        /// Chain this channel to a FormattingChannel with an
65        /// appropriate Formatter to control what is in the text.
66        ///
67        /// Log file rotation based on log file size is supported.
68        ///
69        /// If rotation is enabled, the SimpleFileChannel will
70        /// alternate between two log files. If the size of
71        /// the primary log file exceeds a specified limit,
72        /// the secondary log file will be used, and vice
73        /// versa.
74        ///
75        /// Log rotation is configured with the "rotation"
76        /// property, which supports the following values:
77        ///   * never:         no log rotation
78        ///   * <n>:           the file is rotated when its size exceeds
79        ///                    <n> bytes.
80        ///   * <n> K:         the file is rotated when its size exceeds
81        ///                    <n> Kilobytes.
82        ///   * <n> M:         the file is rotated when its size exceeds
83        ///                    <n> Megabytes.
84        ///
85        /// The path of the (primary) log file can be specified with
86        /// the "path" property. Optionally, the path of the secondary
87        /// log file can be specified with the "secondaryPath" property.
88        ///
89        /// If no secondary path is specified, the secondary path will
90        /// default to <primaryPath>.1.
91{
92public:
93        SimpleFileChannel();
94                /// Creates the FileChannel.
95
96        SimpleFileChannel(const std::string& path);
97                /// Creates the FileChannel for a file with the given path.
98
99        void open();
100                /// Opens the FileChannel and creates the log file if necessary.
101               
102        void close();
103                /// Closes the FileChannel.
104
105        void log(const Message& msg);
106                /// Logs the given message to the file.
107               
108        void setProperty(const std::string& name, const std::string& value);
109                /// Sets the property with the given name.
110                ///
111                /// The following properties are supported:
112                ///   * path:          The primary log file's path.
113                ///   * secondaryPath: The secondary log file's path.
114                ///   * rotation:      The log file's rotation mode. See the
115                ///                    SimpleFileChannel class for details.
116
117        std::string getProperty(const std::string& name) const;
118                /// Returns the value of the property with the given name.
119                /// See setProperty() for a description of the supported
120                /// properties.
121
122        Timestamp creationDate() const;
123                /// Returns the log file's creation date.
124               
125        UInt64 size() const;
126                /// Returns the log file's current size in bytes.
127
128        const std::string& path() const;
129                /// Returns the log file's primary path.
130
131        const std::string& secondaryPath() const;
132                /// Returns the log file's secondary path.
133
134        static const std::string PROP_PATH;
135        static const std::string PROP_SECONDARYPATH;
136        static const std::string PROP_ROTATION;
137
138protected:
139        ~SimpleFileChannel();
140        void setRotation(const std::string& rotation);
141        void rotate();
142
143private:
144        std::string      _path;
145        std::string      _secondaryPath;
146        std::string      _rotation;
147        UInt64           _limit;
148        LogFile*         _pFile;
149        FastMutex        _mutex;
150};
151
152
153} // namespace Poco
154
155
156#endif // Foundation_SimpleFileChannel_INCLUDED
Note: See TracBrowser for help on using the repository browser.