Add file logger and fix log level output
Some checks failed
Build ptprnt / build (push) Failing after 38s
Some checks failed
Build ptprnt / build (push) Failing after 38s
This commit is contained in:
@@ -16,14 +16,25 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
|
||||||
|
#define SPDLOG_DEBUG_ON
|
||||||
|
#define SPDLOG_TRACE_ON
|
||||||
|
|
||||||
#include "PtouchPrint.hpp"
|
#include "PtouchPrint.hpp"
|
||||||
|
|
||||||
#include <CLI/App.hpp>
|
#include <CLI/App.hpp>
|
||||||
|
#include <fmt/core.h>
|
||||||
#include <spdlog/common.h>
|
#include <spdlog/common.h>
|
||||||
|
#include <spdlog/details/synchronous_factory.h>
|
||||||
|
#include <spdlog/logger.h>
|
||||||
|
#include <spdlog/sinks/base_sink.h>
|
||||||
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "CLI/Option.hpp"
|
#include "CLI/Option.hpp"
|
||||||
#include "P700Printer.hpp"
|
#include "P700Printer.hpp"
|
||||||
@@ -45,9 +56,9 @@ int PtouchPrint::init(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mVerboseFlag) {
|
if (mVerboseFlag) {
|
||||||
setupLogger(spdlog::level::trace);
|
setupLogger(spdlog::level::debug);
|
||||||
} else {
|
} else {
|
||||||
setupLogger(spdlog::level::critical);
|
setupLogger(spdlog::level::err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mUsbDeviceFactory.init()) {
|
if (!mUsbDeviceFactory.init()) {
|
||||||
@@ -59,10 +70,12 @@ int PtouchPrint::init(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int PtouchPrint::run() {
|
int PtouchPrint::run() {
|
||||||
|
spdlog::debug("ptprnt version {}", mVersionString);
|
||||||
|
SPDLOG_TRACE("testing trace");
|
||||||
auto numFoundPrinters = getCompatiblePrinters();
|
auto numFoundPrinters = getCompatiblePrinters();
|
||||||
if (numFoundPrinters == 0) {
|
if (numFoundPrinters == 0) {
|
||||||
spdlog::error(
|
spdlog::error(
|
||||||
"No compatible printers found, please make sure if they are turned on and connected");
|
"No compatible printers found, please make sure that they are turned on and connected");
|
||||||
return -1;
|
return -1;
|
||||||
} else if (numFoundPrinters > 1) {
|
} else if (numFoundPrinters > 1) {
|
||||||
spdlog::warn("Found more than one compatible printer. Currently not supported.");
|
spdlog::warn("Found more than one compatible printer. Currently not supported.");
|
||||||
@@ -84,7 +97,7 @@ int PtouchPrint::run() {
|
|||||||
//printer->printText("wurst", 1);
|
//printer->printText("wurst", 1);
|
||||||
|
|
||||||
for (auto& cmd : mCommands) {
|
for (auto& cmd : mCommands) {
|
||||||
std::cout << cmd.second << std::endl;
|
spdlog::debug("Command: {}", cmd.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -113,13 +126,22 @@ unsigned int PtouchPrint::getCompatiblePrinters() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
void PtouchPrint::setupLogger(spdlog::level::level_enum lvl) {
|
||||||
spdlog::set_level(lvl);
|
auto consoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||||
spdlog::debug("Starting ptprnt {}", mVersionString);
|
consoleSink->set_level(lvl);
|
||||||
|
consoleSink->set_pattern("%^%L:%$ %v");
|
||||||
|
|
||||||
|
auto fileSink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("ptprnt.log", true);
|
||||||
|
fileSink->set_level(spdlog::level::trace);
|
||||||
|
fileSink->set_pattern("%Y-%m-%d %H:%m:%S:%e [pid:%P tid:%t] [%^%l%$] %v (%@)");
|
||||||
|
std::vector<spdlog::sink_ptr> sinks{consoleSink, fileSink};
|
||||||
|
auto logger = std::make_shared<spdlog::logger>("default_logger", sinks.begin(), sinks.end());
|
||||||
|
logger->set_level(spdlog::level::trace);
|
||||||
|
spdlog::set_default_logger(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PtouchPrint::setupCliParser() {
|
void PtouchPrint::setupCliParser() {
|
||||||
auto printVersion = [this](std::size_t) {
|
auto printVersion = [this](std::size_t) {
|
||||||
std::cout << "ptprnt version: " << mVersionString << std::endl;
|
fmt::println("ptprnt version: {}", mVersionString);
|
||||||
};
|
};
|
||||||
|
|
||||||
// General options
|
// General options
|
||||||
|
Reference in New Issue
Block a user