debug messages to log file

This commit is contained in:
2021-09-12 00:35:36 +02:00
parent 4d8ab68b81
commit 09abf3e122

View File

@@ -42,7 +42,7 @@ namespace po = boost::program_options;
typedef vector< string > split_vector_type; typedef vector< string > split_vector_type;
static void init_log(void) static void init_log(bool debug = false)
{ {
/* init boost log /* init boost log
* 1. Add common attributes * 1. Add common attributes
@@ -89,6 +89,10 @@ static void init_log(void)
boost::log::keywords::min_free_space = 30 * 1024 * 1024, boost::log::keywords::min_free_space = 30 * 1024 * 1024,
boost::log::keywords::open_mode = std::ios_base::app); boost::log::keywords::open_mode = std::ios_base::app);
fsSink->set_formatter(logFmt); fsSink->set_formatter(logFmt);
if (!debug)
fsSink->set_filter(
boost::log::trivial::severity >= boost::log::trivial::warning
);
fsSink->locked_backend()->auto_flush(true); fsSink->locked_backend()->auto_flush(true);
} }
@@ -110,12 +114,11 @@ int main(int argc, char* argv[])
std::string port,path,filename; std::string port,path,filename;
int speed; int speed;
init_log();
po::options_description desc("Allowed options"); po::options_description desc("Allowed options");
desc.add_options() desc.add_options()
("help", "produce help message") ("help", "produce help message")
("measure", "get and print values") ("measure", "get and print values")
("debug", "debug output to file")
("verbose", po::value<string>()->implicit_value("0"), "verbosity level") ("verbose", po::value<string>()->implicit_value("0"), "verbosity level")
("file", po::value<string>(&filename)->default_value("camera.jpg"),"filename of capture filename") ("file", po::value<string>(&filename)->default_value("camera.jpg"),"filename of capture filename")
("path", po::value<string>(&path)->default_value("/tmp"),"directory for file of capture") ("path", po::value<string>(&path)->default_value("/tmp"),"directory for file of capture")
@@ -138,7 +141,9 @@ int main(int argc, char* argv[])
cout << desc << "\n"; cout << desc << "\n";
return 0; return 0;
} }
init_log(vm.count("debug"));
} catch(std::exception& e) { } catch(std::exception& e) {
cerr << "error: " << e.what() << "\n"; cerr << "error: " << e.what() << "\n";
return 1; return 1;