tools: add a logging tool

This commit is contained in:
Danny Robson 2019-10-10 15:11:02 +11:00
parent fa9f537e59
commit 5666a64e77
2 changed files with 43 additions and 1 deletions

View File

@ -605,7 +605,7 @@ endif ()
###############################################################################
foreach (tool cpuid poisson macro scratch)
foreach (tool cpuid log poisson macro scratch)
add_executable (util_${tool} tools/${tool}.cpp)
set_target_properties (util_${tool} PROPERTIES OUTPUT_NAME ${tool})
target_link_libraries (util_${tool} cruft)

42
tools/log.cpp Normal file
View File

@ -0,0 +1,42 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2019, Danny Robson <danny@nerdcruft.net>
*/
#include <cruft/util/log.hpp>
#include <iostream>
#include <cstdlib>
enum {
ARG_SELF,
ARG_LEVEL,
ARG_FORMAT,
MIN_ARGS,
};
int main (int const argc, char const **argv)
{
if (argc < MIN_ARGS) {
std::cerr << "usage: " << argv[ARG_SELF] << " <level> <format> [arg]...\n";
return EXIT_FAILURE;
}
auto const level = cruft::log::to_level (argv[ARG_LEVEL]);
auto const format = argv[ARG_FORMAT];
auto const count = argc - 3;
switch (count) {
case 0: cruft::log::write (level, format); break;
case 1: cruft::log::write (level, format, argv[MIN_ARGS + 0]); break;
case 2: cruft::log::write (level, format, argv[MIN_ARGS + 0], argv[MIN_ARGS + 1]); break;
}
return EXIT_SUCCESS;
}