File: LogConfig.h

package info (click to toggle)
trafficserver 9.2.5%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 53,008 kB
  • sloc: cpp: 345,484; ansic: 31,134; python: 24,200; sh: 7,271; makefile: 3,045; perl: 2,261; java: 277; pascal: 119; sql: 94; xml: 2
file content (232 lines) | stat: -rw-r--r-- 6,918 bytes parent folder | download | duplicates (2)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/** @file

  A brief file description

  @section license License

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */

#pragma once

#include <string_view>
#include <string>

#include "tscore/ink_platform.h"
#include "records/P_RecProcess.h"
#include "ProxyConfig.h"
#include "LogObject.h"
#include "RolledLogDeleter.h"
#include "tscpp/util/MemSpan.h"

/* Instead of enumerating the stats in DynamicStats.h, each module needs
   to enumerate its stats separately and register them with librecords
   */
enum {
  // Logging Events
  log_stat_event_log_error_ok_stat,
  log_stat_event_log_error_skip_stat,
  log_stat_event_log_error_aggr_stat,
  log_stat_event_log_error_full_stat,
  log_stat_event_log_error_fail_stat,

  log_stat_event_log_access_ok_stat,
  log_stat_event_log_access_skip_stat,
  log_stat_event_log_access_aggr_stat,
  log_stat_event_log_access_full_stat,
  log_stat_event_log_access_fail_stat,

  // Logging Data
  log_stat_num_sent_to_network_stat,
  log_stat_num_lost_before_sent_to_network_stat,
  log_stat_num_received_from_network_stat,
  log_stat_num_flush_to_disk_stat,
  log_stat_num_lost_before_flush_to_disk_stat,

  log_stat_bytes_lost_before_preproc_stat,
  log_stat_bytes_sent_to_network_stat,
  log_stat_bytes_lost_before_sent_to_network_stat,
  log_stat_bytes_received_from_network_stat,

  log_stat_bytes_flush_to_disk_stat,
  log_stat_bytes_lost_before_flush_to_disk_stat,
  log_stat_bytes_written_to_disk_stat,
  log_stat_bytes_lost_before_written_to_disk_stat,

  // Logging I/O
  log_stat_log_files_open_stat,
  log_stat_log_files_space_used_stat,

  log_stat_count
};

extern RecRawStatBlock *log_rsb;

struct dirent;

/*-------------------------------------------------------------------------
  this object keeps the state of the logging configuration variables.  upon
  construction, the log configuration file is read and the logging
  variables are initialized.

  the "global" logconfig object is kept as a static pointer in the log
  class, called "config", and changed whenever the configuration variables
  are changed in the config file, using log::change_configuration().

  to add a new config variable:
     1. add a line in records.config for the new config variable.
        the name in records.config should be "proxy.config.log.xxx".
     2. create a member variable to store the current value.
        the name of the member variable should be "xxx".
     3. if the member variable is a string, add a delete for it in the
        destructor, logconfig::~logconfig.
     4. initialize the member variable in logconfig::setup_default_values
     5. update the member variable from the records.config file
        in logconfig::read_configuration_variables() using a call to
        configreadinteger or configreadstring.
     6. add a line in the logconfig::register_config_callbacks() function
        for this new variable if it is exposed in the GUI
  -------------------------------------------------------------------------*/

class LogConfig : public ConfigInfo
{
public:
  LogConfig();
  ~LogConfig() override;

  void init(LogConfig *previous_config = nullptr);
  void display(FILE *fd = stdout);
  void setup_log_objects();

  static int reconfigure(const char *name, RecDataT data_type, RecData data, void *cookie);

  static void register_config_callbacks();
  static void register_stat_callbacks();
  static void register_mgmt_callbacks();

  bool space_to_write(int64_t bytes_to_write) const;

  bool
  space_is_short() const
  {
    return !space_to_write(max_space_mb_headroom * LOG_MEGABYTE);
  };

  void
  increment_space_used(int bytes)
  {
    m_space_used += bytes;
    m_partition_space_left -= bytes;
  }

  void update_space_used();
  void read_configuration_variables();

  // CVR This is the mgmt callback function, hence all the strange arguments
  static void reconfigure_mgmt_variables(ts::MemSpan<void>);

  int
  get_max_space_mb() const
  {
    return max_space_mb_for_logs;
  }

  void
  transfer_objects(LogConfig *old_config)
  {
    log_object_manager.transfer_objects(old_config->log_object_manager);
  }

  bool
  has_api_objects() const
  {
    return log_object_manager.has_api_objects();
  }

  /** Register rolled logs of logname for auto-deletion when there are space
   * constraints.
   *
   * @param[in] logname The name of the unrolled log to register, such as
   * "diags.log".
   *
   * @param[in] rolling_min_count The minimum amount of rolled logs of logname
   * to try to keep around. A value of 0 expresses a desire to keep all rolled
   * files, if possible.
   */
  void register_rolled_log_auto_delete(std::string_view logname, int rolling_min_count);

public:
  bool initialized             = false;
  bool reconfiguration_needed  = false;
  bool logging_space_exhausted = false;
  int64_t m_space_used         = 0;
  int64_t m_partition_space_left;
  bool roll_log_files_now; // signal that files must be rolled

  LogObjectManager log_object_manager;

  LogFilterList filter_list;
  LogFormatList format_list;

  int log_buffer_size;
  int max_secs_per_buffer;
  int max_space_mb_for_logs;
  int max_space_mb_headroom;
  int logfile_perm;

  int preproc_threads;

  Log::RollingEnabledValues rolling_enabled;
  int rolling_interval_sec;
  int rolling_offset_hr;
  int rolling_size_mb;
  int rolling_min_count;
  int rolling_max_count;
  bool rolling_allow_empty;
  bool auto_delete_rolled_files;

  int sampling_frequency;
  int file_stat_frequency;
  int space_used_frequency;

  int ascii_buffer_size;
  int max_line_size;
  int logbuffer_max_iobuf_index;

  char *hostname           = nullptr;
  char *logfile_dir        = nullptr;
  char *error_log_filename = nullptr;

private:
  bool evaluate_config();

  void setup_default_values();

private:
  bool m_disk_full                  = false;
  bool m_disk_low                   = false;
  bool m_partition_full             = false;
  bool m_partition_low              = false;
  bool m_log_directory_inaccessible = false;

  RolledLogDeleter rolledLogDeleter;

  // noncopyable
  // -- member functions not allowed --
  LogConfig(const LogConfig &) = delete;
  LogConfig &operator=(const LogConfig &) = delete;
};