00001 /* 00002 * LogWriter.h 00003 * 00004 * Smalltalk like class library for C++ 00005 * Logging facility with priorities and stream-like interface. Header. 00006 * 00007 * Copyright (c) 2004 Milan Cermak 00008 */ 00009 /* 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or (at your option) any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 */ 00024 #ifndef __LOGWRITER_H 00025 #define __LOGWRITER_H 00026 00027 #include <stlib/StreamDecorator.h> 00028 00029 #include <stlib/SequenceableCollection.h> 00030 #include <stlib/String.h> 00031 #include <stlib/os/Semaphore.h> 00032 00033 namespace Tools { 00034 00035 enum LogVerbosityLevel { 00036 LogNone, LogError, LogWarning, LogInfo, LogTraffic, LogDebug 00037 }; 00038 00039 class Filename; 00040 00041 class LogWriter : public Core::StreamDecorator 00042 { 00043 protected: 00044 LogVerbosityLevel _level; 00045 OS::Semaphore *mutex; 00046 00047 public: 00048 LogWriter(Stream *output); 00049 ~LogWriter(void); 00050 00051 /* Instance creation protocol */ 00052 static LogWriter *on(String *filename); 00053 static LogWriter *on(Filename *filename); 00054 00055 /* Accessing protocol */ 00056 virtual Object *next(void); 00057 virtual void nextPut(Object *object); 00058 virtual void nextPut(const char object); 00059 virtual void writeLog(LogVerbosityLevel level, Collection *collection); 00060 virtual void writeLog(LogVerbosityLevel level, const char *collection); 00061 00062 virtual void logAll(void); 00063 virtual void logErrors(void); 00064 virtual void logWarnings(void); 00065 virtual void logInfos(void); 00066 virtual void logNone(void); 00067 virtual void logTraffic(void); 00068 virtual void logDebug(void); 00069 virtual LogVerbosityLevel verbosity(void); 00070 virtual void verbosity(LogVerbosityLevel level); 00071 00072 /* Status protocol */ 00073 virtual void close(void); 00074 virtual void commit(void); 00075 00076 /* Testing protocol */ 00077 virtual bool isBinary(void); 00078 00079 /* Private protocol */ 00080 virtual void writeLevel(LogVerbosityLevel level); 00081 00082 protected: 00083 virtual SequenceableCollection *contentSpeciesFor(long items); 00084 }; 00085 00086 }; 00087 00088 #endif /* __LOGWRITER_H */