| 1 |
/* |
| 2 |
* The Mana World |
| 3 |
* Copyright (C) 2004 The Mana World Development Team |
| 4 |
* |
| 5 |
* This file is part of The Mana World. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef _LOG_H |
| 23 |
#define _LOG_H |
| 24 |
|
| 25 |
#include <fstream> |
| 26 |
|
| 27 |
class ChatWindow; |
| 28 |
|
| 29 |
/** |
| 30 |
* The Log Class : Useful to write debug or info messages |
| 31 |
*/ |
| 32 |
class Logger |
| 33 |
{ |
| 34 |
public: |
| 35 |
/** |
| 36 |
* Constructor. |
| 37 |
*/ |
| 38 |
Logger(); |
| 39 |
|
| 40 |
/** |
| 41 |
* Destructor, closes log file. |
| 42 |
*/ |
| 43 |
~Logger(); |
| 44 |
|
| 45 |
/** |
| 46 |
* Sets the file to log to and opens it |
| 47 |
*/ |
| 48 |
void setLogFile(const std::string &logFilename); |
| 49 |
|
| 50 |
/** |
| 51 |
* Sets whether the log should be written to standard output. |
| 52 |
*/ |
| 53 |
void setLogToStandardOut(bool value) { mLogToStandardOut = value; } |
| 54 |
|
| 55 |
/** |
| 56 |
* Enables logging to chat window |
| 57 |
*/ |
| 58 |
void setChatWindow(ChatWindow *window) { mChatWindow = window; } |
| 59 |
|
| 60 |
/** |
| 61 |
* Enters a message in the log. The message will be timestamped. |
| 62 |
*/ |
| 63 |
void log(const char *log_text, ...) |
| 64 |
#ifdef __GNUC__ |
| 65 |
__attribute__((__format__(__printf__, 2, 3))) |
| 66 |
#endif |
| 67 |
; |
| 68 |
|
| 69 |
/** |
| 70 |
* Log an error and quit. The error will pop-up on Windows and Mac, and |
| 71 |
* will be printed to standard error everywhere else. |
| 72 |
*/ |
| 73 |
void error(const std::string &error_text); |
| 74 |
|
| 75 |
private: |
| 76 |
std::ofstream mLogFile; |
| 77 |
bool mLogToStandardOut; |
| 78 |
ChatWindow *mChatWindow; |
| 79 |
}; |
| 80 |
|
| 81 |
extern Logger *logger; |
| 82 |
|
| 83 |
#endif |