Colobot
logger.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 
28 #include "common/singleton.h"
29 
30 #include <string>
31 #include <cstdarg>
32 #include <cstdio>
33 #include <vector>
34 
35 
42 {
43  LOG_TRACE = 1,
44  LOG_DEBUG = 2,
45  LOG_INFO = 3,
46  LOG_WARN = 4,
47  LOG_ERROR = 5,
48  LOG_NONE = 6
49 };
50 
51 
58 class CLogger : public CSingleton<CLogger>
59 {
60 public:
61  CLogger();
62  ~CLogger();
63 
68  void Message(const char *str, ...);
69 
74  void Trace(const char *str, ...);
75 
80  void Debug(const char *str, ...);
81 
86  void Info(const char *str, ...);
87 
92  void Warn(const char *str, ...);
93 
98  void Error(const char *str, ...);
99 
105  void Log(LogLevel logLevel, const char *str, ...);
106 
111  void AddOutput(FILE* file);
112 
116  void SetLogLevel(LogLevel level);
117 
125  static bool ParseLogLevel(const std::string& str, LogLevel& logLevel);
126 
127 private:
128  std::vector<FILE*> m_outputs;
129  LogLevel m_logLevel;
130  void Log(LogLevel type, const char* str, va_list args);
131 };
132 
133 
136 {
137  return CLogger::GetInstancePointer();
138 }
void Debug(const char *str,...)
Definition: logger.cpp:89
Definition: logger.h:48
CSingleton base class for singletons.
Class for loggin information to file or console.
Definition: logger.h:58
void Trace(const char *str,...)
Definition: logger.cpp:81
Definition: logger.h:45
Definition: logger.h:43
Definition: singleton.h:30
void AddOutput(FILE *file)
Definition: logger.cpp:137
void SetLogLevel(LogLevel level)
Definition: logger.cpp:143
CLogger * GetLogger()
Global function to get Logger instance.
Definition: logger.h:135
void Error(const char *str,...)
Definition: logger.cpp:113
void Message(const char *str,...)
Definition: logger.cpp:121
LogLevel
Enum representing log level.
Definition: logger.h:41
Definition: logger.h:44
Definition: logger.h:46
static bool ParseLogLevel(const std::string &str, LogLevel &logLevel)
Definition: logger.cpp:148
void Log(LogLevel logLevel, const char *str,...)
Definition: logger.cpp:129
void Warn(const char *str,...)
Definition: logger.cpp:105
void Info(const char *str,...)
Definition: logger.cpp:97
Definition: logger.h:47