filelog.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008 
00009   RCS information
00010    $Name: OSB_060808 $
00011    $Revision: 1.14 $
00012 
00013   License
00014    OSB rating and billing library for communication networks
00015    Copyright (C) 2004, 2005, 2006  OSB systems
00016 
00017    This file may be distributed and/or modify under the terms of the
00018    GNU General Public License (GPL) as published by the Free Software
00019    Foundation which is provided in the file LICENSE.GPL included in the
00020    packaging of this file.
00021 
00022    The file is distributed in the hope that it will be useful, but WITHOUT
00023    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025    for more details.
00026 
00027    Holders of a OSB Commercial License may use this file under the terms
00028    and conditions of this commercial license.
00029  */
00030 #ifndef _FILELOG_H_
00031 #define _FILELOG_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 #include <fstream>
00037 #include <sstream>
00038 
00039 // + libraries
00040 
00041 // + local headers
00042 #include "osblog.h"
00043 
00044 // + class declarations
00045 
00046 // ************************************************************************
00047 // namespace extensions
00048 namespace OSB_APP {
00049 
00050 // ************************************************************************
00051 // forward declarations
00052 
00053 // ************************************************************************
00054 // type definitions
00055 
00056 // ************************************************************************
00057 // class definitions
00061     class FileLogBase : public OSB_LIB::LogBase {
00062     public:
00064         explicit FileLogBase(int logLevel);
00077         virtual ~FileLogBase() = 0;
00078     private:
00080         FileLogBase(const FileLogBase&);
00082         FileLogBase& operator==(const FileLogBase&);
00083 
00084     public:
00086 
00087 
00092         LogBase& nl();
00098         void elog();
00104         void endlog();
00106         LogBase& head(char);
00108 
00109     public:
00111 
00112 
00113         int logLevel() const;
00115         bool verbose() const;
00117         std::string tempBuf() const;
00125         std::string path() const;
00126 
00132         void setLevel(int logLevel);
00134         void setVerbose(bool on);
00146         bool open(
00147             const std::string&       name,
00148             const std::string&       dir,
00149                   std::ios::openmode mode,
00150                   bool               flush = true
00151         );
00152 
00164         bool create(
00165             const std::string& app,
00166             const std::string& dir,
00167                   bool         flush = true
00168         );
00169 
00181         bool append(
00182             const std::string& name,
00183             const std::string& dir,
00184                   bool         flush = true
00185         );
00191         bool close();
00199         bool flushTemp();
00203         void clearTemp();
00205 
00206     private:
00214         virtual void lock() const;
00222         virtual void unlock() const;
00223 
00224     private:
00231 
00232         std::string tempBufUl() const;
00233 
00242         bool openUl(
00243             const std::string&       name,
00244             const std::string&       dir,
00245                   std::ios::openmode mode,
00246                   bool               flush
00247         );
00248 
00257         bool createUl(
00258             const std::string& app,
00259             const std::string& dir,
00260                   bool         flush
00261         );
00262 
00268         bool closeUl();
00269 
00278         bool flushTempUl();
00280         void clearTempUl();
00282 
00283     private:
00293         LogBase& start(int level, bool noHead);
00294 
00300         LogBase& init(const char* what);
00301 
00308         std::ostream& plog();
00315         std::ostream* slog();
00316 
00317     private:
00319         std::ofstream os_;
00321         std::string path_;
00322 
00324         bool useCerr_;
00325 
00327         std::ostringstream ts_;
00328     };                                  // class FileLogBase
00329 
00333     class FileLog : public FileLogBase {
00334     public:
00336         explicit FileLog(int logLevel = 4);
00337     private:
00339         FileLog(const FileLog&);
00341         FileLog& operator==(const FileLog&);
00342     };                                  // class FileLog
00343 }                                       // namespace OSB_APP
00344 
00345 // ************************************************************************
00346 // inline definitions
00347 namespace OSB_APP {
00348 }                                       // namespace OSB_APP
00349 #endif                                  // #ifndef _FILELOG_H_

Generated on Sat Sep 2 14:17:18 2006 for OSB Library by  doxygen 1.4.7