Last sync 2016.04.01
[deliverable/titan.core.git] / core / TitanLoggerControlImpl.cc
CommitLineData
d44e3c4f 1/******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Kovacs, Ferenc
11 * Raduly, Csaba
12 *
13 ******************************************************************************/
970ed795
EL
14#include "Error.hh"
15#include "TitanLoggerControl.hh"
16#include "Logger.hh"
17#include "LoggingBits.hh"
18#include "Component.hh"
19
20// TODO: We should ask somebody instead...
21const char LegacyLoggerName[] = "LegacyLogger";
22
23void validate_plugin_name(CHARSTRING const& plugin)
24{
25 if (strcmp(LegacyLoggerName, (const char *)plugin))
26 TTCN_error("Only `%s' can be configured dynamically.", LegacyLoggerName);
27}
28
29namespace TitanLoggerControl {
30
31void set__log__file(CHARSTRING const& plugin, CHARSTRING const& filename)
32{
33 validate_plugin_name(plugin);
34
35 TTCN_Logger::set_file_name(filename, false);
36 TTCN_Logger::open_file();
37}
38
39void set__log__entity__name(CHARSTRING const& plugin, BOOLEAN const& log_it)
40{
41 validate_plugin_name(plugin);
42
43 TTCN_Logger::set_log_entity_name(log_it);
44}
45
46BOOLEAN get__log__entity__name(CHARSTRING const& plugin)
47{
48 validate_plugin_name(plugin);
49
50 return BOOLEAN(TTCN_Logger::get_log_entity_name());
51}
52
53void set__matching__verbosity(CHARSTRING const& plugin, verbosity const& v)
54{
55 validate_plugin_name(plugin);
56
57 TTCN_Logger::set_matching_verbosity(
58 static_cast<TTCN_Logger::matching_verbosity_t>(v.as_int()));
59}
60
61verbosity get__matching__verbosity(CHARSTRING const& plugin)
62{
63 validate_plugin_name(plugin);
64
65 verbosity retval(TTCN_Logger::get_matching_verbosity());
66 return retval;
67}
68
69Severities get__file__mask(CHARSTRING const& plugin)
70{
71 validate_plugin_name(plugin);
72
73 Severities retval(NULL_VALUE); // Empty but initialized.
74 Logging_Bits const& lb = TTCN_Logger::get_file_mask();
75 for (int i = 1, s = 0; i < TTCN_Logger::NUMBER_OF_LOGSEVERITIES; ++i) {
76 if (lb.bits[i]) {
77 retval[s++] = Severity(i);
78 // operator[] creates a new element and we assign a temporary to it
79 }
80 }
81
82 return retval;
83}
84
85Severities get__console__mask(CHARSTRING const& plugin)
86{
87 validate_plugin_name(plugin);
88
89 Severities retval(NULL_VALUE); // Empty but initialized.
90 Logging_Bits const& lb = TTCN_Logger::get_console_mask();
91 for (int i = 1, s = 0; i < TTCN_Logger::NUMBER_OF_LOGSEVERITIES; ++i) {
92 if (lb.bits[i]) {
93 retval[s++] = Severity(i);
94 // operator[] creates a new element and we assign a temporary to it
95 }
96 }
97
98 return retval;
99}
100
101void set__console__mask(CHARSTRING const& plugin, Severities const& mask)
102{
103 validate_plugin_name(plugin);
104
105 Logging_Bits lb(Logging_Bits::log_nothing);
106 for (int B = mask.size_of() - 1; B >= 0; B--) {
107 lb.add_sev(static_cast<TTCN_Logger::Severity>((int)mask[B]));
108 }
109 component_id_t cmpt_id = { COMPONENT_ID_COMPREF, { self } };
110 TTCN_Logger::set_console_mask(cmpt_id, lb);
111}
112
113void set__file__mask(CHARSTRING const& plugin, Severities const& mask)
114{
115 validate_plugin_name(plugin);
116
117 Logging_Bits lb(Logging_Bits::log_nothing);
118 for (int B = mask.size_of() - 1; B >= 0; B--) {
119 lb.add_sev(static_cast<TTCN_Logger::Severity>((int)mask[B]));
120 }
121 component_id_t cmpt_id = { COMPONENT_ID_COMPREF, { self } };
122 TTCN_Logger::set_file_mask(cmpt_id, lb);
123}
124
125void add__to__console__mask(CHARSTRING const& plugin, Severities const& mask)
126{
127 validate_plugin_name(plugin);
128
129 Logging_Bits lb(TTCN_Logger::get_console_mask());
130 for (int B = mask.size_of() - 1; B >= 0; B--) {
131 lb.add_sev(static_cast<TTCN_Logger::Severity>((int)mask[B]));
132 }
133 component_id_t cmpt_id = { COMPONENT_ID_COMPREF, { self } };
134 TTCN_Logger::set_console_mask(cmpt_id, lb);
135}
136
137void add__to__file__mask(CHARSTRING const& plugin, Severities const& mask)
138{
139 validate_plugin_name(plugin);
140
141 Logging_Bits lb(TTCN_Logger::get_file_mask());
142 for (int B = mask.size_of() - 1; B >= 0; B--) {
143 lb.add_sev(static_cast<TTCN_Logger::Severity>((int)mask[B]));
144 }
145 component_id_t cmpt_id = { COMPONENT_ID_COMPREF, { self } };
146 TTCN_Logger::set_file_mask(cmpt_id, lb);
147}
148
149void remove__from__console__mask(CHARSTRING const& plugin, Severities const& mask)
150{
151 validate_plugin_name(plugin);
152
153 Logging_Bits lb(TTCN_Logger::get_console_mask());
154 for (int B = mask.size_of() - 1; B >= 0; B--) {
155 TTCN_Logger::Severity sev = static_cast<TTCN_Logger::Severity>((int)mask[B]);
156 if (sev > 0 && sev < TTCN_Logger::NUMBER_OF_LOGSEVERITIES) {
157 lb.bits[sev] = false;
158 }
159 }
160 component_id_t cmpt_id = { COMPONENT_ID_COMPREF, { self } };
161 TTCN_Logger::set_console_mask(cmpt_id, lb);
162}
163
164void remove__from__file__mask(CHARSTRING const& plugin, Severities const& mask)
165{
166 validate_plugin_name(plugin);
167
168 Logging_Bits lb(TTCN_Logger::get_file_mask());
169 for (int B = mask.size_of() - 1; B >= 0; B--) {
170 TTCN_Logger::Severity sev = static_cast<TTCN_Logger::Severity>((int)mask[B]);
171 if (sev > 0 && sev < TTCN_Logger::NUMBER_OF_LOGSEVERITIES) {
172 lb.bits[sev] = false;
173 }
174 }
175 component_id_t cmpt_id = { COMPONENT_ID_COMPREF, { self } };
176 TTCN_Logger::set_file_mask(cmpt_id, lb);
177}
178
179} // namespace
This page took 0.02965 seconds and 5 git commands to generate.