Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2026 BMW AG
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 : #include "Logger.h"
11 :
12 : #include <chrono>
13 : #include <iomanip>
14 :
15 : namespace simulation
16 : {
17 :
18 : std::mutex Logger::logMutex_;
19 :
20 99 : void Logger::writeLog(std::string const& logLine)
21 : {
22 99 : std::lock_guard<std::mutex> lock(logMutex_);
23 99 : std::cout << logLine << std::endl;
24 99 : }
25 :
26 86 : std::string Logger::getTimestamp()
27 : {
28 86 : std::time_t now = std::time(nullptr);
29 86 : std::tm tm{};
30 86 : localtime_r(&now, &tm);
31 86 : std::ostringstream oss;
32 86 : oss << "[" << std::put_time(&tm, "%T") << "] ";
33 172 : return oss.str();
34 86 : }
35 :
36 86 : std::string Logger::getClusterId(uint8_t const id)
37 : {
38 86 : std::ostringstream oss;
39 86 : oss << "[Cluster" << static_cast<int>(id) << "] ";
40 172 : return oss.str();
41 86 : }
42 :
43 : } // namespace simulation
|