#include <FileLogger.h>
Inheritance diagram for ASSA::FileLogger:
Public Member Functions | |
FileLogger () | |
virtual int | log_open (const char *logfname_, u_long groups_, u_long maxsize_=10485760) |
Open File Logger. | |
virtual int | log_close (void) |
virtual void | log_resync (void) |
virtual int | log_msg (Group g_, size_t indent_level_, const string &func_name_, size_t expected_sz_, const char *fmt_, va_list) |
If output string is longer then LOGGER_MAXLINE-1, it is truncated to that size. | |
virtual int | log_func (Group g_, size_t indent_level_, const string &func_name_, marker_t type_) |
int | log_raw_msg (const string &msg_) |
Log message as it is (raw) without indentation or timestamping, but still perform byte counting and the logic associated with it. | |
void | dump (void) |
Private Types | |
enum | state_t { opened, closed } |
Private Member Functions | |
FileLogger (const FileLogger &) | |
FileLogger & | operator= (const FileLogger &) |
int | handle_rollover () |
Private Attributes | |
std::ofstream | m_sink |
u_long | m_maxsize |
state_t | m_state |
u_long | m_bytecount |
Definition at line 30 of file FileLogger.h.
|
Definition at line 60 of file FileLogger.h.
|
|
Definition at line 75 of file FileLogger.h. 00076 : m_maxsize (1048576), 00077 m_state (closed), 00078 m_bytecount (0) 00079 { 00080 /*--- empty ---*/ 00081 }
|
|
|
|
Definition at line 235 of file FileLogger.cpp. References ASSA::endl(), m_bytecount, ASSA::Logger_Impl::m_groups, ASSA::Logger_Impl::m_indent_step, ASSA::Logger_Impl::m_logfname, m_maxsize, m_sink, m_state, ASSA::Logger_Impl::m_tmflg, and opened. 00236 { 00237 #ifdef BUG_HUNTING 00238 if (m_state == opened) { 00239 m_sink << "m_logfname = \"" << m_logfname << "\"\n" 00240 << "m_groups = 0x"; 00241 char oldfill = m_sink.fill ('0'); 00242 m_sink << std::setw(8) << std::hex << m_groups << '\n' << std::dec; 00243 m_sink.fill (oldfill); 00244 m_sink << "m_indent_step = " << m_indent_step << '\n' 00245 << "m_tmflg = " << m_tmflg << '\n' 00246 << "m_maxsize = " << m_maxsize << '\n' 00247 << "m_state = opened\n" 00248 << "m_bytecount = " << m_bytecount << std::endl; 00249 } 00250 #endif 00251 }
|
|
Definition at line 199 of file FileLogger.cpp. References Assure_exit, closed, ASSA::endl(), m_bytecount, ASSA::Logger_Impl::m_logfname, m_maxsize, m_sink, m_state, and opened. Referenced by log_func(), log_msg(), and log_raw_msg(). 00200 { 00201 if (m_bytecount >= m_maxsize) { 00202 struct stat fst; 00203 if (::stat (m_logfname.c_str(), &fst) == 0) { 00204 if (S_ISREG (fst.st_mode)) { 00205 m_sink << "\nReached maximum allowable size\n" 00206 << "m_bytecount = " << m_bytecount 00207 << ", m_maxsize = " << m_maxsize << std::endl; 00208 m_sink.close (); 00209 m_state = closed; 00210 m_bytecount = 0; 00211 00212 string newname = m_logfname + ".0"; 00213 unlink (newname.c_str ()); 00214 rename (m_logfname.c_str (), newname.c_str ()); 00215 m_sink.open (m_logfname.c_str (), 00216 std::ios::app | std::ios::out); 00217 if (!m_sink) { 00218 return -1; 00219 } 00220 m_state = opened; 00221 } 00222 else if (S_ISCHR (fst.st_mode)) { // It is /dev/null 00223 m_bytecount = 0; 00224 } 00225 else { 00226 Assure_exit (1); 00227 } 00228 } 00229 } 00230 return 0; 00231 }
|
|
Implements ASSA::Logger_Impl. Definition at line 70 of file FileLogger.cpp. References closed, ASSA::flush(), m_bytecount, ASSA::Logger_Impl::m_groups, ASSA::Logger_Impl::m_logfname, m_maxsize, m_sink, and m_state. 00071 { 00072 if (m_state != closed) { 00073 m_sink << std::flush; 00074 m_sink.close (); 00075 m_state = closed; 00076 00077 if (m_groups == 0) { 00078 ::unlink (m_logfname.c_str ()); 00079 } 00080 m_logfname.empty (); 00081 m_maxsize = 0; 00082 m_bytecount = 0; 00083 } 00084 return 0; 00085 }
|
|
Implements ASSA::Logger_Impl. Definition at line 162 of file FileLogger.cpp. References ASSA::Logger_Impl::add_timestamp(), closed, ASSA::flush(), ASSA::FUNC_ENTRY, ASSA::Logger_Impl::group_enabled(), handle_rollover(), ASSA::Logger_Impl::indent_func_name(), m_bytecount, m_sink, and m_state. 00164 { 00165 if (m_state == closed) { 00166 errno = EPERM; 00167 return -1; 00168 } 00169 00170 if (! group_enabled (g_)) { 00171 return 0; 00172 } 00173 00174 m_bytecount += add_timestamp (m_sink); 00175 m_bytecount += indent_func_name (m_sink, func_name_, indent_level_, type_); 00176 m_sink << ((type_ == FUNC_ENTRY) ? "---v---\n" : "---^---\n") << std::flush; 00177 m_bytecount += ::strlen ("---v---\n"); 00178 00179 return handle_rollover (); 00180 }
|
|
If output string is longer then LOGGER_MAXLINE-1, it is truncated to that size. From printf(3) manpage: "Upon successful return, these functions return the number of characters printed (not including the trailing '\0' used to end output to strings). If the output was truncated due to this limit then the return value is the number of characters (not including the trailing '\0') which would have been written to the final string if enough space had been available. Thus, a return value of size or more means that the output was truncated. If an output error is encountered, a negative value is returned." In other words, if you have attempted to write more then buffer can hold, the output is truncated by buffer size - 1, and the return value would be the number of bytes you have tried to write to the buffer. If buffer size is 256, and you tried to write 340 bytes to it, the first 255 bytes are written to the buffer, and 340 is returns as the return value. Implements ASSA::Logger_Impl. Definition at line 117 of file FileLogger.cpp. References ASSA::Logger_Impl::add_timestamp(), closed, ASSA::flush(), ASSA::Logger_Impl::format_msg(), ASSA::FUNC_MSG, ASSA::Logger_Impl::group_enabled(), handle_rollover(), ASSA::Logger_Impl::indent_func_name(), m_bytecount, m_sink, and m_state. 00123 { 00124 // std::cout << "FileLogger::log_msg() enter\n" 00125 // << "group__=0x" << std::setw(8) << std::hex << (u_long)g_ << "\n"; 00126 00127 if (m_state == closed) { 00128 // std::cout << "FileLogger::log_msg() sink closed!\n"; 00129 errno = EPERM; 00130 return -1; 00131 } 00132 00133 if (! group_enabled (g_)) { 00134 // std::cout << "FileLogger::log_msg() group is not enabled!\n" 00135 // << "m_groups=0x" 00136 // << std::setw(8) << std::hex << m_groups << "\n"; 00137 return 0; 00138 } 00139 00140 m_bytecount += add_timestamp (m_sink); 00141 m_bytecount += indent_func_name (m_sink, func_name_,indent_level_,FUNC_MSG); 00142 00143 bool release = false; 00144 char* msgbuf_ptr = format_msg (expected_sz_, fmt_, msg_list_, release); 00145 if (msgbuf_ptr == NULL) { 00146 // std::cout << "FileLogger::log_msg() call to format_msg() failed!" 00147 // << " fmt_= \"" << fmt_ << "\"\n" << std::flush; 00148 return -1; // failed to format 00149 } 00150 m_sink << msgbuf_ptr << std::flush; 00151 m_bytecount += strlen (msgbuf_ptr); 00152 00153 if (release) { 00154 delete [] msgbuf_ptr; 00155 } 00156 00157 return handle_rollover (); 00158 }
|
|
Open File Logger.
Reimplemented from ASSA::Logger_Impl. Definition at line 33 of file FileLogger.cpp. References ASSA::Logger_Impl::m_groups, ASSA::Logger_Impl::m_logfname, m_maxsize, m_sink, m_state, and opened. 00034 { 00035 // std::cout << "Enter: FileLogger::log_open(fname=\"" 00036 // << logfname_ << "\"" 00037 // << " groups=0x" << std::setw(8) << std::hex << groups_ 00038 // << " maxsize=" << std::dec << maxsize_ << ")\n"; 00039 00040 if (logfname_ == NULL || maxsize_ <= 0) { 00041 // std::cout << "FileLogger::log_open() failed 1\n"; 00042 errno = EINVAL; 00043 return -1; 00044 } 00045 00046 if (m_state == opened) { 00047 // std::cout << "FileLogger::log_open() already open\n"; 00048 errno = EEXIST; 00049 return -1; 00050 } 00051 00052 m_logfname = logfname_; 00053 m_groups = groups_; 00054 m_maxsize = maxsize_; 00055 00056 m_sink.open (m_logfname.c_str (), std::ios::out | std::ios::app); 00057 00058 if (!m_sink) { 00059 // std::cout << "FileLogger::log_open() failed to open()!\n"; 00060 return -1; 00061 } 00062 // std::cout << "Success on FileLogger::log_open()\n"; 00063 00064 m_state = opened; 00065 return 0; 00066 }
|
|
Log message as it is (raw) without indentation or timestamping, but still perform byte counting and the logic associated with it.
Definition at line 184 of file FileLogger.cpp. References closed, ASSA::flush(), handle_rollover(), m_bytecount, m_sink, and m_state. 00185 { 00186 if (m_state == closed) { 00187 errno = EPERM; 00188 return -1; 00189 } 00190 00191 m_sink << msg_ << std::flush; 00192 m_bytecount += msg_.length (); 00193 00194 return handle_rollover (); 00195 }
|
|
Reimplemented from ASSA::Logger_Impl. Definition at line 85 of file FileLogger.h. References ASSA::flush(), and m_sink. 00086 { 00087 m_sink << std::flush; 00088 }
|
|
|
|
Definition at line 71 of file FileLogger.h. Referenced by dump(), handle_rollover(), log_close(), log_func(), log_msg(), and log_raw_msg(). |
|
Definition at line 69 of file FileLogger.h. Referenced by dump(), handle_rollover(), log_close(), and log_open(). |
|
Definition at line 68 of file FileLogger.h. Referenced by dump(), handle_rollover(), log_close(), log_func(), log_msg(), log_open(), log_raw_msg(), and log_resync(). |
|
Definition at line 70 of file FileLogger.h. Referenced by dump(), handle_rollover(), log_close(), log_func(), log_msg(), log_open(), and log_raw_msg(). |