MSCEqF
1.0
Multi State Constraint Equivariant Filter for visual inertial navigation
Toggle main menu visibility
Loading...
Searching...
No Matches
logger.hpp
1
// Copyright (C) 2023 Alessandro Fornasier.
2
// Control of Networked Systems, University of Klagenfurt, Austria.
3
//
4
// All rights reserved.
5
//
6
// This software is licensed under the terms of the Apache License, Version 2.0
7
// (the "License"); you may not use this file except in compliance with the
8
// License. You may obtain a copy of the License at
9
//
10
// http://www.apache.org/licenses/LICENSE-2.0
11
//
12
// Unless required by applicable law or agreed to in writing, software
13
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
// License for the specific language governing permissions and limitations
16
// under the License.
17
//
18
// You can contact the authors at <alessandro.fornasier@ieee.org>
19
20
#ifndef LOGGER_HPP_
21
#define LOGGER_HPP_
22
23
#include <iostream>
24
#include <memory>
25
26
namespace
utils
27
{
28
template
<
class
S,
class
C,
typename
=
void
>
29
struct
is_streamable
: ::std::false_type
30
{
31
};
32
33
template
<
class
S,
class
C>
34
struct
is_streamable
<S, C, decltype(void(std::declval<S&>() << std::declval<C const&>()))> : ::std::true_type
35
{
36
};
37
38
enum class
LoggerLevel
39
{
40
FULL,
41
INFO,
42
WARN,
43
ERR,
44
INACTIVE,
45
};
46
51
class
Logger
52
{
53
public
:
59
static
const
LoggerLevel&
getlevel
() {
return
level_; }
60
66
static
void
setLevel
(
const
LoggerLevel& level) { level_ = level; }
67
74
template
<
typename
T>
75
static
void
info
(
const
T& msg)
76
{
77
static_assert
(
is_streamable<std::ostream, T>::value
);
78
if
(level_ == LoggerLevel::INFO || level_ == LoggerLevel::FULL)
79
{
80
std::cout <<
"[ INFO]: "
<< msg <<
'.'
<< std::endl;
81
}
82
}
83
90
template
<
typename
T>
91
static
void
err
(
const
T& msg)
92
{
93
static_assert
(
is_streamable<std::ostream, T>::value
);
94
if
(level_ == LoggerLevel::INFO || level_ == LoggerLevel::WARN || level_ == LoggerLevel::ERR ||
95
level_ == LoggerLevel::FULL)
96
{
97
std::cout <<
"\033[31m[ ERROR]: "
<< msg <<
".\033[0m"
<< std::endl;
98
}
99
}
100
107
template
<
typename
T>
108
static
void
warn
(
const
T& msg)
109
{
110
static_assert
(
is_streamable<std::ostream, T>::value
);
111
if
(level_ == LoggerLevel::INFO || level_ == LoggerLevel::WARN || level_ == LoggerLevel::FULL)
112
{
113
std::cout <<
"\033[33m[ WARNING]: "
<< msg <<
".\033[0m"
<< std::endl;
114
}
115
}
116
123
template
<
typename
T>
124
static
void
debug
(
const
T& msg)
125
{
126
static_assert
(
is_streamable<std::ostream, T>::value
);
127
if
(level_ == LoggerLevel::FULL)
128
{
129
std::cout <<
"\033[34m[ DEBUG]: "
<< msg <<
".\033[0m"
<< std::endl;
130
}
131
}
132
133
private
:
134
static
inline
LoggerLevel level_ = LoggerLevel::INFO;
135
};
136
137
}
// namespace utils
138
139
#endif
// LOGGER_HPP_
utils::Logger
Logger.
Definition
logger.hpp:52
utils::Logger::warn
static void warn(const T &msg)
Format a warn message and log it in yellow.
Definition
logger.hpp:108
utils::Logger::getlevel
static const LoggerLevel & getlevel()
Get the logger level (see LoggerLevel).
Definition
logger.hpp:59
utils::Logger::debug
static void debug(const T &msg)
Format a debug message and log it in blue.
Definition
logger.hpp:124
utils::Logger::err
static void err(const T &msg)
Format a error message and log it in red.
Definition
logger.hpp:91
utils::Logger::info
static void info(const T &msg)
Format a info message and log it in white.
Definition
logger.hpp:75
utils::Logger::setLevel
static void setLevel(const LoggerLevel &level)
Set the logger level (see LoggerLevel).
Definition
logger.hpp:66
utils::is_streamable
Definition
logger.hpp:30
include
utils
logger.hpp
Generated by
1.17.0