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 <gst/gst.h>
28 :
29 : #include "LogToGstHandler.h"
30 :
31 : namespace
32 : {
33 : GST_DEBUG_CATEGORY_STATIC(kGstRialtoCategory);
34 : const char *kCategory = "rialto";
35 : }; // namespace
36 :
37 : using namespace firebolt::rialto;
38 :
39 2 : LogToGstHandler::LogToGstHandler()
40 : {
41 2 : GST_DEBUG_CATEGORY_INIT(kGstRialtoCategory, kCategory, 0, "Messages from rialto client library");
42 : }
43 :
44 : LogToGstHandler::~LogToGstHandler() {}
45 :
46 7 : void LogToGstHandler::log(Level level, const std::string &file, int line, const std::string &function,
47 : const std::string &message)
48 : {
49 7 : std::string toReport;
50 7 : toReport += "M:" + file;
51 7 : toReport += " F:" + function;
52 7 : toReport += " L:" + std::to_string(line);
53 7 : toReport += " > " + message;
54 :
55 7 : switch (level)
56 : {
57 2 : case Level::Fatal:
58 : case Level::Error:
59 2 : GST_CAT_ERROR(kGstRialtoCategory, "%s", toReport.c_str());
60 2 : break;
61 :
62 1 : case Level::Warning:
63 1 : GST_CAT_WARNING(kGstRialtoCategory, "%s", toReport.c_str());
64 1 : break;
65 :
66 2 : case Level::Milestone:
67 : case Level::Info:
68 2 : GST_CAT_INFO(kGstRialtoCategory, "%s", toReport.c_str());
69 2 : break;
70 :
71 1 : case Level::Debug:
72 1 : GST_CAT_DEBUG(kGstRialtoCategory, "%s", toReport.c_str());
73 1 : break;
74 :
75 1 : case Level::External:
76 : default:
77 1 : GST_CAT_LOG(kGstRialtoCategory, "%s", toReport.c_str());
78 1 : break;
79 : }
80 7 : }
|