MySQL 8.0.32
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, 2022, 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 also distributed 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 included with MySQL.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License, version 2.0, for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25
26/// @file
27///
28/// This file declares the Log file class.
29
30#include "my_io.h"
31#include "my_sys.h"
32
33class Logfile {
34 public:
35 Logfile();
36 Logfile(const Logfile &) = default;
37
38 virtual ~Logfile() { close(); }
39
40 /// Return file name.
41 ///
42 /// @retval Name of the file.
43 const char *file_name() const { return m_filename; }
44
45 /// Return number bytes written into a log file.
46 ///
47 /// @retval Number bytes written into a log file.
48 std::size_t bytes_written() const { return m_bytes_written; }
49
50 /// Flush any unwritten content from the stream's buffer to the
51 /// associated file.
52 ///
53 /// @retval False if successful, true otherwise.
54 bool flush();
55
56 /// Construct a file path using directory name, file name and extension
57 /// arguments and open it in write/update mode.
58 ///
59 /// @param dirname Directory name
60 /// @param filename File name
61 /// @param ext Extension name
62 ///
63 /// @retval False if successful, true otherwise.
64 bool open(const char *dirname, const char *filename, const char *ext);
65
66 /// Write the contents in data array to a file.
67 ///
68 /// @param data Pointer to the array to be written
69 /// @param length Length of the buffer
70 ///
71 /// @retval False if successful, true otherwise.
72 bool write(const char *data, std::size_t length);
73
74 /// Print the last N number of lines from a file to stderr.
75 ///
76 /// @param lines Number of lines
77 void show_tail(unsigned int lines);
78
79 private:
80 /// Close the given file stream.
81 void close();
82
85 std::size_t m_bytes_written;
86};
87
88#endif // LOGFILE_INCLUDED
Definition: logfile.h:33
bool flush()
Flush any unwritten content from the stream's buffer to the associated file.
Definition: logfile.cc:33
void close()
Close the given file stream.
Definition: logfile.cc:77
bool write(const char *data, std::size_t length)
Write the contents in data array to a file.
Definition: logfile.cc:64
FILE * m_file
Definition: logfile.h:84
std::size_t bytes_written() const
Return number bytes written into a log file.
Definition: logfile.h:48
std::size_t m_bytes_written
Definition: logfile.h:85
char m_filename[FN_REFLEN]
Definition: logfile.h:83
void show_tail(unsigned int lines)
Print the last N number of lines from a file to stderr.
Definition: logfile.cc:87
virtual ~Logfile()
Definition: logfile.h:38
const char * file_name() const
Return file name.
Definition: logfile.h:43
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:44
Logfile()
Definition: logfile.cc:29
Logfile(const Logfile &)=default
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:82
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:75
Json_data_extension ext
Definition: backend.cc:50
std::string dirname(const std::string &path)
Definition: utilities.cc:37
const char * filename
Definition: pfs_example_component_population.cc:66