root/trunk/src/game/WorldLog.h @ 102

Revision 102, 2.2 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
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 2 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. See the
14 * 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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/// \addtogroup u2w
22/// @{
23/// \file
24
25#ifndef TRINITY_WORLDLOG_H
26#define TRINITY_WORLDLOG_H
27
28#include "Common.h"
29#include "Policies/Singleton.h"
30#include "Errors.h"
31
32#include <stdarg.h>
33
34/// %Log packets to a file
35class TRINITY_DLL_DECL WorldLog : public Trinity::Singleton<WorldLog, Trinity::ClassLevelLockable<WorldLog, ZThread::FastMutex> >
36{
37    friend class Trinity::OperatorNew<WorldLog>;
38    WorldLog() : i_file(NULL) { Initialize(); }
39    WorldLog(const WorldLog &);
40    WorldLog& operator=(const WorldLog &);
41    typedef Trinity::ClassLevelLockable<WorldLog, ZThread::FastMutex>::Lock Guard;
42
43    /// Close the file in destructor
44    ~WorldLog()
45    {
46        if( i_file != NULL )
47            fclose(i_file);
48        i_file = NULL;
49    }
50
51    public:
52        void Initialize();
53        /// Is the world logger active?
54        inline bool LogWorld(void) const { return (i_file != NULL); }
55        /// %Log to the file
56        inline void Log(char const *fmt, ...)
57        {
58            if( LogWorld() )
59            {
60                Guard guard(*this);
61                ASSERT(i_file);
62
63                va_list args;
64                va_start(args, fmt);
65                vfprintf(i_file, fmt, args);
66                va_end(args);
67
68                fflush(i_file);
69            }
70        }
71
72    private:
73        FILE *i_file;
74};
75
76#define sWorldLog WorldLog::Instance()
77#endif
78/// @}
Note: See TracBrowser for help on using the browser.