generated from tier4/ros2-project-template
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Max SCHMELLER <[email protected]>
- Loading branch information
Showing
20 changed files
with
1,307 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
"nproc", | ||
"nsec", | ||
"ntoa", | ||
"OVFL", | ||
"pandar", | ||
"PANDAR", | ||
"PANDARAT", | ||
|
55 changes: 55 additions & 0 deletions
55
nebula_common/include/nebula_common/loggers/console_logger.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include "nebula_common/loggers/logger.hpp" | ||
|
||
#include <cstdio> | ||
#include <iostream> | ||
#include <memory> | ||
#include <ostream> | ||
#include <string> | ||
#include <utility> | ||
|
||
namespace nebula::drivers::loggers | ||
{ | ||
|
||
class ConsoleLogger : public Logger | ||
{ | ||
public: | ||
explicit ConsoleLogger(std::string name) : name_(std::move(name)) {} | ||
|
||
void debug(const std::string & message) override { print_tagged(std::cout, "DEBUG", message); } | ||
void info(const std::string & message) override { print_tagged(std::cout, "INFO", message); } | ||
void warn(const std::string & message) override { print_tagged(std::cerr, "WARN", message); } | ||
void error(const std::string & message) override { print_tagged(std::cerr, "ERROR", message); } | ||
|
||
std::shared_ptr<Logger> child(const std::string & name) override | ||
{ | ||
return std::make_shared<ConsoleLogger>(name_ + "." + name); | ||
} | ||
|
||
private: | ||
std::string name_; | ||
|
||
void print_tagged(std::ostream & os, const std::string & severity, const std::string & message) | ||
{ | ||
// In multithreaded logging, building the string first (... + ...) and then shifting to the | ||
// stream will ensure that no other logger outputs between string fragments | ||
os << ("[" + name_ + "][" + severity + "] " + message) << std::endl; | ||
} | ||
}; | ||
|
||
} // namespace nebula::drivers::loggers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <sstream> | ||
#include <string> | ||
|
||
#define NEBULA_LOG_STREAM(log_func, stream_args) \ | ||
{ \ | ||
std::stringstream ss{}; \ | ||
ss << stream_args; \ | ||
log_func(ss.str()); \ | ||
} | ||
|
||
namespace nebula::drivers::loggers | ||
{ | ||
|
||
class Logger | ||
{ | ||
public: | ||
Logger() = default; | ||
Logger(const Logger &) = default; | ||
Logger(Logger &&) = delete; | ||
Logger & operator=(const Logger &) = default; | ||
Logger & operator=(Logger &&) = delete; | ||
virtual ~Logger() = default; | ||
|
||
virtual void debug(const std::string & message) = 0; | ||
virtual void info(const std::string & message) = 0; | ||
virtual void warn(const std::string & message) = 0; | ||
virtual void error(const std::string & message) = 0; | ||
|
||
virtual std::shared_ptr<Logger> child(const std::string & name) = 0; | ||
}; | ||
|
||
} // namespace nebula::drivers::loggers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#pragma once | ||
|
||
#include <exception> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <variant> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.