Debian Codegraph @

src/log/Log.h

raw
1 /*
2 * Copyright (C) 2014-2021 Team Kodi (https://kodi.tv)
3 * Portions Copyright (C) 2013-2014 Lars Op den Kamp
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSE.md for more information.
7 */
8
9 #pragma once
10
11 #include "ILog.h"
12
13 #include <mutex>
14
15 #include <string>
16
17 // --- Shorthand logging -------------------------------------------------------
18
19 #ifndef esyslog
20 #define esyslog(...) LIBRETRO::CLog::Get().Log(SYS_LOG_ERROR, __VA_ARGS__)
21 #endif
22
23 #ifndef isyslog
24 #define isyslog(...) LIBRETRO::CLog::Get().Log(SYS_LOG_INFO, __VA_ARGS__)
25 #endif
26
27 #ifndef dsyslog
28 #define dsyslog(...) LIBRETRO::CLog::Get().Log(SYS_LOG_DEBUG, __VA_ARGS__)
29 #endif
30
31 #define LOG_ERROR_STR(str) esyslog("ERROR (%s, %d): %s: %m", __FILE__, __LINE__, str)
32
33 // --- CLog --------------------------------------------------------------------
34
35 namespace LIBRETRO
36 {
37 class CLog
38 {
39 private:
40 CLog(ILog* pipe);
41
42 public:
43 static CLog& Get(void);
44 ~CLog(void);
45
46 bool SetType(SYS_LOG_TYPE type);
47 void SetLevel(SYS_LOG_LEVEL level);
48 void SetLogPrefix(const std::string& strLogPrefix);
49
50 void Log(SYS_LOG_LEVEL level, const char* format, ...);
51
52 static const char* TypeToString(SYS_LOG_TYPE type);
53
54 private:
55 void SetPipe(ILog* pipe);
56
57 static const char* GetLogPrefix(SYS_LOG_LEVEL level);
58
59 ILog* m_pipe;
60 SYS_LOG_LEVEL m_level;
61 std::string m_strLogPrefix;
62 std::mutex m_mutex;
63 };
64 }