Line data Source code
1 : /*
2 : * Copyright (C) 2024 Sky UK
3 : *
4 : * This library is free software; you can redistribute it and/or
5 : * modify it under the terms of the GNU Lesser General Public
6 : * License as published by the Free Software Foundation;
7 : * version 2.1 of the License.
8 : *
9 : * This library is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : * Lesser General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public
15 : * License along with this library; if not, write to the Free Software
16 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 : */
18 :
19 : //
20 : // This allows, for example, passing the following environment variable
21 : // to the client app which will enable rialto logging via gstreamer...
22 : // GST_DEBUG=6
23 : //
24 :
25 : #include <string>
26 :
27 : #include "LogToGstHandler.h"
28 :
29 : #ifdef USE_ETHANLOG
30 :
31 : #include <ethanlog.h>
32 :
33 : #define SYSTEM_LOG_FATAL(filename, function, line, ...) ethanlog(ETHAN_LOG_FATAL, filename, function, line, __VA_ARGS__)
34 : #define SYSTEM_LOG_ERROR(filename, function, line, ...) ethanlog(ETHAN_LOG_ERROR, filename, function, line, __VA_ARGS__)
35 : #define SYSTEM_LOG_WARN(filename, function, line, ...) \
36 : ethanlog(ETHAN_LOG_WARNING, filename, function, line, __VA_ARGS__)
37 : #define SYSTEM_LOG_MIL(filename, function, line, ...) \
38 : ethanlog(ETHAN_LOG_MILESTONE, filename, function, line, __VA_ARGS__)
39 : #define SYSTEM_LOG_INFO(filename, function, line, ...) ethanlog(ETHAN_LOG_INFO, filename, function, line, __VA_ARGS__)
40 : #define SYSTEM_LOG_DEBUG(filename, function, line, ...) ethanlog(ETHAN_LOG_DEBUG, filename, function, line, __VA_ARGS__)
41 :
42 : #else
43 :
44 : #include <gst/gst.h>
45 :
46 : #define SYSTEM_LOG_FATAL(filename, function, line, ...) GST_CAT_ERROR(kGstRialtoCategory, __VA_ARGS__)
47 : #define SYSTEM_LOG_ERROR(filename, function, line, ...) GST_CAT_ERROR(kGstRialtoCategory, __VA_ARGS__)
48 : #define SYSTEM_LOG_WARN(filename, function, line, ...) GST_CAT_WARNING(kGstRialtoCategory, __VA_ARGS__)
49 : #define SYSTEM_LOG_MIL(filename, function, line, ...) GST_CAT_INFO(kGstRialtoCategory, __VA_ARGS__)
50 : #define SYSTEM_LOG_INFO(filename, function, line, ...) GST_CAT_INFO(kGstRialtoCategory, __VA_ARGS__)
51 : #define SYSTEM_LOG_DEBUG(filename, function, line, ...) GST_CAT_DEBUG(kGstRialtoCategory, __VA_ARGS__)
52 :
53 : namespace
54 : {
55 : GST_DEBUG_CATEGORY_STATIC(kGstRialtoCategory);
56 : const char *kCategory = "rialto";
57 : }; // namespace
58 :
59 : #endif
60 :
61 : using namespace firebolt::rialto;
62 :
63 2 : LogToGstHandler::LogToGstHandler()
64 : {
65 : #ifndef USE_ETHANLOG
66 2 : GST_DEBUG_CATEGORY_INIT(kGstRialtoCategory, kCategory, 0, "Messages from rialto client library");
67 : #endif
68 : }
69 :
70 : LogToGstHandler::~LogToGstHandler() {}
71 :
72 7 : void LogToGstHandler::log(Level level, const std::string &file, int line, const std::string &function,
73 : const std::string &message)
74 : {
75 7 : std::string toReport;
76 7 : toReport += "M:" + file;
77 7 : toReport += " F:" + function;
78 7 : toReport += " L:" + std::to_string(line);
79 7 : toReport += " > " + message;
80 :
81 7 : switch (level)
82 : {
83 1 : case Level::Fatal:
84 1 : SYSTEM_LOG_FATAL(file.c_str(), function.c_str(), line, "%s", toReport.c_str());
85 1 : break;
86 :
87 1 : case Level::Error:
88 1 : SYSTEM_LOG_ERROR(file.c_str(), function.c_str(), line, "%s", toReport.c_str());
89 1 : break;
90 :
91 1 : case Level::Warning:
92 1 : SYSTEM_LOG_WARN(file.c_str(), function.c_str(), line, "%s", toReport.c_str());
93 1 : break;
94 :
95 1 : case Level::Milestone:
96 1 : SYSTEM_LOG_MIL(file.c_str(), function.c_str(), line, "%s", toReport.c_str());
97 1 : break;
98 :
99 1 : case Level::Info:
100 1 : SYSTEM_LOG_INFO(file.c_str(), function.c_str(), line, "%s", toReport.c_str());
101 1 : break;
102 :
103 1 : case Level::Debug:
104 1 : SYSTEM_LOG_DEBUG(file.c_str(), function.c_str(), line, "%s", toReport.c_str());
105 1 : break;
106 :
107 1 : case Level::External:
108 : default:
109 1 : SYSTEM_LOG_INFO(file.c_str(), function.c_str(), line, "%s", toReport.c_str());
110 1 : break;
111 : }
112 7 : }
|