Remove dynamic exceptions
[anna.git] / include / anna / core / tracing / Configuration.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #ifndef anna_core_tracing_Configuration_hpp
10 #define anna_core_tracing_Configuration_hpp
11
12
13
14 #include <anna/core/Singleton.hpp>
15 #include <anna/core/tracing/Logger.hpp>
16
17 #include <anna/core/util/RegularExpression.hpp>
18
19 // STL
20 #include <string>
21 #include <map>
22
23
24
25 namespace anna {
26
27 namespace tracing {
28
29
30 /**
31 * Class used for selective tracing configuration
32 */
33 class Configuration : public anna::Singleton <Configuration> {
34
35
36 public:
37
38   typedef std::map<anna::RegularExpression, anna::Logger::Level> trace_trigger_map_t;
39
40 private:
41
42   trace_trigger_map_t a_traceTriggers; // configured triggers map, for selective tracing
43   bool a_readTraceTriggersAsRegexp; // boolean to configure the way in which trace triggers are interpreted
44
45
46   Configuration() { a_readTraceTriggersAsRegexp = false; }  // private constructor
47
48   friend class anna::Singleton <Configuration>;
49   friend class TraceLevelChecker;
50
51
52   const trace_trigger_map_t & getTraceTriggers() const { return a_traceTriggers; }
53
54
55 public:
56
57   /**
58   * Deletes all added triggers for selective tracing.
59   */
60   void resetTraceTriggers() { a_traceTriggers.clear(); }
61
62
63   /**
64   * Activates a trigger for selective tracing. The normal way is to activate only one
65   * (usually applications register MSISDN, but we prefer the name 'trigger' because
66   * selective tracing capabilities are generalized for any context data we want to detect).
67   * Anyway, it is possible to add several string references for multiple context log activation.
68   *
69   * @param trigger String reference for contexts comparison
70   * @param accumulate Boolean for trigger filter accumulation over internal set. I.e., application
71   * could test any MSISDN within a configured set. False by default, means activation for only one
72   * trigger reference.
73   * @param level Desired trace level when context fulfill this trigger reference. Debug by default
74   */
75   void activateTraceTrigger(const std::string & trigger, bool accumulate = false, anna::Logger::Level level = anna::Logger::Debug) ;
76
77
78   /**
79   * Deletes a trigger for selective tracing.
80   *
81   * @param trigger String reference to be erased from internal trigger set
82   */
83   void deactivateTraceTrigger(const std::string & trigger) ;
84
85
86   /**
87   * Interpret all trace triggers as regular expressions.
88   * Is used from TraceLevelChecker to provide strict or regexp-based checkings.
89   * If not configured, regexp is disabled.
90   *
91   * @return Boolean about if regular expressions interpretation are activated.
92   */
93   bool readRegexpForTraceTriggers() const { return (a_readTraceTriggersAsRegexp); }
94
95
96   /**
97   * Configure all trace triggers to be interpreted as regular expressions.
98   * Application can set this depending on trace filtering needs.
99   * If not configured, regexp is disabled for TraceLevelChecker.
100   *
101   * @param readRegexp Boolean for activation/deactivation of regexp funtionality
102   */
103   void useRegexpForTraceTriggers(bool readRegexp = true) { a_readTraceTriggersAsRegexp = readRegexp; }
104
105
106   /**
107   * Class string representation
108   *
109   * @return String with class content
110   */
111   std::string asString(void) const ;
112 };
113
114 }
115 }
116
117 #endif
118