Skip to content

Commit

Permalink
Added init for boost logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
carsten0x51h committed Feb 29, 2024
1 parent 9898008 commit d5c42a6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 2 additions & 0 deletions source/indi-device-watchdog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set(sources
enum_helper.h
device_data.h
device_data.cpp
logging.h
logging.cpp
device_data_persistance.h
device_data_persistance.cpp
indi_driver_restart_manager.h
Expand Down
6 changes: 3 additions & 3 deletions source/indi-device-watchdog/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
****************************************************************************/

#include "include/logging.h"
#include "logging.h"

void LoggingT::init(const logging::trivial::severity_level &inLogSev, bool inWantConsoleLog, bool inWantLogFile) {
if (inWantConsoleLog) {
Expand All @@ -36,12 +36,12 @@ void LoggingT::init(const logging::trivial::severity_level &inLogSev, bool inWan
if (inWantLogFile) {
logging::add_file_log
(
keywords::file_name = "sample_%N.log", // file name pattern
keywords::file_name = "indi_device_watchdog_%N.log", // file name pattern
keywords::rotation_size =
10 * 1024 * 1024, // rotate files every 10 MiB...
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0,
0), // ...or at midnight
keywords::format = "[%TimeStamp%]: %Message%", // log record format
keywords::format = "[%TimeStamp%]: %Message%", // log record format
keywords::auto_flush = true
);
}
Expand Down
6 changes: 3 additions & 3 deletions source/indi-device-watchdog/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*
****************************************************************************/

#ifndef SOURCE_FOCUS_FINDER_COMMON_INCLUDE_LOGGING_H_
#define SOURCE_FOCUS_FINDER_COMMON_INCLUDE_LOGGING_H_
#ifndef SOURCE_INDI_DEVICE_WATCHDOG_INCLUDE_LOGGING_H_
#define SOURCE_INDI_DEVICE_WATCHDOG_INCLUDE_LOGGING_H_ SOURCE_INDI_DEVICE_WATCHDOG_INCLUDE_LOGGING_H_

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
Expand Down Expand Up @@ -73,4 +73,4 @@ class LoggingT {
};


#endif /* SOURCE_FOCUS_FINDER_COMMON_INCLUDE_LOGGING_H_ */
#endif /* SOURCE_INDI_DEVICE_WATCHDOG_INCLUDE_LOGGING_H_ */
13 changes: 10 additions & 3 deletions source/indi-device-watchdog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "indi_device_watchdog/indi_device_watchdog-version.h"
#include "indi_device_watchdog.h"
#include "device_data_persistance.h"
#include "logging.h"

std::string composeStartupMessage() {
std::stringstream ss;
Expand All @@ -48,9 +49,7 @@ std::string composeStartupMessage() {
int main(int argc, char *argv[]) {

using namespace boost::program_options;
namespace fs = std::filesystem;

std::cout << composeStartupMessage() << std::endl;
namespace fs = std::filesystem;

// Declare the supported options.
options_description options("Astrobox control options");
Expand All @@ -76,6 +75,14 @@ int main(int argc, char *argv[]) {
}


// TODO: Pass in log-level via cmdline
logging::trivial::severity_level sev = logging::trivial::debug;
LoggingT::init(sev, true /*console*/, true /*log file*/);


LOG(info) << composeStartupMessage() << std::endl;


fs::path currentPath = fs::current_path();
fs::path configFilename = vm["config"].as<std::string>();
fs::path fullPath = currentPath / configFilename;
Expand Down

0 comments on commit d5c42a6

Please sign in to comment.