00001 //---------------------------------------------------------------------------// 00002 //Description: Deal with Log 00003 //Author: Wu Chen(wuchen@mail.ihep.ac.cn) 00004 //Created: 17 Oct, 2012 00005 //Comment: 00006 //---------------------------------------------------------------------------// 00007 00008 #ifndef LogSvc_h 00009 #define LogSvc_h 1 00010 00011 #include <string> 00012 00013 //for locking file 00014 #include <unistd.h> 00015 #include <fcntl.h> 00016 #include <errno.h> 00017 //#include <sys/file.h> 00018 00019 class LogSvc 00020 { 00021 public: 00022 LogSvc(); 00023 ~LogSvc(); 00024 00025 static LogSvc* GetLogSvc(); 00026 00027 bool CreateFile(); 00028 00029 bool CheckFileExist(); 00030 00031 bool CheckFileAvailable(); 00032 00033 void SetLogFile( const char* file_name ); 00034 00035 int AddLog( const char* run_name); 00036 00037 private: 00038 00039 int OpenFile(); 00040 00041 void CloseFile(); 00042 00043 int LockFile(); 00044 00045 int UnLockFile(); 00046 00047 static LogSvc* fLogSvc; 00048 00049 std::string fFileName; 00050 00051 int fd; 00052 00053 struct flock lock; 00054 00055 }; 00056 00057 #endif 00058