/** Logging. * * @file * @author Daniel Krebs * @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC * @license GNU General Public License (version 3) * * VILLAScommon * * 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 . *********************************************************************************/ #pragma once #include #define SPDLOG_FMT_EXTERNAL #include #include #include #include #include #include namespace villas { /* Forward declarations */ class Log; using Logger = std::shared_ptr; extern Log logging; class Log { public: using Level = spdlog::level::level_enum; using DefaultSink = std::shared_ptr; using DistSink = std::shared_ptr; protected: DistSink sinks; DefaultSink sink; Level level; std::string pattern; /**< Logging format. */ std::string prefix; /**< Prefix each line with this string. */ public: Log(Level level = Level::info); /**< 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); void setPattern(const std::string &pattern); void setLevel(Level lvl); void setLevel(const std::string &lvl); Level getLevel() const; std::string getLevelName() const; }; } // namespace villas