Skip to content

Commit cd643e7

Browse files
committed
added logRotate options for log file
1 parent 31f71c2 commit cd643e7

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

include/Common/Daemon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class DaemonConfigParameters {
1818
std::string userName; // user name under which should run the process. Not changed if empty.
1919
int redirectOutput=0; // flag set to redirect stdout/stderr to /dev/null
2020
std::string logFile; // log file (leave empty to keep stdout/stderr)
21+
int logRotateMaxBytes=0; // log file max size (0: unlimited)
22+
int logRotateMaxFiles=0; // log file max number of files kept (0:unlimited)
23+
int logRotateNow=0; // log file rotate now (0: append current, 1: create new)
2124
};
2225

2326

src/Daemon.cxx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ Daemon::Daemon(int argc, char * argv[], DaemonConfigParameters *dConfigParams) {
107107
params.redirectOutput=std::stoi(value);;
108108
} else if (key=="logFile") {
109109
params.logFile=value;
110+
} else if (key=="logRotateMaxBytes") {
111+
params.logRotateMaxBytes=std::stoi(value);
112+
} else if (key=="logRotateMaxFiles") {
113+
params.logRotateMaxFiles=std::stoi(value);
114+
} else if (key=="logRotateNow") {
115+
params.logRotateNow=std::stoi(value);
110116
} else {
111117
log.error("Unkown option key %s in option %s",key.c_str(),optarg);
112118
throw __LINE__;
@@ -129,11 +135,14 @@ Daemon::Daemon(int argc, char * argv[], DaemonConfigParameters *dConfigParams) {
129135
config.getOptionalValue<std::string>(cfgEntryPoint + ".userName", params.userName);
130136
config.getOptionalValue<int>(cfgEntryPoint + ".redirectOutput", params.redirectOutput);
131137
config.getOptionalValue<std::string>(cfgEntryPoint + ".logFile", params.logFile);
132-
138+
config.getOptionalValue<int>(cfgEntryPoint + ".logRotateMaxBytes", params.logRotateMaxBytes);
139+
config.getOptionalValue<int>(cfgEntryPoint + ".logRotateMaxFiles", params.logRotateMaxFiles);
140+
config.getOptionalValue<int>(cfgEntryPoint + ".logRotateNow", params.logRotateNow);
133141

134142
// open log file, if configured
135143
if (params.logFile.length()>0) {
136-
log.setLogFile(params.logFile.c_str());
144+
log.setLogFile(params.logFile.c_str(),
145+
params.logRotateMaxBytes, params.logRotateMaxFiles, params.logRotateNow);
137146
}
138147

139148
// become a daemon, if configured to do so

0 commit comments

Comments
 (0)