ManaPlus
chatlogger.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2009-2010 The Mana Developers
4  * Copyright (C) 2011-2019 The ManaPlus Developers
5  * Copyright (C) 2009-2021 Andrei Karas
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef CHATLOGGER_H
24 #define CHATLOGGER_H
25 
26 #include <fstream>
27 #include <list>
28 
29 #include "localconsts.h"
30 
32 {
33  public:
37  ChatLogger();
38 
40 
41 
44  ~ChatLogger();
45 
49  void log(std::string str);
50 
51  void log(std::string name, std::string str);
52 
53  void loadLast(std::string name,
54  std::list<std::string> &list,
55  const unsigned int n) const;
56 
57  std::string getDir() const A_WARN_UNUSED;
58 
59  static std::string secureName(std::string &str);
60 
61  void setServerName(const std::string &serverName);
62 
63  void setBaseLogDir(const std::string &logDir)
64  { mBaseLogDir = logDir; }
65 
66  void clear();
67 
68  private:
72  void setLogFile(const std::string &logFilename);
73 
74  void setLogDir(const std::string &logDir);
75 
76  static void writeTo(std::ofstream &file,
77  const std::string &str);
78 
79  std::ofstream mLogFile;
80  std::string mLogDir;
81  std::string mBaseLogDir;
82  std::string mServerName;
83  std::string mLogFileName;
84 };
85 
86 extern ChatLogger *chatLogger;
87 
88 #endif // CHATLOGGER_H
ChatLogger * chatLogger
Definition: chatlogger.cpp:43
std::string mLogFileName
Definition: chatlogger.h:83
void setServerName(const std::string &serverName)
Definition: chatlogger.cpp:176
void loadLast(std::string name, std::list< std::string > &list, const unsigned int n) const
Definition: chatlogger.cpp:197
void setLogFile(const std::string &logFilename)
Definition: chatlogger.cpp:60
void clear()
Definition: chatlogger.cpp:228
static void writeTo(std::ofstream &file, const std::string &str)
Definition: chatlogger.cpp:170
std::string mBaseLogDir
Definition: chatlogger.h:81
static std::string secureName(std::string &str)
Definition: chatlogger.cpp:144
std::string getDir() const
Definition: chatlogger.cpp:124
void setBaseLogDir(const std::string &logDir)
Definition: chatlogger.h:63
std::string mServerName
Definition: chatlogger.h:82
void setLogDir(const std::string &logDir)
Definition: chatlogger.cpp:77
std::string mLogDir
Definition: chatlogger.h:80
void log(std::string str)
Definition: chatlogger.cpp:91
std::ofstream mLogFile
Definition: chatlogger.h:79
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53