Skip to content

Commit 0e54df7

Browse files
authored
Merge pull request #64 from sy-c/master
infologger_options
2 parents b8a8e0f + 7244681 commit 0e54df7

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

doc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ achieved on CentOS 7 with e.g. (as root):
279279
- outputMode: the main output mode of the library. As accepted by INFOLOGGER_MODE. Default: infoLoggerD.
280280
- outputModeFallback: the fallback output mode of the library. As accepted by INFOLOGGER_MODE. Default: stdout. The fallback mode is selected on initialization only (not later at runtime), if the main mode fails on first attempt.
281281
- verbose: 0 or 1. Default: 0. If 1, extra information is printed on stdout, e.g. to report the selected output.
282+
- floodProtection: 0 or 1. Default: 1. Enable(1)/disable(0) the message flood protection.
282283
283284
284285

doc/releaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,4 @@ This file describes the main feature changes for each InfoLogger released versio
8686

8787
## next version
8888
- added INFOLOGGER_MODE=debug. In this mode, infoLogger library prints on stdout one line per message, with a list of comma-separated field = value pairs. Undefined fields are not shown.
89+
- added INFOLOGGER_OPTIONS environment variable, which allows overriding some of the built-in client defaults: outputMode, outputModeFallback, verbose, floodProtection.

src/InfoLogger.cxx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,18 @@ class InfoLogger::Impl
199199
throw __LINE__;
200200
}
201201
for (auto& it : kv) {
202+
//printf("%s = %s\n",it.first.c_str(), it.second.c_str());
202203
if (it.first == "outputMode") {
203204
getOutputStreamFromString(it.second.c_str(), mainMode);
204205
} else if (it.first == "outputModeFallback") {
205206
getOutputStreamFromString(it.second.c_str(), fallbackMode);
206207
} else if (it.first == "verbose") {
207208
verbose = atoi(it.second.c_str());
208-
} else {
209+
} else if (it.first == "floodProtection") {
210+
flood_protection = atoi(it.second.c_str());
211+
} else {
209212
// unknown option
210-
// printf("Unknown option %s\n",it.second.c_str());
213+
printf("Unknown infoLogger option %s\n",it.first.c_str());
211214
throw __LINE__;
212215
}
213216
}
@@ -241,6 +244,9 @@ class InfoLogger::Impl
241244
}
242245
if (verbose) {
243246
printf("Using output mode %s\n", getStringFromMode(currentMode.mode));
247+
if (!flood_protection) {
248+
printf("Flood protection disabled\n");
249+
}
244250
}
245251

246252
if (currentMode.mode == OutputMode::file) {
@@ -410,7 +416,7 @@ class InfoLogger::Impl
410416

411417
// message flood prevention
412418
// constants
413-
const bool flood_protection = 1; // if set, flood protection mechanism enabled
419+
bool flood_protection = 1; // if set, flood protection mechanism enabled
414420
const unsigned int flood_maxmsg_sec=500; // maximum messages in one second to trigger flood
415421
const unsigned int flood_maxmsg_min=1000; // maximum messages in one minute to trigger flood
416422
const unsigned int flood_maxmsg_file=1000; // maximum number of messages in overflow log file

src/log.cxx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,20 @@ int main(int argc, char** argv)
202202
}
203203
}
204204

205-
InfoLogger theLog;
205+
std::unique_ptr<InfoLogger> theLog;
206+
try {
207+
theLog=std::make_unique<InfoLogger>();
208+
}
209+
catch(int err) {
210+
printf("Failed to initialize infoLogger: exception %d\n",err);
211+
return -1;
212+
}
213+
206214

207215
// additionnal args = messages to send
208216
int i;
209217
for (i = optind; i < argc; i++) {
210-
theLog.log(msgOptions, msgContext, "%s", argv[i]);
218+
theLog->log(msgOptions, msgContext, "%s", argv[i]);
211219
}
212220

213221
// todo: catch exceptions
@@ -227,7 +235,7 @@ int main(int argc, char** argv)
227235
break;
228236
}
229237
//infoLogger_msg_xt(UNDEFINED_STRING,UNDEFINED_INT,UNDEFINED_INT,facility,severity,level,msg);
230-
theLog.log(msgOptions, msgContext, "%s", msg.c_str());
238+
theLog->log(msgOptions, msgContext, "%s", msg.c_str());
231239
}
232240
if (eof)
233241
break;

0 commit comments

Comments
 (0)