Merge pull request #63 from BenceJanosSzabo/master
[deliverable/titan.core.git] / core / LegacyLogger.hh
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 * Pandi, Krisztian
13 *
14 ******************************************************************************/
15 #ifndef LegacyLogger_HH
16 #define LegacyLogger_HH
17
18 #include "Logger.hh"
19 #include "ILoggerPlugin.hh"
20 #include "Charstring.hh"
21
22 namespace TitanLoggerApi
23 {
24 class TitanLogEvent;
25 }
26
27 struct component_id_t;
28 struct logfile_data_struct;
29
30 /// This class is responsible for configuration file parameters: ConsoleMask
31 /// and FileMask as well.
32 class LegacyLogger: public ILoggerPlugin
33 {
34 public:
35 LegacyLogger();
36 virtual ~LegacyLogger();
37 inline bool is_static() { return true; }
38 inline bool is_log2str_capable() { return true; }
39 CHARSTRING log2str(const TitanLoggerApi::TitanLogEvent& event);
40 void init(const char *options = 0);
41 void fini();
42 void reset();
43 void fatal_error(const char *err_msg, ...);
44
45 void log(const TitanLoggerApi::TitanLogEvent& event, bool log_buffered,
46 bool separate_file, bool use_emergency_mask);
47 static char * plugin_specific_settings();
48
49 protected:
50 explicit LegacyLogger(const LegacyLogger&);
51 LegacyLogger& operator=(const LegacyLogger&);
52
53 char *get_file_name(size_t idx);
54 void set_file_name(const char *new_filename_skeleton, boolean from_config);
55 bool set_file_size(int p_size);
56 void set_append_file(bool new_append_file);
57 bool set_file_number(int p_number);
58 bool set_disk_full_action(TTCN_Logger::disk_full_action_t p_disk_full_action);
59 void open_file(bool is_first = true);
60 void close_file();
61 bool log_file(const TitanLoggerApi::TitanLogEvent& event, bool log_buffered);
62 bool log_file_emerg(const TitanLoggerApi::TitanLogEvent& event);
63 bool log_console(const TitanLoggerApi::TitanLogEvent& event,
64 const TTCN_Logger::Severity& severity);
65 bool log_to_file(const char *event_str);
66 void create_parent_directories(const char *path_name);
67 /// Checks for invalid combinations of LogFileSize, LogFileNumber and
68 /// DiskFullAction.
69 void chk_logfile_data();
70 protected:
71 FILE *log_fp_;
72 FILE *er_;
73 size_t logfile_bytes_;
74 size_t logfile_size_;
75 size_t logfile_number_;
76 size_t logfile_index_;
77 /** @brief "Format string" for the log file name.
78 * The following format specifiers will be interpreted:
79 * \li \%c -> name of the current testcase (only on PTCs)
80 * \li \%e -> name of executable
81 * \li \%h -> hostname
82 * \li \%l -> login name
83 * \li \%n -> component name (only on PTCs, optional)
84 * \li \%p -> process id
85 * \li \%r -> component reference
86 * \li \%s -> default suffix (currently: always "log")
87 * \li \%t -> component type (only on PTCs)
88 * \li \%i -> log file index
89 * \li \%\% -> \%
90 **/
91 char *filename_skeleton_;
92 TTCN_Logger::disk_full_action_t disk_full_action_;
93 struct timeval disk_full_time_;
94
95 /// True if `filename_skeleton_' was set from the configuration file.
96 bool skeleton_given_;
97 /// True to open the log file and append to it, false to truncate.
98 bool append_file_;
99 bool is_disk_full_;
100 bool format_c_present_;
101 bool format_t_present_;
102 char *current_filename_;
103 static LegacyLogger *myself;
104 };
105
106 #endif // LegacyLogger_HH
This page took 0.032919 seconds and 5 git commands to generate.