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-2015, 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 
34 
41 {
42  LOG_TRACE = 1,
43  LOG_DEBUG = 2,
44  LOG_INFO = 3,
45  LOG_WARN = 4,
46  LOG_ERROR = 5,
47  LOG_NONE = 6
48 };
49 
50 
57 class CLogger : public CSingleton<CLogger>
58 {
59 public:
60  CLogger();
61  ~CLogger();
62 
67  void Message(const char *str, ...);
68 
73  void Trace(const char *str, ...);
74 
79  void Debug(const char *str, ...);
80 
85  void Info(const char *str, ...);
86 
91  void Warn(const char *str, ...);
92 
97  void Error(const char *str, ...);
98 
104  void Log(LogLevel logLevel, const char *str, ...);
105 
109  void SetOutputFile(std::string filename);
110 
114  void SetLogLevel(LogLevel level);
115 
123  static bool ParseLogLevel(const std::string& str, LogLevel& logLevel);
124 
125 private:
126  std::string m_filename;
127  FILE *m_file;
128  LogLevel m_logLevel;
129 
130  void Open();
131  void Close();
132  bool IsOpened();
133  void Log(LogLevel type, const char* str, va_list args);
134 };
135 
136 
139 {
140  return CLogger::GetInstancePointer();
141 }
void Debug(const char *str,...)
Definition: logger.cpp:81
Definition: logger.h:47
CSingleton base class for singletons.
Class for loggin information to file or console.
Definition: logger.h:57
void Trace(const char *str,...)
Definition: logger.cpp:73
Definition: logger.h:44
Definition: logger.h:42
Definition: singleton.h:30
void SetOutputFile(std::string filename)
Definition: logger.cpp:129
void SetLogLevel(LogLevel level)
Definition: logger.cpp:154
CLogger * GetLogger()
Global function to get Logger instance.
Definition: logger.h:138
void Error(const char *str,...)
Definition: logger.cpp:105
void Message(const char *str,...)
Definition: logger.cpp:113
LogLevel
Enum representing log level.
Definition: logger.h:40
Definition: logger.h:43
Definition: logger.h:45
static bool ParseLogLevel(const std::string &str, LogLevel &logLevel)
Definition: logger.cpp:159
void Log(LogLevel logLevel, const char *str,...)
Definition: logger.cpp:121
void Warn(const char *str,...)
Definition: logger.cpp:97
void Info(const char *str,...)
Definition: logger.cpp:89
Definition: logger.h:46