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