1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 #include "LoggerPlugin.hh"
10 #include "../common/memory.h"
12 #include "TitanLoggerApi.hh"
15 #include "ILoggerPlugin.hh"
19 // constructor for dynamic plug-in
20 LoggerPlugin::LoggerPlugin(const char *path
) :
21 ref_(NULL
), handle_(NULL
), filename_(NULL
), create_(NULL
),
22 is_log2str_capable_(false)
25 this->filename_
= mcopystr(path
);
28 // constructor for static plug-in
29 // Rant. The logical thing would be for the type of the parameter to be
30 // cb_create_plugin (which is already a pointer). But calling
31 // LoggerPlugin(create_legacy_logger) results in the wrong value being passed
32 // to the function. So the call has to be written as
33 // LoggerPlugin(&create_legacy_logger), which means that the type
34 // of the parameter has to be _pointer_to_ cb_create_plugin.
35 LoggerPlugin::LoggerPlugin(cb_create_plugin
*create
) :
36 ref_(NULL
), handle_(NULL
), filename_(NULL
),
37 // We want the create_ member to be cb_create_plugin, to be able to call
38 // this->create_(). Hence the need for this hideous cast.
39 create_((cb_create_plugin
)(unsigned long)create
),
40 is_log2str_capable_(false)
44 LoggerPlugin::~LoggerPlugin()
46 Free(this->filename_
);
49 //void LoggerPlugin::load()
51 //void LoggerPlugin::unload()
53 void LoggerPlugin::reset()
58 void LoggerPlugin::open_file(bool is_first
)
60 this->ref_
->open_file(is_first
);
63 void LoggerPlugin::close_file()
65 this->ref_
->close_file();
68 void LoggerPlugin::set_file_name(const char *new_filename_skeleton
,
71 this->ref_
->set_file_name(new_filename_skeleton
, from_config
);
74 void LoggerPlugin::set_append_file(bool new_append_file
)
76 this->ref_
->set_append_file(new_append_file
);
79 bool LoggerPlugin::set_file_size(int p_size
)
81 return this->ref_
->set_file_size(p_size
);
84 bool LoggerPlugin::set_file_number(int p_number
)
86 return this->ref_
->set_file_number(p_number
);
89 bool LoggerPlugin::set_disk_full_action(TTCN_Logger::disk_full_action_t p_disk_full_action
)
91 return this->ref_
->set_disk_full_action(p_disk_full_action
);
94 void LoggerPlugin::set_parameter(const char* param_name
, const char* param_value
)
96 this->ref_
->set_parameter(param_name
, param_value
);
99 int LoggerPlugin::log(const TitanLoggerApi::TitanLogEvent
& event
,
100 bool log_buffered
, bool separate_file
, bool use_emergency_mask
)
102 if (!this->ref_
) return 1;
103 this->ref_
->log(event
, log_buffered
, separate_file
, use_emergency_mask
);
107 CHARSTRING
LoggerPlugin::log2str(const TitanLoggerApi::TitanLogEvent
& event
) const
110 if (!this->is_log2str_capable_
) return CHARSTRING();
111 return this->ref_
->log2str(event
);
114 const char *LoggerPlugin::plugin_name() const
117 return this->ref_
->plugin_name();
120 bool LoggerPlugin::is_configured() const
122 return this->ref_
!= NULL
&& this->ref_
->is_configured();
125 void LoggerPlugin::set_configured(bool configured
)
127 if (this->ref_
!= NULL
)
128 this->ref_
->set_configured(configured
);