blob: 62d4e9e682aedfefdbb0d0053bb4a27db577f5e9 [file] [log] [blame]
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -05001#include "logger.hpp"
2
3#include <sstream>
4
5namespace vpd
6{
Sunny Srivastava5779d972025-08-08 01:45:23 -05007std::shared_ptr<Logger> Logger::m_loggerInstance;
8
9void Logger::logMessage(std::string_view i_message,
10 const PlaceHolder& i_placeHolder,
11 const types::PelInfoTuple* i_pelTuple,
12 const std::source_location& i_location)
13{
14 std::ostringstream l_log;
15 l_log << "FileName: " << i_location.file_name() << ","
16 << " Line: " << i_location.line() << " " << i_message;
17
18 if (i_placeHolder == PlaceHolder::COLLECTION)
19 {
20 // Log it to a specific place.
21 m_logFileHandler->writeLogToFile(i_placeHolder);
22 }
23 else if (i_placeHolder == PlaceHolder::PEL)
24 {
25 if (i_pelTuple)
26 {
27 // LOG PEL
28 // This should call create PEL API from the event logger.
29 return;
30 }
31 std::cout << "Pel info tuple required to log PEL for message <" +
32 l_log.str() + ">"
33 << std::endl;
34 }
35 else
36 {
37 // Default case, let it go to journal.
38 std::cout << l_log.str() << std::endl;
39 }
40}
41
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050042namespace logging
43{
44void logMessage(std::string_view message, const std::source_location& location)
45{
46 std::ostringstream log;
47 log << "FileName: " << location.file_name() << ","
48 << " Line: " << location.line() << " " << message;
49
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050050 std::cout << log.str() << std::endl;
51}
52} // namespace logging
53} // namespace vpd