libassa
3.5.0
|
00001 // -*- c++ -*- 00002 //------------------------------------------------------------------------------ 00003 // $Id: FileLogger.h,v 1.4 2005/10/08 02:42:00 vlg Exp $ 00004 //------------------------------------------------------------------------------ 00005 // FileLogger.h 00006 //------------------------------------------------------------------------------ 00007 // Copyright (C) 1997-2002 Vladislav Grinchenko 00008 // 00009 // This library is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU Library General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2 of the License, or (at your option) any later version. 00013 //------------------------------------------------------------------------------ 00014 #ifndef FILE_LOGGER_H 00015 #define FILE_LOGGER_H 00016 00017 #include <fstream> 00018 #include <string> 00019 #include <iostream> 00020 00021 #include "assa/Logger_Impl.h" 00022 00023 namespace ASSA { 00024 00030 class FileLogger : public Logger_Impl 00031 { 00032 public: 00033 FileLogger (); 00034 00035 virtual int log_open (const char* logfname_, 00036 u_long groups_, 00037 u_long maxsize_ = 10485760); // 10 Mb = 1024x1024x10 00038 00039 virtual int log_close (void); 00040 virtual void log_resync (void); 00041 00042 virtual int log_msg (Group g_, 00043 size_t indent_level_, 00044 const string& func_name_, 00045 size_t expected_sz_, 00046 const char* fmt_, va_list); 00047 virtual int log_func (Group g_, 00048 size_t indent_level_, 00049 const string& func_name_, 00050 marker_t type_); 00051 00056 int log_raw_msg (const string& msg_); 00057 void dump (void); 00058 00059 private: 00060 enum state_t { opened, closed }; 00061 00062 FileLogger (const FileLogger&); // copy constructor 00063 FileLogger& operator= (const FileLogger&); // copy assignment 00064 00065 int handle_rollover (); 00066 00067 private: 00068 std::ofstream m_sink; 00069 u_long m_maxsize; 00070 state_t m_state; 00071 u_long m_bytecount; 00072 }; 00073 00074 inline FileLogger:: 00075 FileLogger () 00076 : m_maxsize (1048576), 00077 m_state (closed), 00078 m_bytecount (0) 00079 { 00080 /*--- empty ---*/ 00081 } 00082 00083 inline void 00084 FileLogger:: 00085 log_resync (void) 00086 { 00087 m_sink << std::flush; 00088 } 00089 00090 } // end namespace ASSA 00091 00092 #endif /* FILE_LOGGER_H */