Skip to content
Snippets Groups Projects
Commit c5b95c2e authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[BL] Add Logging functions.

parent fcb6419f
No related branches found
No related tags found
No related merge requests found
/**
* \file
*
* \copyright
* Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "Logging.h"
#include <spdlog/sinks/stdout_color_sinks.h>
#include <map>
#include "Error.h"
namespace BaseLib
{
std::shared_ptr<spdlog::logger> console = spdlog::stdout_color_st("ogs");
void setConsoleLogLevel(std::string const& level_string)
{
using namespace spdlog::level;
std::map<std::string, level_enum> string_to_log_level = {
{"none", off}, {"critical", critical}, {"error", err}, {"warn", warn},
{"info", info}, {"debug", debug}, {"all", trace}};
auto const level = string_to_log_level.find(level_string);
if (level == string_to_log_level.end())
{
ERR("'{:s}' is not a valid log level!", level_string);
OGS_FATAL("Wrong log level string.");
}
console->set_level(level->second);
spdlog::set_default_logger(console);
}
} // namespace BaseLib
/**
* \file
*
* \copyright
* Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#pragma once
#include <spdlog/spdlog.h>
namespace BaseLib
{
extern std::shared_ptr<spdlog::logger> console;
void setConsoleLogLevel(std::string const& level_string);
} // namespace BaseLib
template <typename... Args>
void DBUG(char const* fmt, Args const&... args)
{
BaseLib::console->debug(fmt, args...);
}
template <typename... Args>
void INFO(char const* fmt, Args const&... args)
{
BaseLib::console->info(fmt, args...);
}
template <typename... Args>
void WARN(char const* fmt, Args const&... args)
{
BaseLib::console->warn(fmt, args...);
}
template <typename... Args>
void ERR(char const* fmt, Args const&... args)
{
BaseLib::console->error(fmt, args...);
}
template <typename... Args>
void CRITICAL(char const* fmt, Args const&... args)
{
BaseLib::console->critical(fmt, args...);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment