1
// ------------------------------------------------------------------------
2
// eca-logger.cpp: A logging subsystem implemented as a singleton class
3
// Copyright (C) 2002 Kai Vehmanen
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
// ------------------------------------------------------------------------
21
#include <kvu_locks.h>
23
#include "eca-logger-interface.h"
24
#include "eca-logger-default.h"
25
#include "eca-logger.h"
27
ECA_LOGGER_INTERFACE* ECA_LOGGER::interface_impl_repp = 0;
28
pthread_mutex_t ECA_LOGGER::lock_rep = PTHREAD_MUTEX_INITIALIZER;
30
static const char *level_descs[] = {
43
ECA_LOGGER_INTERFACE& ECA_LOGGER::instance(void)
46
// Note! Below we use the Double-Checked Locking Pattern
47
// to protect against concurrent access
49
if (ECA_LOGGER::interface_impl_repp == 0) {
50
KVU_GUARD_LOCK guard(&ECA_LOGGER::lock_rep);
51
if (ECA_LOGGER::interface_impl_repp == 0) {
52
ECA_LOGGER::interface_impl_repp = new ECA_LOGGER_DEFAULT();
55
return(*interface_impl_repp);
58
void ECA_LOGGER::attach_logger(ECA_LOGGER_INTERFACE* logger)
61
if (interface_impl_repp != 0) {
62
oldloglevel = interface_impl_repp->get_log_level_bitmask();
64
ECA_LOGGER::detach_logger();
65
if (ECA_LOGGER::interface_impl_repp == 0) {
66
KVU_GUARD_LOCK guard(&ECA_LOGGER::lock_rep);
67
if (ECA_LOGGER::interface_impl_repp == 0) {
68
ECA_LOGGER::interface_impl_repp = logger;
69
if (oldloglevel != -1) {
70
logger->set_log_level_bitmask(oldloglevel);
74
DBC_ENSURE(ECA_LOGGER::interface_impl_repp == logger);
78
* Detaches the current logger implementation.
80
void ECA_LOGGER::detach_logger(void)
82
if (ECA_LOGGER::interface_impl_repp != 0) {
83
KVU_GUARD_LOCK guard(&ECA_LOGGER::lock_rep);
84
if (ECA_LOGGER::interface_impl_repp != 0) {
85
delete ECA_LOGGER::interface_impl_repp;
86
ECA_LOGGER::interface_impl_repp = 0;
89
DBC_ENSURE(ECA_LOGGER::interface_impl_repp == 0);
92
const char* ECA_LOGGER::level_to_string(ECA_LOGGER::Msg_level_t arg)
96
case ECA_LOGGER::errors: return level_descs[0];
97
case ECA_LOGGER::info: return level_descs[1];
98
case ECA_LOGGER::subsystems: return level_descs[2];
99
case ECA_LOGGER::module_names: return level_descs[3];
100
case ECA_LOGGER::user_objects: return level_descs[4];
101
case ECA_LOGGER::system_objects: return level_descs[5];
102
case ECA_LOGGER::functions: return level_descs[6];
103
case ECA_LOGGER::continuous: return level_descs[7];
104
case ECA_LOGGER::eiam_return_values: return level_descs[8];
105
default: return level_descs[9];