1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/common/include/villas/log.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2 KiB
C++
Raw Normal View History

2018-08-21 00:25:44 +02:00
/** Logging.
*
* @file
* @author Daniel Krebs <github@daniel-krebs.net>
2019-04-06 18:22:22 +02:00
* @author Steffen Vogel <post@steffenvogel.de>
2020-01-20 17:15:25 +01:00
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
2018-08-21 00:25:44 +02:00
* @license GNU General Public License (version 3)
*
* VILLAScommon
2018-08-21 00:25:44 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
#pragma once
#include <string>
#include <spdlog/spdlog.h>
2018-10-19 14:33:10 +02:00
#include <spdlog/sinks/dist_sink.h>
2019-01-23 02:49:44 +01:00
#include <spdlog/sinks/stdout_color_sinks.h>
2018-08-21 00:25:44 +02:00
#include <spdlog/fmt/ostr.h>
2018-10-19 14:33:10 +02:00
#include <jansson.h>
2018-08-21 00:25:44 +02:00
2018-10-19 14:33:10 +02:00
namespace villas {
2018-08-21 00:25:44 +02:00
2018-10-19 14:33:10 +02:00
/* Forward declarations */
class Log;
2018-08-21 00:25:44 +02:00
2018-10-19 14:33:10 +02:00
using Logger = std::shared_ptr<spdlog::logger>;
extern Log logging;
class Log {
public:
using Level = spdlog::level::level_enum;
2019-01-23 02:49:44 +01:00
using DefaultSink = std::shared_ptr<spdlog::sinks::stderr_color_sink_mt>;
2018-12-04 14:12:22 +01:00
using DistSink = std::shared_ptr<spdlog::sinks::dist_sink_mt>;
2018-10-19 14:33:10 +02:00
protected:
DistSink sinks;
2019-01-23 02:49:44 +01:00
DefaultSink sink;
2018-10-19 14:33:10 +02:00
Level level;
2018-10-19 14:33:10 +02:00
std::string pattern; /**< Logging format. */
std::string prefix; /**< Prefix each line with this string. */
public:
Log(Level level = Level::info);
2018-10-19 14:33:10 +02:00
/**< Get the real usable log output width which fits into one line. */
int getWidth();
void parse(json_t *cfg);
Logger get(const std::string &name);
2018-11-04 17:09:25 +01:00
void setPattern(const std::string &pattern);
2018-10-19 14:33:10 +02:00
void setLevel(Level lvl);
void setLevel(const std::string &lvl);
2018-11-01 14:30:32 +01:00
Level getLevel() const;
2018-12-02 02:50:55 +01:00
std::string getLevelName() const;
2018-10-19 14:33:10 +02:00
};
} /* namespace villas */