Keyple Util C++ Library 2.0.0
Reference Terminal Reader API for C++
Logger.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2021 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
13#include <cstdarg>
14
15#include "Logger.h"
16
17namespace keyple {
18namespace core {
19namespace util {
20namespace cpp {
21
23
24Logger::Logger(const std::string& className, std::mutex* mtx)
25: className(demangle(className.c_str())), mtx(mtx) {}
26
28{
29 return className;
30}
31
33{
34 mLevel = level;
35}
36
37const std::string Logger::getCurrentTimestamp()
38{
39 using std::chrono::system_clock;
40 auto currentTime = std::chrono::system_clock::now();
41 char buffer1[21];
42 char buffer2[25];
43
44 auto transformed = currentTime.time_since_epoch().count() / 1000000;
45 auto millis = transformed % 1000;
46
47 std::time_t tt;
48 tt = system_clock::to_time_t(currentTime);
49 auto timeinfo = localtime(&tt);
50
51 strftime(buffer1, sizeof(buffer1), "%F %H:%M:%S", timeinfo);
52 sprintf(buffer2, "%s:%03d", buffer1, (int)millis);
53
54 return std::string(buffer2);
55}
56
57}
58}
59}
60}
static void setLoggerLevel(Level level)
Definition: Logger.cpp:32
Logger(const std::string &className, std::mutex *mtx)
Definition: Logger.cpp:24