AnCH Framework  0.1
Another C++ Hack Framework
writer.hpp
1 /*
2  ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3  Copyright (C) 2012 Vincent Lachenal
4 
5  This file is part of ANCH Framework.
6 
7  ANCH Framework is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  ANCH Framework is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19 */
20 #ifndef _ANCH_LOGGER_WRITER_H_
21 #define _ANCH_LOGGER_WRITER_H_
22 
23 #include <iostream>
24 
25 #include "logger/levels.hpp"
26 #include "logger/formatter/messageFormatter.hpp"
27 
28 
29 namespace anch {
30  namespace logger {
31 
37  class Writer {
38  // Attributes +
39  protected:
41  std::ostream* _output;
42 
45 
46  private:
48  std::string _fileName;
49 
51  int _maxSize;
52 
54  int _maxIndex;
55 
57  int _fileIndex;
58  // Attributes -
59 
60  public:
61  // Constructors +
70  Writer(const std::string& fileName,
71  const std::string& linePattern,
72  int maxSize = 0,
73  int maxIndex = 0);
74 
81  Writer(std::ostream* output, const std::string& linePattern);
82  // Constructors -
83 
84  // Destructor +
88  virtual ~Writer();
89  // Destructor -
90 
91  public:
99  virtual void write(const std::string& category,
100  const anch::logger::Level& level,
101  const std::string& message);
102 
103  protected:
109  inline bool rotate() const {
110  return (_maxSize > 0 && _fileName != "" && _output->tellp() >= _maxSize);
111  }
112 
116  void rotateFiles();
117 
118  };
119 
120  }
121 }
122 
123 #endif // _ANCH_LOGGER_WRITER_H_
std::ostream * _output
Definition: writer.hpp:41
Definition: messageFormatter.hpp:53
AnCH framework base namespace.
Definition: base64.hpp:28
virtual ~Writer()
Definition: writer.cpp:103
bool rotate() const
Definition: writer.hpp:109
Writer(const std::string &fileName, const std::string &linePattern, int maxSize=0, int maxIndex=0)
Definition: writer.cpp:51
anch::logger::formatter::MessageFormatter _formatter
Definition: writer.hpp:44
void rotateFiles()
Definition: writer.cpp:132
Level
Definition: levels.hpp:34
Definition: writer.hpp:37
virtual void write(const std::string &category, const anch::logger::Level &level, const std::string &message)
Definition: writer.cpp:119