OpenZWave Library  1.2
Log.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Log.h
4 //
5 // Cross-platform message and error logging
6 //
7 // Copyright (c) 2010 Mal Lansell <mal@lansell.org>
8 // All rights reserved.
9 //
10 // SOFTWARE NOTICE AND LICENSE
11 //
12 // This file is part of OpenZWave.
13 //
14 // OpenZWave is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU Lesser General Public License as published
16 // by the Free Software Foundation, either version 3 of the License,
17 // or (at your option) any later version.
18 //
19 // OpenZWave is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU Lesser General Public License for more details.
23 //
24 // You should have received a copy of the GNU Lesser General Public License
25 // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
26 //
27 //-----------------------------------------------------------------------------
28 #ifndef _Log_H
29 #define _Log_H
30 
31 #include <stdarg.h>
32 #include <string>
33 #include "Defs.h"
34 
35 
36 
37 namespace OpenZWave
38 {
39  class Mutex;
40  extern char const *LogLevelString[];
41  enum LogLevel
42  {
55  };
56 
57  class i_LogImpl
58  {
59  public:
60  i_LogImpl() { } ;
61  virtual ~i_LogImpl() { } ;
62  virtual void Write( LogLevel _level, uint8 const _nodeId, char const* _format, va_list _args ) = 0;
63  virtual void QueueDump() = 0;
64  virtual void QueueClear() = 0;
65  virtual void SetLoggingState( LogLevel _saveLevel, LogLevel _queueLevel, LogLevel _dumpTrigger ) = 0;
66  virtual void SetLogFileName( const string &_filename ) = 0;
67  };
68 
71  class Log
72  {
73  public:
81  static Log* Create( string const& _filename, bool const _bAppend, bool const _bConsoleOutput, LogLevel const _saveLevel, LogLevel const _queueLevel, LogLevel const _dumpTrigger );
82 
92  static Log* Create( i_LogImpl *LogClass );
93 
100  static void Destroy();
101 
107  static bool SetLoggingClass(i_LogImpl *LogClass );
108 
113  static void SetLoggingState(bool _dologging);
114 
122  static void SetLoggingState( LogLevel _saveLevel, LogLevel _queueLevel, LogLevel _dumpTrigger );
123 
128  static bool GetLoggingState();
129 
136  static void GetLoggingState( LogLevel* _saveLevel, LogLevel* _queueLevel, LogLevel* _dumpTrigger );
137 
144  static void SetLogFileName( const string &_filename );
145 
154  static void Write( LogLevel _level, char const* _format, ... );
155 
165  static void Write( LogLevel _level, uint8 const _nodeId, char const* _format, ... );
166 
170  static void QueueDump();
171 
175  static void QueueClear();
176 
177  private:
178  Log( string const& _filename, bool const _bAppend, bool const _bConsoleOutput, LogLevel _saveLevel, LogLevel _queueLevel, LogLevel _dumpTrigger );
179  ~Log();
180 
181  static i_LogImpl* m_pImpl;
182  static Log* s_instance;
183  Mutex* m_logMutex;
184  };
185 } // namespace OpenZWave
186 
187 #endif //_Log_H
LogLevel
Definition: Log.h:41
Definition: Bitfield.h:34
virtual void SetLoggingState(LogLevel _saveLevel, LogLevel _queueLevel, LogLevel _dumpTrigger)=0
i_LogImpl()
Definition: Log.h:60
virtual void QueueClear()=0
Definition: Log.h:54
virtual void QueueDump()=0
Definition: Log.h:46
char const * LogLevelString[]
Definition: Log.cpp:43
Definition: Log.h:44
virtual void Write(LogLevel _level, uint8 const _nodeId, char const *_format, va_list _args)=0
Definition: Log.h:45
virtual ~i_LogImpl()
Definition: Log.h:61
Definition: Log.h:47
Definition: Log.h:48
virtual void SetLogFileName(const string &_filename)=0
Definition: Log.h:51
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition: Mutex.h:39
Definition: Log.h:49
Definition: Log.h:57
Definition: Log.h:50
Implements a platform-independent log...written to the console and, optionally, a file...
Definition: Log.h:71
Definition: Log.h:43
unsigned char uint8
Definition: Defs.h:63