diff --git a/CMakeLists.txt b/CMakeLists.txt index 5df0af84..7ab3a277 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/tools/log.cpp b/tools/log.cpp new file mode 100644 index 00000000..ec9760b0 --- /dev/null +++ b/tools/log.cpp @@ -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 + */ + +#include + +#include +#include + + +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] << " [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; +} \ No newline at end of file