OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
log-handle.cpp
Go to the documentation of this file.
1 /*
2  * mape - C4 Landscape.txt editor
3  *
4  * Copyright (c) 2005-2009, Armin Burgmeier
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #include "C4Include.h"
17 #include "lib/C4Log.h"
18 
19 // This implements the Log engine function such that the first log message
20 // is stored and can be retrieved later by the C API.
21 std::string first_log;
22 unsigned int n_logs = 0;
23 
24 bool Log(const char *msg)
25 {
26  if(first_log.empty())
27  {
28  assert(n_logs == 0);
29  first_log = msg;
30  }
31 
32  if(*msg != '\0')
33  ++n_logs;
34 
35  return true;
36 }
37 bool DebugLog(const char *strMessage) { return Log(strMessage); }
38 bool LogFatal(const char *strMessage) { return Log(strMessage); }
39 
40 #define IMPLEMENT_LOGF(func) \
41  bool func(const char *msg, ...) { \
42  va_list args; va_start(args, msg); \
43  StdStrBuf Buf; \
44  Buf.FormatV(msg, args); \
45  return Log(Buf.getData()); \
46  }
47 
51 
52 // C API follows here
53 extern "C" {
54 
56 {
57  first_log.clear();
58  n_logs = 0;
59 }
60 
62 {
63  if(first_log.empty()) return nullptr;
64  return first_log.c_str();
65 }
66 
68 {
69  return n_logs;
70 }
71 
72 } // extern "C"
bool DebugLog(const char *strMessage)
Definition: log-handle.cpp:37
bool Log(const char *msg)
Definition: log-handle.cpp:24
const char * c4_log_handle_get_first_log_message()
Definition: log-handle.cpp:61
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:263
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:281
unsigned int c4_log_handle_get_n_log_messages()
Definition: log-handle.cpp:67
std::string first_log
Definition: log-handle.cpp:21
void c4_log_handle_clear()
Definition: log-handle.cpp:55
unsigned int n_logs
Definition: log-handle.cpp:22
bool LogFatal(const char *strMessage)
Definition: log-handle.cpp:38
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
#define IMPLEMENT_LOGF(func)
Definition: log-handle.cpp:40