1 /* 2 ** Copyright 2011-2013 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_BACKEND_HH 20 #define CC_LOGGING_BACKEND_HH 21 22 #include <mutex> 23 #include "com/centreon/namespace.hh" 24 25 CC_BEGIN() 26 27 namespace misc { 28 class stringifier; 29 } 30 31 namespace logging { 32 enum time_precision { none = 0, microsecond = 1, millisecond = 2, second = 3 }; 33 34 /** 35 * @class backend backend.hh "com/centreon/logging/backend.hh" 36 * @brief Base logging backend class. 37 * 38 * This class defines an interface to create logger backend, to 39 * log data into many different objects. 40 */ 41 class backend { 42 public: 43 backend(bool is_sync = true, 44 bool show_pid = true, 45 time_precision show_timestamp = second, 46 bool show_thread_id = false); 47 backend(backend const& right); 48 virtual ~backend() noexcept; 49 backend& operator=(backend const& right); 50 virtual void close() noexcept = 0; 51 virtual bool enable_sync() const; 52 virtual void enable_sync(bool enable); 53 virtual void log(uint64_t types, uint32_t verbose, char const* msg) noexcept; 54 virtual void log(uint64_t types, 55 uint32_t verbose, 56 char const* msg, 57 uint32_t size) noexcept = 0; 58 virtual void open() = 0; 59 virtual void reopen() = 0; 60 virtual bool show_pid() const; 61 virtual void show_pid(bool enable); 62 virtual time_precision show_timestamp() const; 63 virtual void show_timestamp(time_precision val); 64 virtual bool show_thread_id() const; 65 virtual void show_thread_id(bool enable); 66 67 protected: 68 void _build_header(misc::stringifier& buffer); 69 70 bool _is_sync; 71 mutable std::recursive_mutex _lock; 72 bool _show_pid; 73 time_precision _show_timestamp; 74 bool _show_thread_id; 75 76 protected: 77 void _internal_copy(backend const& right); 78 }; 79 } // namespace logging 80 81 CC_END() 82 83 #endif // !CC_LOGGING_BACKEND_HH 84