00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*- 00002 00003 // -- BEGIN LICENSE BLOCK ---------------------------------------------- 00004 // This file is part of FZIs ic_workspace. 00005 // 00006 // This program is free software licensed under the LGPL 00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3). 00008 // You can find a copy of this license in LICENSE folder in the top 00009 // directory of the source code. 00010 // 00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany 00012 // 00013 // -- END LICENSE BLOCK ------------------------------------------------ 00014 00015 //---------------------------------------------------------------------- 00026 //---------------------------------------------------------------------- 00027 #ifndef ICL_CORE_LOGGING_FILE_LOG_OUTPUT_H_INCLUDED 00028 #define ICL_CORE_LOGGING_FILE_LOG_OUTPUT_H_INCLUDED 00029 00030 #include <fstream> 00031 00032 #include "icl_core/TimeSpan.h" 00033 #include "icl_core/TimeStamp.h" 00034 #include "icl_core_logging/ImportExport.h" 00035 #include "icl_core_logging/LogOutputStream.h" 00036 00037 #ifdef _IC_BUILDER_ZLIB_ 00038 # include <zlib.h> 00039 #endif 00040 00041 namespace icl_core { 00042 namespace logging { 00043 00049 class ICL_CORE_LOGGING_IMPORT_EXPORT FileLogOutput : public LogOutputStream, 00050 protected virtual icl_core::Noncopyable 00051 { 00052 friend class LoggingManager; 00053 00054 public: 00057 static LogOutputStream *create(const icl_core::String& name, const icl_core::String& config_prefix, 00058 icl_core::logging::LogLevel log_level = cDEFAULT_LOG_LEVEL); 00059 00060 private: 00061 FileLogOutput(const icl_core::String& name, const icl_core::String& config_prefix, 00062 icl_core::logging::LogLevel log_level); 00063 FileLogOutput(const icl_core::String& name, const icl_core::String& config_prefix, 00064 icl_core::logging::LogLevel log_level, bool flush); 00065 virtual ~FileLogOutput(); 00066 00067 virtual void pushImpl(const icl_core::String& log_line); 00068 00069 void expandFilename(); 00070 00071 bool isOpen(); 00072 void flush(); 00073 00074 void closeLogFile(); 00075 void openLogFile(); 00076 void rotateLogFile(); 00077 00078 icl_core::String m_filename; 00079 std::ofstream m_log_file; 00080 00081 bool m_rotate; 00082 int64_t m_last_rotation; 00083 00084 bool m_delete_old_files; 00085 uint32_t m_delete_older_than_days; 00086 00087 bool m_flush; 00088 00089 #if defined(_IC_BUILDER_ZLIB_) 00090 bool m_online_zip; 00091 gzFile m_zipped_log_file; 00092 #endif 00093 }; 00094 00095 } 00096 } 00097 00098 #endif