1 /*============================================================================== 2 Copyright(c) 2017 Intel Corporation 3 4 Permission is hereby granted, free of charge, to any person obtaining a 5 copy of this software and associated documentation files(the "Software"), 6 to deal in the Software without restriction, including without limitation 7 the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 and / or sell copies of the Software, and to permit persons to whom the 9 Software is furnished to do so, subject to the following conditions: 10 11 The above copyright notice and this permission notice shall be included 12 in all copies or substantial portions of the Software. 13 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 OTHER DEALINGS IN THE SOFTWARE. 21 ============================================================================*/ 22 23 #pragma once 24 25 #ifdef __cplusplus 26 #if GMM_LOG_AVAILABLE 27 28 #include "spdlog/spdlog.h" 29 30 ///////////////////////////////////////////////////////////////////////////////////// 31 /// @file Logger.h 32 /// @brief This file contains the functions that are useful for logging in GmmLib 33 ///////////////////////////////////////////////////////////////////////////////////// 34 namespace GmmLib 35 { 36 class Logger 37 { 38 private: 39 /// This enum determines where the log goes 40 enum GmmLogMethod 41 { 42 ToOSLog, ///< Log is sent to OS logging infrastructure (Debugger on Windows) 43 ToFile, ///< Log is written to file 44 } LogMethod; ///< Indicates which Logging method is preferred 45 46 spdlog::level::level_enum LogLevel; ///< Indicates the max log level to print 47 48 private: 49 Logger(); 50 ~Logger(); 51 52 bool GmmLogInit(); 53 54 public: 55 std::shared_ptr<spdlog::logger> SpdLogger; ///< spdlog instance 56 57 ///////////////////////////////////////////////////////////////////////////////////// 58 /// Creates a Logger singlton per process 59 /// 60 /// @remark 61 /// If there are multiple modules loaded in one process, this singleton will be 62 /// per module. For example: D3D10 and D3D12 are all used in process A. Both D3D10 63 /// and D3D12 are built with GmmLib.lib. They are considered to be two modules and 64 /// each has a Logger instance (singleton). 65 /// 66 /// @return Logger instance 67 ///////////////////////////////////////////////////////////////////////////////////// CreateGmmLogSingleton()68 static Logger& CreateGmmLogSingleton() 69 { 70 static Logger GmmLoggerPerProc; 71 return GmmLoggerPerProc; 72 } 73 }; 74 } // namespace GmmLib 75 76 // Macros 77 extern GmmLib::Logger& GmmLoggerPerProc; 78 #endif 79 #endif