1 // level.hpp 2 3 // Boost Logging library 4 // 5 // Author: John Torjo, www.torjo.com 6 // 7 // Copyright (C) 2007 John Torjo (see www.torjo.com for email) 8 // 9 // Distributed under the Boost Software License, Version 1.0. 10 // (See accompanying file LICENSE_1_0.txt or copy at 11 // http://www.boost.org/LICENSE_1_0.txt) 12 // 13 // See http://www.boost.org for updates, documentation, and revision history. 14 // See http://www.torjo.com/log2/ for more details 15 16 17 #ifndef JT28092007_level_HPP_DEFINED 18 #define JT28092007_level_HPP_DEFINED 19 20 #include <hpx/util/logging/detail/fwd.hpp> 21 22 namespace hpx { namespace util { namespace logging { 23 24 /** 25 @brief Handling levels - classes that can hold and/or deal with levels 26 - filters and level holders 27 28 By default we have these levels: 29 30 - debug (smallest level), 31 - info, 32 - warning , 33 - error , 34 - fatal (highest level) 35 36 Depending on which level is enabled for your application, 37 some messages will reach the log: those 38 messages having at least that level. For instance, if info level is enabled, all 39 logged messages will reach the log. 40 If warning level is enabled, all messages are logged, but the warnings. 41 If debug level is enabled, messages that have levels debug, 42 error, fatal will be logged. 43 44 */ 45 namespace level { 46 /** the higher the level, the more critical the error */ 47 typedef unsigned int type; 48 49 enum { 50 disable_all = -1, 51 enable_all = 0, 52 debug = 1000, 53 info = 2000, 54 warning = 3000, 55 error = 4000, 56 fatal = 5000, 57 always = 6000 58 }; 59 60 /** 61 @brief Filter - holds the level. 62 63 Holds the level, and tells you if a specific level is enabled. 64 It does this in a non-thread-safe way. 65 66 If you change set_enabled() while program is running, 67 it can take a bit to propagate 68 between threads. Most of the time, this should be acceptable. 69 */ 70 struct holder { holderhpx::util::logging::level::holder71 holder(type default_level = enable_all) : m_level(default_level) {} is_enabledhpx::util::logging::level::holder72 bool is_enabled(type level) const { return level >= m_level; } set_enabledhpx::util::logging::level::holder73 void set_enabled(type level) { 74 m_level = level; 75 } 76 private: 77 type m_level; 78 }; 79 80 /** 81 @brief Filter - holds the level 82 - and tells you at compile time if a filter is enabled or not. 83 84 Fix (compile time) holder 85 */ 86 template<int fix_level = debug> struct holder_compile_time { is_enabledhpx::util::logging::level::holder_compile_time87 static bool is_enabled(type level) { 88 return fix_level >= level; 89 } 90 }; 91 } // namespace level 92 93 }}} 94 95 #endif 96