API
 
Loading...
Searching...
No Matches
logFileRaw.hpp
Go to the documentation of this file.
1/** \file logFileRaw.hpp
2 * \brief Manage a raw log file.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup logger_files
6 *
7 * History:
8 * - 2017-08-28 created by JRM
9 */
10
11#ifndef logger_logFileRaw_hpp
12#define logger_logFileRaw_hpp
13
14
15#include <iostream>
16
17#include <string>
18
19
20#include <mx/ioutils/stringUtils.hpp>
21
22#include "../common/defaults.hpp"
23#include <flatlogs/flatlogs.hpp>
24
25namespace MagAOX
26{
27namespace logger
28{
29
30/// A class to manage raw binary log files
31/** Manages a binary file containing MagAO-X logs.
32 *
33 * The log entries are written as a binary stream of a configurable
34 * maximum size. If this size will be exceed by the next entry, then a new file is created.
35 *
36 * Filenames have a standard form of: [path]/[name]_YYYYMMDDHHMMSSNNNNNNNNN.[ext] where fields in [] are configurable.
37 *
38 * The timestamp is from the first entry of the file.
39 *
40 */
42{
43
44protected:
45
46 /** \name Configurable Parameters
47 *@{
48 */
49 std::string m_logPath {"."}; ///< The base path for the log files.
50 std::string m_logName {"xlog"}; ///< The base name for the log files.
51 std::string m_logExt {MAGAOX_default_logExt}; ///< The extension for the log files.
52
53 size_t m_maxLogSize {MAGAOX_default_max_logSize}; ///< The maximum file size in bytes. Default is 10 MB.
54 ///@}
55
56 /** \name Internal State
57 *@{
58 */
59
60 FILE * m_fout {0}; ///< The file pointer
61
62 size_t m_currFileSize {0}; ///< The current file size.
63
64 ///@}
65
66public:
67
68 /// Default constructor
69 /** Currently does nothing.
70 */
71 logFileRaw();
72
73 ///Destructor
74 /** Closes the file if open
75 */
77
78 /// Set the path.
79 /**
80 *
81 * \returns 0 on success
82 * \returns -1 on error
83 */
84 int logPath( const std::string & newPath /**< [in] the new value of _path */ );
85
86 /// Get the path.
87 /**
88 * \returns the current value of m_logPath.
89 */
90 std::string logPath();
91
92 /// Set the log name
93 /**
94 *
95 * \returns 0 on success
96 * \returns -1 on error
97 */
98 int logName( const std::string & newName /**< [in] the new value of m_logName */ );
99
100 /// Get the name
101 /**
102 * \returns the current value of _name.
103 */
104 std::string logName();
105
106 /// Set the log extension
107 /**
108 *
109 * \returns 0 on success
110 * \returns -1 on error
111 */
112 int logExt( const std::string & newExt /**< [in] the new value of m_logExt */ );
113
114 /// Get the log extension
115 /**
116 * \returns the current value of m_logExt.
117 */
118 std::string logExt();
119
120 /// Set the maximum file size
121 /**
122 *
123 * \returns 0 on success
124 * \returns -1 on error
125 */
126 int maxLogSize( size_t newMaxFileSize/**< [in] the new value of _maxLogSize */);
127
128 /// Get the maximum file size
129 /**
130 * \returns the current value of m_maxLogSize
131 */
132 size_t maxLogSize();
133
134 ///Write a log entry to the file
135 /** Checks if this write will exceed m_maxLogSize, and if so opens a new file.
136 * The new file will have the timestamp of this log entry.
137 *
138 * \returns 0 on success
139 * \returns -1 on error
140 */
141 int writeLog( flatlogs::bufferPtrT & data ///< [in] the log entry to write to disk
142 );
143
144 /// Flush the stream
145 /**
146 * \returns 0 on success
147 * \returns -1 on error
148 */
149 int flush();
150
151 ///Close the file pointer
152 /**
153 * \returns 0 on success
154 * \returns -1 on error
155 */
156 int close();
157
158protected:
159
160 ///Create a new file
161 /** Closes the current file if open. Then creates a new file with a name of the form
162 * [path]/[name]_YYYYMMDDHHMMSSNNNNNNNNN.[ext]
163 *
164 *
165 * \returns 0 on success
166 * \returns -1 on error
167 */
168 int createFile(flatlogs::timespecX & ts /**< [in] A MagAOX timespec, used to set the timestamp */);
169
170
171};
172
173
174
175} //namespace logger
176} //namespace MagAOX
177
178#endif //logger_logFileRaw_hpp
A class to manage raw binary log files.
std::string m_logName
The base name for the log files.
std::string logExt()
Get the log extension.
std::string m_logPath
The base path for the log files.
logFileRaw()
Default constructor.
int close()
Close the file pointer.
size_t m_maxLogSize
The maximum file size in bytes. Default is 10 MB.
std::string m_logExt
The extension for the log files.
int createFile(flatlogs::timespecX &ts)
Create a new file.
std::string logName()
Get the name.
int writeLog(flatlogs::bufferPtrT &data)
Write a log entry to the file.
size_t maxLogSize()
Get the maximum file size.
int flush()
Flush the stream.
FILE * m_fout
The file pointer.
std::string logPath()
Get the path.
size_t m_currFileSize
The current file size.
Flatlogs single include file.
#define MAGAOX_default_logExt
The extension for MagAO-X binary log files.
Definition defaults.hpp:22
#define MAGAOX_default_max_logSize
The default maximum log file size.
Definition defaults.hpp:40
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition logHeader.hpp:58
Definition dm.hpp:24
A fixed-width timespec structure.
Definition timespecX.hpp:35