Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
logger.h
Go to the documentation of this file.
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2012, Polish Portal of Colobot (PPC)
3 // *
4 // * This program is free software: you can redistribute it and/or modify
5 // * it under the terms of the GNU General Public License as published by
6 // * the Free Software Foundation, either version 3 of the License, or
7 // * (at your option) any later version.
8 // *
9 // * This program is distributed in the hope that it will be useful,
10 // * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // * GNU General Public License for more details.
13 // *
14 // * You should have received a copy of the GNU General Public License
15 // * along with this program. If not, see http://www.gnu.org/licenses/.
16 
22 #pragma once
23 
24 
25 #include "common/singleton.h"
26 
27 #include <string>
28 #include <cstdarg>
29 #include <cstdio>
30 
31 
38 {
39  LOG_TRACE = 1,
40  LOG_DEBUG = 2,
41  LOG_INFO = 3,
42  LOG_WARN = 4,
43  LOG_ERROR = 5,
44  LOG_NONE = 6
45 };
46 
47 
54 class CLogger : public CSingleton<CLogger>
55 {
56 public:
57  CLogger();
58  ~CLogger();
59 
64  void Message(const char *str, ...);
65 
70  void Trace(const char *str, ...);
71 
76  void Debug(const char *str, ...);
77 
82  void Info(const char *str, ...);
83 
88  void Warn(const char *str, ...);
89 
94  void Error(const char *str, ...);
95 
99  void SetOutputFile(std::string filename);
100 
104  void SetLogLevel(LogLevel level);
105 
113  static bool ParseLogLevel(const std::string& str, LogLevel& logLevel);
114 
115 private:
116  std::string m_filename;
117  FILE *m_file;
118  LogLevel m_logLevel;
119 
120  void Open();
121  void Close();
122  bool IsOpened();
123  void Log(LogLevel type, const char* str, va_list args);
124 };
125 
126 
129 {
130  return CLogger::GetInstancePointer();
131 }
132 
void Debug(const char *str,...)
Definition: logger.cpp:82
Definition: logger.h:44
CSingleton base class for singletons.
Class for loggin information to file or console.
Definition: logger.h:54
void Trace(const char *str,...)
Definition: logger.cpp:73
Definition: logger.h:41
Definition: logger.h:39
Definition: singleton.h:27
void SetOutputFile(std::string filename)
Definition: logger.cpp:127
void SetLogLevel(LogLevel level)
Definition: logger.cpp:156
CLogger * GetLogger()
Global function to get Logger instance.
Definition: logger.h:128
void Error(const char *str,...)
Definition: logger.cpp:109
void Message(const char *str,...)
Definition: logger.cpp:118
LogLevel
Enum representing log level.
Definition: logger.h:37
Definition: logger.h:40
Definition: logger.h:42
static bool ParseLogLevel(const std::string &str, LogLevel &logLevel)
Definition: logger.cpp:162
void Warn(const char *str,...)
Definition: logger.cpp:100
void Info(const char *str,...)
Definition: logger.cpp:91
Definition: logger.h:43