File: LegacyLogger.hh

package info (click to toggle)
eclipse-titan 8.2.0-1
  • links: PTS
  • area: main
  • in suites: bookworm, sid
  • size: 103,544 kB
  • sloc: cpp: 271,008; ansic: 33,683; yacc: 23,419; makefile: 15,483; lex: 9,204; java: 4,848; perl: 4,555; sh: 2,242; xml: 1,378; javascript: 85; awk: 48; php: 32; python: 13
file content (106 lines) | stat: -rw-r--r-- 3,634 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/******************************************************************************
 * Copyright (c) 2000-2021 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 *
 * Contributors:
 *   Balasko, Jeno
 *   Kovacs, Ferenc
 *   Raduly, Csaba
 *   Pandi, Krisztian
 *
 ******************************************************************************/
#ifndef LegacyLogger_HH
#define LegacyLogger_HH

#include "Logger.hh"
#include "ILoggerPlugin.hh"
#include "Charstring.hh"

namespace TitanLoggerApi
{
  class TitanLogEvent;
}

struct component_id_t;
struct logfile_data_struct;

/// This class is responsible for configuration file parameters: ConsoleMask
/// and FileMask as well.
class LegacyLogger: public ILoggerPlugin
{
public:
  LegacyLogger();
  virtual ~LegacyLogger();
  inline boolean is_static() { return TRUE; }
  inline boolean is_log2str_capable() { return TRUE; }
  CHARSTRING log2str(const TitanLoggerApi::TitanLogEvent& event);
  void init(const char *options = 0);
  void fini();
  void reset();
  void fatal_error(const char *err_msg, ...);

  void log(const TitanLoggerApi::TitanLogEvent& event, boolean log_buffered,
      boolean separate_file, boolean use_emergency_mask);
  static char * plugin_specific_settings();

protected:
  explicit LegacyLogger(const LegacyLogger&);
  LegacyLogger& operator=(const LegacyLogger&);

  char *get_file_name(size_t idx);
  void set_file_name(const char *new_filename_skeleton, boolean from_config);
  boolean set_file_size(int p_size);
  void set_append_file(boolean new_append_file);
  boolean set_file_number(int p_number);
  boolean set_disk_full_action(TTCN_Logger::disk_full_action_t p_disk_full_action);
  void open_file(boolean is_first = TRUE);
  void close_file();
  boolean log_file(const TitanLoggerApi::TitanLogEvent& event, boolean log_buffered);
  boolean log_file_emerg(const TitanLoggerApi::TitanLogEvent& event);
  boolean log_console(const TitanLoggerApi::TitanLogEvent& event,
                   const TTCN_Logger::Severity& severity);
  boolean log_to_file(const char *event_str);
  void create_parent_directories(const char *path_name);
  /// Checks for invalid combinations of LogFileSize, LogFileNumber and
  /// DiskFullAction.
  void chk_logfile_data();
protected:
  FILE *log_fp_;
  FILE *er_;
  size_t logfile_bytes_;
  size_t logfile_size_;
  size_t logfile_number_;
  size_t logfile_index_;
  /** @brief "Format string" for the log file name.
   *  The following format specifiers will be interpreted:
   *  \li \%c -> name of the current testcase (only on PTCs)
   *  \li \%e -> name of executable
   *  \li \%h -> hostname
   *  \li \%l -> login name
   *  \li \%n -> component name (only on PTCs, optional)
   *  \li \%p -> process id
   *  \li \%r -> component reference
   *  \li \%s -> default suffix (currently: always "log")
   *  \li \%t -> component type (only on PTCs)
   *  \li \%i -> log file index
   *  \li \%\% -> \%
   **/
  char *filename_skeleton_;
  TTCN_Logger::disk_full_action_t disk_full_action_;
  struct timeval disk_full_time_;

  /// True if `filename_skeleton_' was set from the configuration file.
  boolean skeleton_given_;
  /// True to open the log file and append to it, false to truncate.
  boolean append_file_;
  boolean is_disk_full_;
  boolean format_c_present_;
  boolean format_t_present_;
  char *current_filename_;
  static LegacyLogger *myself;
};

#endif  // LegacyLogger_HH