TrueReality  v0.1.1912
LogManager.h
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * The Base of this class has been adopted from the Delta3D engine
6 *
7 * This library is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the Free
9 * Software Foundation; either version 3.0 of the License, or (at your option)
10 * any later version.
11 *
12 * This library is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 * details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Class Inspired by the Delta3D Engine
22 * http://delta3dengine.org/
23 *
24 * @author Matthew W. Campbell
25 * @author Erik Johnson
26 * @author David Guthrie
27 * @author Maxim Serebrennik
28 */
29 #pragma once
30 #include <trUtil/Export.h>
31 
32 #include <trUtil/HashMap.h>
33 #include <trUtil/Logging/Log.h>
37 
38 #include <osg/Referenced>
39 #include <osg/ref_ptr>
40 #include <osg/observer_ptr>
41 
42 #include <string>
43 
49 namespace trUtil::Logging
50 {
56  class LogManager : public osg::Referenced
57  {
58  public:
59 
65  LogManager();
66 
72  ~LogManager();
73 
84  bool AddInstance(const std::string& name, Log* log);
85 
95  Log* GetInstance(const std::string& name);
96 
104  void SetAllLogLevels(const LogLevel& newLevel);
105 
118  void SetAllOutputStreamBits(unsigned int option);
119 
127  bool IsLogTimeProviderValid() const;
128 
134  void ReOpenFile();
135 
141  void LogHorizRule();
142 
150  void LogMessageToFile(const LogWriter::LogData& logData);
151 
159  void LogMessageToConsole(const LogWriter::LogData& logData);
160 
171 
179  unsigned int GetFrameNumber();
180 
188  const trUtil::DateTime& GetDateTime();
189 
197  OpenThreads::Mutex& GetMutex();
198 
199  private:
201 
202  osg::ref_ptr<LogWriter> mLogWriterConsole;
203  osg::ref_ptr<LogWriterFile> mLogWriterFile;
204  osg::observer_ptr<osg::Referenced> mLogTimeProviderAsRef;
206  OpenThreads::Mutex mMutex;
207  };
208 }
Log class which the engine uses for all of its logging needs.
Definition: Log.h:197
OpenThreads::Mutex & GetMutex()
Returns the reference to an internal OpenThreads Mutex.
Definition: LogManager.cpp:145
void LogMessageToConsole(const LogWriter::LogData &logData)
Write out a message to the screen console.
Definition: LogManager.cpp:113
void LogHorizRule()
Writes out a horizontal line to the Log File.
Definition: LogManager.cpp:101
Interface class get the time for the logger.
void LogMessageToFile(const LogWriter::LogData &logData)
Write out a message to the Log file.
Definition: LogManager.cpp:107
Log * GetInstance(const std::string &name)
Retrieves a stored Log instance.
Definition: LogManager.cpp:57
Manager for logs.
Definition: LogManager.h:56
trUtil::HashMap< std::string, osg::ref_ptr< Log > > mInstances
Definition: LogManager.h:200
bool AddInstance(const std::string &name, Log *log)
Stores a new Log instance in the manager.
Definition: LogManager.cpp:51
void SetLogTimeProvider(LogTimeProvider *ltp)
This sets a Log time source.
Definition: LogManager.cpp:119
bool IsLogTimeProviderValid() const
Check if the Log Time Provider is currently valid in this manager.
Definition: LogManager.cpp:88
LogManager()
Default constructor.
Definition: LogManager.cpp:35
OpenThreads::Mutex mMutex
Definition: LogManager.h:206
LogTimeProvider * mLogTimeProvider
Definition: LogManager.h:205
osg::ref_ptr< LogWriter > mLogWriterConsole
Definition: LogManager.h:202
osg::ref_ptr< LogWriterFile > mLogWriterFile
writes to console
Definition: LogManager.h:203
void ReOpenFile()
Reopens the log file.
Definition: LogManager.cpp:94
osg::observer_ptr< osg::Referenced > mLogTimeProviderAsRef
writes to file
Definition: LogManager.h:204
void SetAllLogLevels(const LogLevel &newLevel)
Set the Log Level for all active Loggers.
Definition: LogManager.cpp:68
unsigned int GetFrameNumber()
Returns the stored frame number.
Definition: LogManager.cpp:133
const trUtil::DateTime & GetDateTime()
Returns the reference to the stored DateTime object.
Definition: LogManager.cpp:139
void SetAllOutputStreamBits(unsigned int option)
Set the OutputStreamOptions bits for all stored Loggers The bits correspond to: NO_OUTPUT = 0x0000000...
Definition: LogManager.cpp:78