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
12 * Zalanyi, Balazs Andor
15 ******************************************************************************/
16 #include "LoggerPlugin.hh"
18 #include "../common/memory.h"
20 #include "TitanLoggerApi.hh"
23 #include "ILoggerPlugin.hh"
27 // constructor for dynamic plug-in
28 LoggerPlugin::LoggerPlugin(const char *path
) :
29 ref_(NULL
), handle_(NULL
), filename_(NULL
), create_(NULL
),
30 is_log2str_capable_(false)
33 this->filename_
= mcopystr(path
);
36 // constructor for static plug-in
37 // Rant. The logical thing would be for the type of the parameter to be
38 // cb_create_plugin (which is already a pointer). But calling
39 // LoggerPlugin(create_legacy_logger) results in the wrong value being passed
40 // to the function. So the call has to be written as
41 // LoggerPlugin(&create_legacy_logger), which means that the type
42 // of the parameter has to be _pointer_to_ cb_create_plugin.
43 LoggerPlugin::LoggerPlugin(cb_create_plugin
*create
) :
44 ref_(NULL
), handle_(NULL
), filename_(NULL
),
45 // We want the create_ member to be cb_create_plugin, to be able to call
46 // this->create_(). Hence the need for this hideous cast.
47 create_((cb_create_plugin
)(unsigned long)create
),
48 is_log2str_capable_(false)
52 LoggerPlugin::~LoggerPlugin()
54 Free(this->filename_
);
57 //void LoggerPlugin::load()
59 //void LoggerPlugin::unload()
61 void LoggerPlugin::reset()
66 void LoggerPlugin::open_file(bool is_first
)
68 this->ref_
->open_file(is_first
);
71 void LoggerPlugin::close_file()
73 this->ref_
->close_file();
76 void LoggerPlugin::set_file_name(const char *new_filename_skeleton
,
79 this->ref_
->set_file_name(new_filename_skeleton
, from_config
);
82 void LoggerPlugin::set_append_file(bool new_append_file
)
84 this->ref_
->set_append_file(new_append_file
);
87 bool LoggerPlugin::set_file_size(int p_size
)
89 return this->ref_
->set_file_size(p_size
);
92 bool LoggerPlugin::set_file_number(int p_number
)
94 return this->ref_
->set_file_number(p_number
);
97 bool LoggerPlugin::set_disk_full_action(TTCN_Logger::disk_full_action_t p_disk_full_action
)
99 return this->ref_
->set_disk_full_action(p_disk_full_action
);
102 void LoggerPlugin::set_parameter(const char* param_name
, const char* param_value
)
104 this->ref_
->set_parameter(param_name
, param_value
);
107 int LoggerPlugin::log(const TitanLoggerApi::TitanLogEvent
& event
,
108 bool log_buffered
, bool separate_file
, bool use_emergency_mask
)
110 if (!this->ref_
) return 1;
111 this->ref_
->log(event
, log_buffered
, separate_file
, use_emergency_mask
);
115 CHARSTRING
LoggerPlugin::log2str(const TitanLoggerApi::TitanLogEvent
& event
) const
118 if (!this->is_log2str_capable_
) return CHARSTRING();
119 return this->ref_
->log2str(event
);
122 const char *LoggerPlugin::plugin_name() const
125 return this->ref_
->plugin_name();
128 bool LoggerPlugin::is_configured() const
130 return this->ref_
!= NULL
&& this->ref_
->is_configured();
133 void LoggerPlugin::set_configured(bool configured
)
135 if (this->ref_
!= NULL
)
136 this->ref_
->set_configured(configured
);