GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/chatlogger.h Lines: 0 1 0.0 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
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
31
class ChatLogger final
32
{
33
    public:
34
        /**
35
         * Constructor.
36
         */
37
        ChatLogger();
38
39
        A_DELETE_COPY(ChatLogger)
40
41
        /**
42
         * Destructor, closes log file.
43
         */
44
        ~ChatLogger();
45
46
        /**
47
         * Enters a message in the log. The message will be timestamped.
48
         */
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:
69
        /**
70
         * Sets the file to log to and opens it
71
         */
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