Set the debug level in the command line.
[ruwai.git] / software / c++ / ruwai / src / ruwai_record.cpp
blob7d3c7188027e71de950949fc8eca141be04d0548
1 /*--------------------------------------------------------------------------*/
2 // LICENSE
3 //
4 // This file is part of ruwai.
5 //
6 // If you use ruwai_parser in any program or publication, please inform and
7 // acknowledge its author Stefan Mertl (stefan@mertl-research.at).
8 //
9 // ruwai is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 /*--------------------------------------------------------------------------*/
22 #include "root.h"
25 int main(int argc, char* argv[])
27 std::string config_file = "";
28 std::string debug_level = "";
29 if((argc != 2) && (argc != 3))
31 std::cout << "usage: " << argv[0] << " CONFIG_FILENAME [LOG_LEVEL]" << std::endl;
32 return(EXIT_SUCCESS);
34 else if(argc == 2)
36 config_file = (std::string)argv[1];
37 debug_level = "notice";
39 else if(argc == 3)
41 config_file = (std::string)argv[1];
42 debug_level = (std::string)argv[2];
45 int log_level = LOG_NOTICE;
46 if(debug_level == "emerg")
48 log_level = LOG_EMERG;
50 else if(debug_level == "alert")
52 log_level = LOG_ALERT;
54 else if(debug_level == "crit")
56 log_level = LOG_CRIT;
58 else if(debug_level == "err")
60 log_level = LOG_ERR;
62 else if(debug_level == "warning")
64 log_level = LOG_WARNING;
66 else if(debug_level == "notice")
68 log_level = LOG_NOTICE;
70 else if(debug_level == "info")
72 log_level = LOG_INFO;
74 else if(debug_level == "debug")
76 log_level = LOG_DEBUG;
79 setlogmask(LOG_UPTO(log_level));
80 openlog("ruwai_record", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
81 syslog(LOG_NOTICE, "Starting ruwai_record.");
83 Root root = Root(config_file);
85 // TODO: Check and mount the SD card.
86 syslog(LOG_NOTICE, "Initial check for the SD card.");
87 if (root.is_sd_dev_available())
89 if (!root.is_sd_mounted())
91 syslog(LOG_NOTICE, "Mounting the SD card....");
92 // Try to mount the SD card.
93 if(!root.mount_sd())
95 syslog(LOG_ERR, "Couldn't mount the SD card. No place to write the data to.");
100 syslog(LOG_NOTICE, "Starting the root...");
101 if (root.ready())
103 root.run();
105 else
107 syslog(LOG_NOTICE, "The root is not ready. Can't start it. Good bye.");
110 syslog(LOG_NOTICE, "Exiting ruwai_record.");
111 closelog();
112 return(EXIT_SUCCESS);