1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_core_tracing_Configuration_hpp
38 #define anna_core_tracing_Configuration_hpp
42 #include <anna/core/Singleton.hpp>
43 #include <anna/core/tracing/Logger.hpp>
45 #include <anna/core/util/RegularExpression.hpp>
59 * Class used for selective tracing configuration
61 class Configuration : public anna::Singleton <Configuration> {
66 typedef std::map<anna::RegularExpression, anna::Logger::Level> trace_trigger_map_t;
70 trace_trigger_map_t a_traceTriggers; // configured triggers map, for selective tracing
71 bool a_readTraceTriggersAsRegexp; // boolean to configure the way in which trace triggers are interpreted
74 Configuration() { a_readTraceTriggersAsRegexp = false; } // private constructor
76 friend class anna::Singleton <Configuration>;
77 friend class TraceLevelChecker;
80 const trace_trigger_map_t & getTraceTriggers() const throw() { return a_traceTriggers; }
86 * Deletes all added triggers for selective tracing.
88 void resetTraceTriggers() throw() { a_traceTriggers.clear(); }
92 * Activates a trigger for selective tracing. The normal way is to activate only one
93 * (usually applications register MSISDN, but we prefer the name 'trigger' because
94 * selective tracing capabilities are generalized for any context data we want to detect).
95 * Anyway, it is possible to add several string references for multiple context log activation.
97 * @param trigger String reference for contexts comparison
98 * @param accumulate Boolean for trigger filter accumulation over internal set. I.e., application
99 * could test any MSISDN within a configured set. False by default, means activation for only one
101 * @param level Desired trace level when context fulfill this trigger reference. Debug by default
103 void activateTraceTrigger(const std::string & trigger, bool accumulate = false, anna::Logger::Level level = anna::Logger::Debug) throw();
107 * Deletes a trigger for selective tracing.
109 * @param trigger String reference to be erased from internal trigger set
111 void deactivateTraceTrigger(const std::string & trigger) throw();
115 * Interpret all trace triggers as regular expressions.
116 * Is used from TraceLevelChecker to provide strict or regexp-based checkings.
117 * If not configured, regexp is disabled.
119 * @return Boolean about if regular expressions interpretation are activated.
121 bool readRegexpForTraceTriggers() const throw() { return (a_readTraceTriggersAsRegexp); }
125 * Configure all trace triggers to be interpreted as regular expressions.
126 * Application can set this depending on trace filtering needs.
127 * If not configured, regexp is disabled for TraceLevelChecker.
129 * @param readRegexp Boolean for activation/deactivation of regexp funtionality
131 void useRegexpForTraceTriggers(bool readRegexp = true) throw() { a_readTraceTriggersAsRegexp = readRegexp; }
135 * Class string representation
137 * @return String with class content
139 std::string asString(void) const throw();