uvgVPCCenc 1.0.0
uvgVPCCenc is an open-source real-time V-PCC encoder library written in C++ from scratch.
Loading...
Searching...
No Matches
log.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 * This file is part of uvgVPCCenc V-PCC encoder.
3 *
4 * Copyright (c) 2024, Tampere University, ITU/ISO/IEC, project contributors
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice, this
14 * list of conditions and the following disclaimer in the documentation and/or
15 * other materials provided with the distribution.
16 *
17 * * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
31 ****************************************************************************/
32
33#pragma once
34
36
37#include <chrono>
38#include <cstdarg>
39#include <iomanip>
40#include <iostream>
41#include <string>
42
43namespace uvgvpcc_enc {
45
46// stringify table for LogLevel
47static const std::string LogLevelStr[] = {"FATAL", "ERROR", "WARNING", "INFO", "PROFILING", "TRACE", "DEBUG"};
48
49constexpr bool errorsAreFatalDefaultValue = true;
51
52class Logger {
53 public:
54 static void setLogLevel(const LogLevel& level);
55 static void setErrorsAreFatal(const bool& isFatal);
56 static LogLevel getLogLevel();
57
58 static void log(LogLevel level, const std::string& context, const std::string& message);
59 static std::string printfStrToStdStr(const char* fmt, ...);
60 static std::string vprintfStrToStdStr(const char* fmt, va_list args);
61
62 private:
63 static LogLevel logLevel;
64 static bool errorsAreFatal_;
65};
66
67class Timer {
68 public:
69 Timer() : start(std::chrono::steady_clock::now()) {}
70
71 // Function to get elapsed time since the start of the program
72 double elapsed() const {
73 return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - start).count() / 1000000.0;
74 }
75 std::string elapsed_str() const {
76 std::ostringstream oss;
77 oss << std::fixed << std::setprecision(6) << elapsed();
78 return oss.str();
79 }
80
81 private:
82 std::chrono::time_point<std::chrono::steady_clock> start;
83};
84
85static Timer global_timer;
86
87} // namespace uvgvpcc_enc
Definition log.hpp:52
static LogLevel getLogLevel()
Definition log.cpp:82
static void setErrorsAreFatal(const bool &isFatal)
Definition log.cpp:81
static std::string vprintfStrToStdStr(const char *fmt, va_list args)
Definition log.cpp:131
static std::string printfStrToStdStr(const char *fmt,...)
Definition log.cpp:116
static void log(LogLevel level, const std::string &context, const std::string &message)
Definition log.cpp:84
static void setLogLevel(const LogLevel &level)
Definition log.cpp:80
Definition log.hpp:67
std::string elapsed_str() const
Definition log.hpp:75
double elapsed() const
Definition log.hpp:72
Timer()
Definition log.hpp:69
Definition log.hpp:43
constexpr LogLevel logLevelDefaultValue
Definition log.hpp:50
constexpr bool errorsAreFatalDefaultValue
Definition log.hpp:49
LogLevel
Definition log.hpp:44