logger.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 
30 #pragma once
31 
32 #include "../api_core.h"
33 #include "string_format.h"
34 #include "string_help.h"
35 #include "../System/mutex.h"
36 
37 namespace clan
38 {
41 
43 class CL_API_CORE Logger
44 {
47 
48 public:
50  Logger();
51 
52  virtual ~Logger();
53 
57 
58 public:
60  static std::vector<Logger*> instances;
61 
63  static Mutex mutex;
64 
68 
69 public:
71  void enable();
72 
74  void disable();
75 
77  virtual void log(const std::string &type, const std::string &text);
78 
82 
83 private:
85 };
86 
89 CL_API_CORE void log_event(const std::string &type, const std::string &text);
90 
91 template <class Arg1>
92 void log_event(const std::string &type, const std::string &format, Arg1 arg1)
93 { StringFormat f(format); f.set_arg(1, arg1); log_event(type, f.get_result()); }
94 
95 template <class Arg1, class Arg2>
96 void log_event(const std::string &type, const std::string &format, Arg1 arg1, Arg2 arg2)
97 { StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); log_event(type, f.get_result()); }
98 
99 template <class Arg1, class Arg2, class Arg3>
100 void log_event(const std::string &type, const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
101 { StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); log_event(type, f.get_result()); }
102 
103 template <class Arg1, class Arg2, class Arg3, class Arg4>
104 void log_event(const std::string &type, const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
105 { StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); f.set_arg(4, arg4); log_event(type, f.get_result()); }
106 
107 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
108 void log_event(const std::string &type, const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
109 { StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); f.set_arg(4, arg4); f.set_arg(5, arg5); log_event(type, f.get_result()); }
110 
111 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
112 void log_event(const std::string &type, const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
113 { StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); f.set_arg(4, arg4); f.set_arg(5, arg5); f.set_arg(6, arg6); log_event(type, f.get_result()); }
114 
115 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
116 void log_event(const std::string &type, const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
117 { StringFormat f(format); f.set_arg(1, arg1); f.set_arg(2, arg2); f.set_arg(3, arg3); f.set_arg(4, arg4); f.set_arg(5, arg5); f.set_arg(6, arg6); f.set_arg(7, arg7); log_event(type, f.get_result()); }
118 
119 }
120 
CL_API_CORE void log_event(const std::string &type, const std::string &text)
Log text to logger.
static Mutex mutex
Logger mutex object.
Definition: logger.h:63
void set_arg(int index, const std::string &text)
Set arg.
Logger interface.
Definition: logger.h:43
Mutex class.
Definition: mutex.h:50
static std::vector< Logger * > instances
Pointers to currently enabled logger.
Definition: logger.h:60
String formatting class.
Definition: string_format.h:41
const std::string & get_result() const