Commit 326f4e30 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Add an option for storing urd logs to a file

Added a new 'log_file' option to urd's configuration file that instructs
it to save all log messages to the configured file. As of now, this
option is only honored if 'use_syslog' is set to false.

This commit closes #4.
parent b95f7005
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -3,9 +3,12 @@
## global service settings
global_settings: [

  # dump log messages to syslog
  # if true, dump log messages to syslog
  use_syslog: false,

  # log file
  log_file: "@localstatedir@/urd.log",

  # path to globally-accessible socket
  global_socket: "@localstatedir@/global.socket.2",

+2 −0
Original line number Diff line number Diff line
@@ -218,6 +218,8 @@ config/defaults.cpp: Makefile
	   echo "    const char* progname           = \"urd\";"; \
	   echo "    const bool  daemonize          = true;"; \
	   echo "    const bool  use_syslog         = false;"; \
	   echo "    const bfs::path log_file = boost::filesystem::path();"; \
	   echo "    const uint32_t log_file_max_size = static_cast<uint32_t>(16*1024*1024);"; \
	   echo ""; \
\
	   echo "    const bool dry_run             = false;"; \
+10 −0
Original line number Diff line number Diff line
@@ -58,6 +58,16 @@ const file_schema valid_options = declare_file({
                    opt_type::mandatory, 
                    converter<bool>(parsers::parse_bool)), 

            declare_option<bfs::path>(
                    keywords::log_file,
                    opt_type::optional,
                    converter<bfs::path>(parsers::parse_path)), 

            declare_option<uint32_t>(
                    keywords::log_file_max_size,
                    opt_type::optional,
                    converter<uint32_t>(parsers::parse_capacity)),

            declare_option<bool>(
                    keywords::dry_run, 
                    opt_type::optional, 
+5 −0
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@

#include <cstdint>
#include <netinet/in.h>
#include <boost/filesystem.hpp>

namespace bfs = boost::filesystem;

namespace norns {
namespace config {
@@ -38,6 +41,8 @@ namespace defaults {
    extern const char*      progname;
    extern const bool       daemonize;
    extern const bool       use_syslog;
    extern const bfs::path  log_file;
    extern const uint32_t   log_file_max_size;
    extern const bool       dry_run;
    extern const char*      global_socket;
    extern const char*      control_socket;
+4 −0
Original line number Diff line number Diff line
@@ -68,6 +68,10 @@ struct option_value {
 * can be accessed using the usual std::map interface. */
struct options_group : public std::map<std::string, option_value> {

    bool has(const std::string& opt_name) const {
        return count(opt_name) != 0;
    }

    /*! If the options_group contains an option named 'opt_name'
     * of type T, returns the value for that option. 
     * If the option does not exist, throws std::invalid_argument exception.
Loading