Sync with 5.3.0
[deliverable/titan.core.git] / core / LoggerPlugin.cc
CommitLineData
970ed795
EL
1///////////////////////////////////////////////////////////////////////////////
2// Copyright (c) 2000-2014 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"
9
10#include "../common/memory.h"
11
12#include "TitanLoggerApi.hh"
13#include "Error.hh"
14#include "Logger.hh"
15#include "ILoggerPlugin.hh"
16
17#include <assert.h>
18
19// constructor for dynamic plug-in
20LoggerPlugin::LoggerPlugin(const char *path) :
21 ref_(NULL), handle_(NULL), filename_(NULL), create_(NULL),
22 is_log2str_capable_(false)
23{
24 assert(path != NULL);
25 this->filename_ = mcopystr(path);
26}
27
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.
35LoggerPlugin::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)
41{
42}
43
44LoggerPlugin::~LoggerPlugin()
45{
46 Free(this->filename_);
47}
48
49//void LoggerPlugin::load()
50
51//void LoggerPlugin::unload()
52
53void LoggerPlugin::reset()
54{
55 this->ref_->reset();
56}
57
58void LoggerPlugin::open_file(bool is_first)
59{
60 this->ref_->open_file(is_first);
61}
62
63void LoggerPlugin::close_file()
64{
65 this->ref_->close_file();
66}
67
68void LoggerPlugin::set_file_name(const char *new_filename_skeleton,
69 bool from_config)
70{
71 this->ref_->set_file_name(new_filename_skeleton, from_config);
72}
73
74void LoggerPlugin::set_append_file(bool new_append_file)
75{
76 this->ref_->set_append_file(new_append_file);
77}
78
79bool LoggerPlugin::set_file_size(int p_size)
80{
81 return this->ref_->set_file_size(p_size);
82}
83
84bool LoggerPlugin::set_file_number(int p_number)
85{
86 return this->ref_->set_file_number(p_number);
87}
88
89bool LoggerPlugin::set_disk_full_action(TTCN_Logger::disk_full_action_t p_disk_full_action)
90{
91 return this->ref_->set_disk_full_action(p_disk_full_action);
92}
93
94void LoggerPlugin::set_parameter(const char* param_name, const char* param_value)
95{
96 this->ref_->set_parameter(param_name, param_value);
97}
98
99int LoggerPlugin::log(const TitanLoggerApi::TitanLogEvent& event,
100 bool log_buffered, bool separate_file, bool use_emergency_mask)
101{
102 if (!this->ref_) return 1;
103 this->ref_->log(event, log_buffered, separate_file, use_emergency_mask);
104 return 0;
105}
106
107CHARSTRING LoggerPlugin::log2str(const TitanLoggerApi::TitanLogEvent& event) const
108{
109 assert(this->ref_);
110 if (!this->is_log2str_capable_) return CHARSTRING();
111 return this->ref_->log2str(event);
112}
113
114const char *LoggerPlugin::plugin_name() const
115{
116 assert(this->ref_);
117 return this->ref_->plugin_name();
118}
119
120bool LoggerPlugin::is_configured() const
121{
122 return this->ref_ != NULL && this->ref_->is_configured();
123}
124
125void LoggerPlugin::set_configured(bool configured)
126{
127 if (this->ref_ != NULL)
128 this->ref_->set_configured(configured);
129}
This page took 0.028356 seconds and 5 git commands to generate.