cAudio 2.3.0
3d Audio Engine
Loading...
Searching...
No Matches
cLogger.cpp
1// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
2// This file is part of the "cAudio Engine"
3// For conditions of distribution and use, see copyright notice in cAudio.h
4
5#include <time.h>
6#include <stdio.h>
7#include "cLogger.h"
8#include "cConsoleLogReceiver.h"
9#include "cFileLogReceiver.h"
10#include "cUtils.h"
11
12namespace cAudio
13{
14 cLogger::cLogger() : StartTime(0), MinLogLevel(ELL_INFO)
15 {
16 StartTime = clock();
17 }
18
19 void cLogger::logCritical( const char* sender, const char *msg, ... )
20 {
21 if(ELL_CRITICAL >= MinLogLevel)
22 {
23 Mutex.lock();
24 va_list args;
25 va_start( args, msg );
26 broadcastMessage( ELL_CRITICAL, sender, msg, args );
27 va_end( args );
28 Mutex.unlock();
29 }
30 }
31 void cLogger::logError( const char* sender, const char *msg, ... )
32 {
33 if(ELL_ERROR >= MinLogLevel)
34 {
35 Mutex.lock();
36 va_list args;
37 va_start( args, msg );
38 broadcastMessage( ELL_ERROR, sender, msg, args );
39 va_end( args );
40 Mutex.unlock();
41 }
42 }
43 void cLogger::logWarning( const char* sender, const char *msg, ... )
44 {
45 if(ELL_WARNING >= MinLogLevel)
46 {
47 Mutex.lock();
48 va_list args;
49 va_start( args, msg );
50 broadcastMessage( ELL_WARNING, sender, msg, args );
51 va_end( args );
52 Mutex.unlock();
53 }
54 }
55 void cLogger::logInfo( const char* sender, const char *msg, ... )
56 {
57 if(ELL_INFO >= MinLogLevel)
58 {
59 Mutex.lock();
60 va_list args;
61 va_start( args, msg );
62 broadcastMessage( ELL_INFO, sender, msg, args );
63 va_end( args );
64 Mutex.unlock();
65 }
66 }
67 void cLogger::logDebug( const char* sender, const char *msg, ... )
68 {
69 if(ELL_DEBUG >= MinLogLevel)
70 {
71 Mutex.lock();
72 va_list args;
73 va_start( args, msg );
74 broadcastMessage( ELL_DEBUG, sender, msg, args );
75 va_end( args );
76 Mutex.unlock();
77 }
78 }
79 void cLogger::setLogLevel( const LogLevel& logLevel )
80 {
81 Mutex.lock();
82 MinLogLevel = logLevel;
83 Mutex.unlock();
84 }
85 void cLogger::broadcastMessage( LogLevel level, const char* sender, const char* msg, va_list args )
86 {
87 float messageTime = (clock() - StartTime) / (float)CLOCKS_PER_SEC;
88 vsnprintf( TempTextBuf, 2048, msg, args );
89
90 ReceiversIterator it = Receivers.begin();
91 for (it = Receivers.begin(); it != Receivers.end(); it++)
92 {
93 it->second->OnLogMessage(sender, TempTextBuf, level, messageTime);
94 }
95 }
96 bool cLogger::registerLogReceiver(ILogReceiver* receiver, const char* name)
97 {
98 Mutex.lock();
99 cAudioString logName = fromUTF8(name);
100 Receivers[logName] = receiver;
101 Mutex.unlock();
102 return true;
103 }
104
105 void cLogger::unRegisterLogReceiver(const char* name)
106 {
107 Mutex.lock();
108 cAudioString logName = fromUTF8(name);
109 ReceiversIterator it = Receivers.find(logName);
110 if(it != Receivers.end())
111 {
112 Receivers.erase(it);
113 }
114 Mutex.unlock();
115 }
116
117 bool cLogger::isLogReceiverRegistered(const char* name)
118 {
119 Mutex.lock();
120 cAudioString logName = fromUTF8(name);
121 ReceiversIterator it = Receivers.find(logName);
122 bool result = (it != Receivers.end());
123 Mutex.unlock();
124 return result;
125 }
126
127 ILogReceiver* cLogger::getLogReceiver(const char* name)
128 {
129 Mutex.lock();
130 cAudioString logName = fromUTF8(name);
131 ReceiversIterator it = Receivers.find(logName);
132 if(it != Receivers.end())
133 {
134 Mutex.unlock();
135 return it->second;
136 }
137 Mutex.unlock();
138 return NULL;
139 }
140};
Interface for receiving log messages and relaying them to some kind of output device or stream.
Definition: ILogReceiver.h:33
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:16
LogLevel
Enum of all supported log levels in cAudio.
Definition: ILogReceiver.h:11