1 /* 2 ** Copyright 2011-2014 Centreon 3 ** 4 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** you may not use this file except in compliance with the License. 6 ** You may obtain a copy of the License at 7 ** 8 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** 10 ** Unless required by applicable law or agreed to in writing, software 11 ** distributed under the License is distributed on an "AS IS" BASIS, 12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 ** See the License for the specific language governing permissions and 14 ** limitations under the License. 15 ** 16 ** For more information : contact@centreon.com 17 */ 18 19 #ifndef CC_LOGGING_FILE_HH 20 #define CC_LOGGING_FILE_HH 21 22 #include <cstdio> 23 #include <string> 24 #include "com/centreon/logging/backend.hh" 25 #include "com/centreon/namespace.hh" 26 27 CC_BEGIN() 28 29 namespace logging { 30 /** 31 * @class file file.hh "com/centreon/logging/file.hh" 32 * @brief Log messages to file. 33 */ 34 class file : public backend { 35 public: 36 file(FILE* file, 37 bool is_sync = true, 38 bool show_pid = true, 39 time_precision show_timestamp = second, 40 bool show_thread_id = false, 41 uint64_t max_size = 0); 42 file(std::string const& path, 43 bool is_sync = true, 44 bool show_pid = true, 45 time_precision show_timestamp = second, 46 bool show_thread_id = false, 47 uint64_t max_size = 0); 48 virtual ~file() noexcept; 49 void close() noexcept; 50 std::string const& filename() const noexcept; 51 void log(uint64_t types, 52 uint32_t verbose, 53 char const* msg, 54 uint32_t size) noexcept; 55 void open(); 56 void reopen(); 57 58 protected: 59 virtual void _max_size_reached(); 60 61 private: 62 file(file const& right); 63 file& operator=(file const& right); 64 void _flush() noexcept; 65 66 uint64_t _max_size; 67 std::string _path; 68 FILE* _out; 69 uint64_t _size; 70 }; 71 } // namespace logging 72 73 CC_END() 74 75 #endif // !CC_LOGGING_FILE_HH 76