MySQL 8.0.40
Source Code Documentation
logfile.h
Go to the documentation of this file.
1#ifndef LOGFILE_INCLUDED
2#define LOGFILE_INCLUDED
3
4// Copyright (c) 2018, 2024, Oracle and/or its affiliates.
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License, version 2.0,
8// as published by the Free Software Foundation.
9//
10// This program is designed to work with certain software (including
11// but not limited to OpenSSL) that is licensed under separate terms,
12// as designated in a particular file or component or in included license
13// documentation. The authors of MySQL hereby grant you an additional
14// permission to link the program and your derivative works with the
15// separately licensed software that they have either included with
16// the program or referenced in the documentation.
17//
18// This program is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License, version 2.0, for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with this program; if not, write to the Free Software
25// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26
27/// @file
28///
29/// This file declares the Log file class.
30
31#include "my_io.h"
32#include "my_sys.h"
33
34class Logfile {
35 public:
36 Logfile();
37 Logfile(const Logfile &) = default;
38
39 virtual ~Logfile() { close(); }
40
41 /// Return file name.
42 ///
43 /// @retval Name of the file.
44 const char *file_name() const { return m_filename; }
45
46 /// Return number bytes written into a log file.
47 ///
48 /// @retval Number bytes written into a log file.
49 std::size_t bytes_written() const { return m_bytes_written; }
50
51 /// Flush any unwritten content from the stream's buffer to the
52 /// associated file.
53 ///
54 /// @retval False if successful, true otherwise.
55 bool flush();
56
57 /// Construct a file path using directory name, file name and extension
58 /// arguments and open it in write/update mode.
59 ///
60 /// @param dirname Directory name
61 /// @param filename File name
62 /// @param ext Extension name
63 ///
64 /// @retval False if successful, true otherwise.
65 bool open(const char *dirname, const char *filename, const char *ext);
66
67 /// Write the contents in data array to a file.
68 ///
69 /// @param data Pointer to the array to be written
70 /// @param length Length of the buffer
71 ///
72 /// @retval False if successful, true otherwise.
73 bool write(const char *data, std::size_t length);
74
75 /// Print the last N number of lines from a file to stderr.
76 ///
77 /// @param lines Number of lines
78 void show_tail(unsigned int lines);
79
80 private:
81 /// Close the given file stream.
82 void close();
83
86 std::size_t m_bytes_written;
87};
88
89#endif // LOGFILE_INCLUDED
Definition: logfile.h:34
bool flush()
Flush any unwritten content from the stream's buffer to the associated file.
Definition: logfile.cc:34
void close()
Close the given file stream.
Definition: logfile.cc:78
bool write(const char *data, std::size_t length)
Write the contents in data array to a file.
Definition: logfile.cc:65
FILE * m_file
Definition: logfile.h:85
std::size_t bytes_written() const
Return number bytes written into a log file.
Definition: logfile.h:49
std::size_t m_bytes_written
Definition: logfile.h:86
char m_filename[FN_REFLEN]
Definition: logfile.h:84
void show_tail(unsigned int lines)
Print the last N number of lines from a file to stderr.
Definition: logfile.cc:88
virtual ~Logfile()
Definition: logfile.h:39
const char * file_name() const
Return file name.
Definition: logfile.h:44
bool open(const char *dirname, const char *filename, const char *ext)
Construct a file path using directory name, file name and extension arguments and open it in write/up...
Definition: logfile.cc:45
Logfile()
Definition: logfile.cc:30
Logfile(const Logfile &)=default
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:83
Common header for many mysys elements.
const std::string FILE("FILE")
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Json_data_extension ext
Definition: backend.cc:51
std::string dirname(const std::string &path)
Definition: utilities.cc:38
const char * filename
Definition: pfs_example_component_population.cc:67