Scene Fusion 2 API Reference
Log.h
1 /*************************************************************************
2  *
3  * KINEMATICOUP CONFIDENTIAL
4  * __________________
5  *
6  * Copyright (2016-2021) KinematicSoup Technologies Incorporated
7  * All Rights Reserved.
8  *
9  * NOTICE: All information contained herein is, and remains
10  * the property of KinematicSoup Technologies Incorporated and its
11  * suppliers, if any. The intellectual and technical concepts contained
12  * herein are proprietary to KinematicSoup Technologies Incorporated
13  * and its suppliers and may be covered by Canadian and Foreign Patents,
14  * patents in process, and are protected by trade secret or copyright law.
15  * Dissemination of this information or reproduction of this material
16  * is strictly forbidden unless prior written permission is obtained
17  * from KinematicSoup Technologies Incorporated.
18  */
19 #pragma once
20 
21 #include <ctime>
22 #include <chrono>
23 #include <cstring>
24 #include <cstdio>
25 #include <fstream>
26 #include <iostream>
27 #include <ostream>
28 #include <string>
29 #include <unordered_map>
30 #include <vector>
31 #include <memory>
32 
33 #include "Exports.h"
34 
35 #ifdef _WIN32
36  #define __cdecl
37 #else
38  #define __cdecl __attribute__((__cdecl__))
39 #endif
40 
41 #define AUTHENTICATION_CHANNEL "Authentication"
42 
46 namespace KS {
47  // Log Levels
48  enum LogLevel:uint8_t
49  {
50  LOG_ALL = 0xFF,
51  LOG_FATAL = 16,
52  LOG_ERROR = 8,
53  LOG_WARNING = 4,
54  LOG_INFO = 2,
55  LOG_DEBUG = 1
56  };
57 
65  typedef void(__cdecl *LogHandler)(LogLevel level, const char* channel, const char* message);
66 
75  class Log
76  {
77  public:
83  EXTERNAL static std::shared_ptr<Log> Instance();
84 
90  EXTERNAL static void SetInstance(std::shared_ptr<Log> logPtr);
91 
101  EXTERNAL void RegisterCallback(const std::string& channel, LogHandler handler, uint8_t levels, bool allowBubbling);
102 
109  EXTERNAL void UnregisterCallback(const std::string& channel, LogHandler handler);
110 
120  EXTERNAL void Write(const std::string& message, const std::string& channel, LogLevel level);
121 
128  EXTERNAL static void Debug(const std::string& message, const std::string& channel = "Root");
129 
136  EXTERNAL static void Info(const std::string& message, const std::string& channel = "Root");
137 
144  EXTERNAL static void Warning(const std::string& message, const std::string& channel = "Root");
145 
152  EXTERNAL static void Error(const std::string& message, const std::string& channel = "Root");
153 
160  EXTERNAL static void Fatal(const std::string& message, const std::string& channel = "Root");
161 
168  EXTERNAL static std::string GetLevelString(LogLevel logLevel);
169 
175  EXTERNAL static std::string GetTimeString();
176 
177  private:
178  static std::shared_ptr<Log> m_instancePtr;
179 
180  struct Logger
181  {
182  LogHandler handler;
183  uint8_t levels;
184  bool allowBubbling;
185  };
186 
187  std::unordered_map<std::string, std::vector<Logger>> m_loggers;
188 
197  bool HandleLog(
198  const std::string& message,
199  const std::string& channel,
200  LogLevel level,
201  const std::string& handler);
202  };
203 }
Definition: Log.h:76
EXTERNAL void Write(const std::string &message, const std::string &channel, LogLevel level)
static EXTERNAL std::shared_ptr< Log > Instance()
static EXTERNAL void Info(const std::string &message, const std::string &channel="Root")
static EXTERNAL void Error(const std::string &message, const std::string &channel="Root")
static EXTERNAL std::string GetTimeString()
static EXTERNAL std::string GetLevelString(LogLevel logLevel)
EXTERNAL void RegisterCallback(const std::string &channel, LogHandler handler, uint8_t levels, bool allowBubbling)
static EXTERNAL void Debug(const std::string &message, const std::string &channel="Root")
EXTERNAL void UnregisterCallback(const std::string &channel, LogHandler handler)
static EXTERNAL void Fatal(const std::string &message, const std::string &channel="Root")
static EXTERNAL void Warning(const std::string &message, const std::string &channel="Root")
static EXTERNAL void SetInstance(std::shared_ptr< Log > logPtr)
Definition: sfDictionaryProperty.h:24
void(__cdecl * LogHandler)(LogLevel level, const char *channel, const char *message)
Definition: Log.h:65