MxEngine
Logger.h
1 // Copyright(c) 2019 - 2020, #Momo
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met :
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and /or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #include <iostream>
32 #include <string>
33 
34 #include "Utilities/SingletonHolder/SingletonHolder.h"
35 #include "Utilities/Format/Format.h"
36 
37 namespace MxEngine
38 {
43  class LoggerImpl
44  {
45  std::ostream* error = &std::cout;
46  std::ostream* debug = &std::cout;
47  std::ostream* warning = &std::cout;
48  bool useDebug = true;
49  bool useWarning = true;
50  bool useError = true;
51  bool useStackTrace = true;
52  public:
53  LoggerImpl() = default;
54  LoggerImpl(const LoggerImpl&) = delete;
55  LoggerImpl(LoggerImpl&&) = delete;
56 
62  void Error (const MxString& invoker, const MxString& message) const;
68  void Debug (const MxString& invoker, const MxString& message) const;
74  void Warning(const MxString& invoker, const MxString& message) const;
79  void StackTrace() const;
84  LoggerImpl& UseErrorStream(std::ostream* error);
89  LoggerImpl& UseWarningStream(std::ostream* warning);
94  LoggerImpl& UseDebugStream(std::ostream* debug);
98  LoggerImpl& UseDebug(bool value = true);
102  LoggerImpl& UseWarning(bool value = true);
106  LoggerImpl& UseError(bool value = true);
110  LoggerImpl& UseStackTrace(bool value = true);
111  };
112 
114 
115  // macro for fast debug messages insert. Prints warnings in format [MX_DBG Warning]: { your message }
116  #define MX_DBG(msg) Logger::Instance().Warning("MX_DBG", msg)
117 }
LoggerImpl & UseWarningStream(std::ostream *warning)
Definition: Logger.cpp:130
LoggerImpl & UseError(bool value=true)
Definition: Logger.cpp:154
void Error(const MxString &invoker, const MxString &message) const
Definition: Logger.cpp:43
Definition: SingletonHolder.h:48
LoggerImpl & UseStackTrace(bool value=true)
Definition: Logger.cpp:160
LoggerImpl & UseWarning(bool value=true)
Definition: Logger.cpp:148
void Debug(const MxString &invoker, const MxString &message) const
Definition: Logger.cpp:61
LoggerImpl & UseErrorStream(std::ostream *error)
Definition: Logger.cpp:124
LoggerImpl & UseDebug(bool value=true)
Definition: Logger.cpp:142
void StackTrace() const
Definition: Logger.cpp:114
LoggerImpl & UseDebugStream(std::ostream *debug)
Definition: Logger.cpp:136
Definition: Application.cpp:49
void Warning(const MxString &invoker, const MxString &message) const
Definition: Logger.cpp:69
Definition: Logger.h:43