iFun Engine API  1.0.0-b6053
Great Technology for Great Games
logging.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2020 iFunFactory Inc. All Rights Reserved.
2 //
3 // This work is confidential and proprietary to iFunFactory Inc. and
4 // must not be used, disclosed, copied, or distributed without the prior
5 // consent of iFunFactory Inc.
6 
9 #ifndef INCLUDE_FUNAPI_SYSTEM_LOGGING_H_
10 #define INCLUDE_FUNAPI_SYSTEM_LOGGING_H_
11 
12 #include <boost/noncopyable.hpp>
13 #include <boost/shared_ptr.hpp>
14 #include <boost/uuid/uuid.hpp>
15 #include <funapi/types.h>
16 #include <glog/logging.h>
17 
18 #include <vector>
19 #include <string>
20 
21 
22 #define LOW_CONCAT_HELPER(a, b) a##b
23 #define LOW_CONCAT(a, b) LOW_CONCAT_HELPER(a, b)
24 #define LOW_COUNT1 LOW_CONCAT(log_count1_, __LINE__)
25 #define LOW_COUNT2 LOW_CONCAT(log_count2_, __LINE__)
26 #define LOW_LAST LOW_CONCAT(log_last_, __LINE__)
27 #define LOW_GET_CTXT LOW_CONCAT(get_ctxt_, __LINE__)
28 
29 
30 #define LOG_ONCE_WHILE(lv, interval) \
31  static size_t LOW_COUNT1 = 0; \
32  static size_t LOW_COUNT2 = 0; \
33  static MonotonicClock::Value LOW_LAST = 0; \
34  static function<bool()> LOW_GET_CTXT = []( ) { \
35  ++LOW_COUNT1; \
36  if ((MonotonicClock::Now() - LOW_LAST) >= (interval * 1000 * 1000)) { \
37  LOW_LAST = MonotonicClock::Now(); \
38  LOW_COUNT2 = LOW_COUNT1; \
39  LOW_COUNT1 = 0; \
40  return true; \
41  } \
42  return false; \
43  }; \
44  LOG_IF(lv, LOW_GET_CTXT()) << "(#" << LOW_COUNT2 << ") "
45 
46 
47 namespace fun {
48 
49 enum LogColumnCppType {
50  LCT_BOOL,
51  LCT_TIME_T,
52  LCT_WALLCLOCK_VALUE,
53  LCT_DOUBLE,
54  LCT_INT64,
55  LCT_STRING,
56 };
57 
58 
59 typedef std::vector<string> LoggerColumnNames;
60 typedef std::vector<string> LoggerColumnValues;
61 typedef std::vector<bool> LoggerColumnQuotes;
62 typedef std::vector<LogColumnCppType> LoggerColumnCppTypes;
63 
64 
67 class FUNAPI_DLL_VISIBILITY LoggerRegistryHelper {
68  public:
76  LoggerRegistryHelper(const string &activityType,
77  const string &schema,
78  const LoggerColumnNames &columns,
79  const LoggerColumnCppTypes &types,
80  const LoggerColumnQuotes &quotes);
81 };
82 
83 
84 FUNAPI_DLL_VISIBILITY
85 void LogActivity(const string &activityType, const LoggerColumnValues &values);
86 
87 } // namespace fun
88 
89 #endif // INCLUDE_FUNAPI_SYSTEM_LOGGING_H_
Helper class to register user-defined activity log.
Definition: logging.h:67
Definition: json.h:18