3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
33
#include "LogFormatType.h"
34
#include "LogBufferSink.h"
38
struct LogBufferHeader;
41
#define LOGFILE_ROLLED_EXTENSION ".old"
42
#define LOGFILE_SEPARATOR_STRING "_"
44
/*-------------------------------------------------------------------------
47
Meta information for LogFile
49
-------------------------------------------------------------------------*/
56
DATA_FROM_METAFILE = 1, // metadata was read (or attempted to)
58
VALID_CREATION_TIME = 2, // creation time is valid
59
VALID_SIGNATURE = 4, // signature is valid
60
PRE_PANDA_METAFILE = 8, // metafile has pre-Panda format
61
// (i.e., creation time only)
62
FILE_OPEN_SUCCESSFUL = 16 // metafile was opened successfully
67
BUF_SIZE = 640 // size of read/write buffer
71
char *_filename; // the name of the meta file
72
time_t _creation_time; // file creation time
73
uint64_t _log_object_signature; // log object signature
74
int _flags; // metainfo status flags
75
char _buffer[BUF_SIZE]; // read/write buffer
77
void _read_from_file();
78
void _write_to_file();
79
void _build_name(const char *filename);
82
MetaInfo(char *filename):_flags(0)
84
_build_name(filename);
88
MetaInfo(char *filename, time_t creation, uint64_t signature):_creation_time(creation),
89
_log_object_signature(signature), _flags(VALID_CREATION_TIME | VALID_SIGNATURE)
92
_build_name(filename);
100
bool get_creation_time(time_t * time)
102
if (_flags & VALID_CREATION_TIME) {
103
*time = _creation_time;
109
bool get_log_object_signature(uint64_t * signature)
111
if (_flags & VALID_SIGNATURE) {
112
*signature = _log_object_signature;
118
bool data_from_metafile()
120
return (_flags & DATA_FROM_METAFILE ? true : false);
122
bool pre_panda_metafile()
124
return (_flags & PRE_PANDA_METAFILE ? true : false);
126
bool file_open_successful()
128
return (_flags & FILE_OPEN_SUCCESSFUL ? true : false);
132
/*-------------------------------------------------------------------------
134
-------------------------------------------------------------------------*/
136
class LogFile:public LogBufferSink
139
LogFile(const LogFile &);
141
LogFile(const char *name, const char *header, LogFileFormat format, uint64_t signature,
143
size_t ascii_buffer_size = 4 * 9216, size_t max_line_size = 9216,
145
size_t ascii_buffer_size = 1024, size_t max_line_size = 1024);
147
size_t overspill_report_count = 1000);
152
LOG_FILE_NO_ERROR = 0,
153
LOG_FILE_NO_PIPE_READERS,
154
LOG_FILE_COULD_NOT_CREATE_PIPE,
155
LOG_FILE_PIPE_MODE_NOT_SUPPORTED,
156
LOG_FILE_COULD_NOT_OPEN_FILE,
157
LOG_FILE_FILESYSTEM_CHECKS_FAILED
160
int write(LogBuffer * lb, size_t * to_disk = 0, size_t * to_net = 0, size_t * to_pipe = 0);
161
int roll(long interval_start, long interval_end);
166
void change_header(const char *header);
167
void change_name(char *new_name);
168
LogFileFormat get_format()
170
return m_file_format;
172
const char *get_format_name()
174
return (m_file_format == BINARY_LOG ? "binary" : (m_file_format == ASCII_PIPE ? "ascii_pipe" : "ascii"));
176
static int write_ascii_logbuffer(LogBufferHeader * buffer_header, int fd, const char *path, char *alt_format = NULL);
177
int write_ascii_logbuffer3(LogBufferHeader * buffer_header, char *alt_format = NULL);
178
static bool rolled_logfile(char *file);
179
static bool exists(const char *pathname);
181
void display(FILE * fd = stdout);
183
bool size_limit_exceeded()
185
if (!m_filesystem_checks_done) {
186
do_filesystem_checks();
188
return (m_has_size_limit ? (uint64_t) m_size_bytes > m_size_limit_bytes : false);
190
int do_filesystem_checks();
191
off_t get_size_bytes()const
205
static int writeln(char *data, int len, int fd, const char *path);
206
void read_metadata();
209
LogFileFormat m_file_format;
212
uint64_t m_signature; // signature of log object stored
213
MetaInfo *m_meta_info;
215
char *m_ascii_buffer; // buffer for ascii output
216
size_t m_ascii_buffer_size; // size of ascii buffer
217
size_t m_max_line_size; // size of longest log line (record)
218
// (including newline)
219
char *m_overspill_buffer; // buffer for data that did not fit
221
size_t m_overspill_bytes; // bytes in the overspill buffer
222
size_t m_overspill_written; // bytes in overspill that have been
223
// transferred to pipe buffer
224
size_t m_attempts_to_write_overspill; // times transfer from overspill to
225
// pipe buffer has been attempted
226
size_t m_overspill_report_count; // number of attempts at which
227
// overspill report is written to
233
uint64_t m_bytes_written;
234
off_t m_size_bytes; // current size of file in bytes
235
bool m_has_size_limit; // true if file has a size limit
236
uint64_t m_size_limit_bytes; // maximum file size in bytes
237
bool m_filesystem_checks_done; // file system checks have been done
243
// -- member functions not allowed --
245
LogFile & operator=(const LogFile &);
248
/***************************************************************************
249
LogFileList IS NOT USED
250
****************************************************************************/