@@ -176,101 +176,101 @@ namespace InfoLogger
176176class InfoLogger ::Impl
177177{
178178 public:
179- Impl (const std::string & options)
179+ Impl (const std::string& options)
180180 {
181181 // initiate internal members
182182 magicTag = InfoLoggerMagicNumber;
183183 numberOfMessages = 0 ;
184184 currentStreamMessage.clear ();
185185 currentStreamOptions = undefinedMessageOption;
186186 client = nullptr ;
187-
187+
188188 floodReset ();
189189
190190 if (infoLog_proto_init ()) {
191191 throw __LINE__;
192192 }
193193 refreshDefaultMsg ();
194194
195- // option-processing routine
196- auto processOptions = [&] (std::string opt) {
195+ // option-processing routine
196+ auto processOptions = [&](std::string opt) {
197197 std::map<std::string, std::string> kv;
198198 if (getKeyValuePairsFromString (opt, kv)) {
199- throw __LINE__;
199+ throw __LINE__;
200200 }
201201 for (auto & it : kv) {
202- if (it.first == " outputMode" ) {
202+ if (it.first == " outputMode" ) {
203203 getOutputStreamFromString (it.second .c_str (), mainMode);
204- } else if (it.first == " outputModeFallback" ) {
204+ } else if (it.first == " outputModeFallback" ) {
205205 getOutputStreamFromString (it.second .c_str (), fallbackMode);
206- } else if (it.first == " verbose" ) {
206+ } else if (it.first == " verbose" ) {
207207 verbose = atoi (it.second .c_str ());
208- } else {
209- // unknown option
208+ } else {
209+ // unknown option
210210 // printf("Unknown option %s\n",it.second.c_str());
211211 throw __LINE__;
212- }
212+ }
213213 }
214214 return ;
215215 };
216-
216+
217217 // parse options from constructor arg
218218 processOptions (options);
219219
220- // parse options from environment
220+ // parse options from environment
221221 const char * confEnvOptions = getenv (" INFOLOGGER_OPTIONS" );
222222 if (confEnvOptions != NULL ) {
223- processOptions (confEnvOptions);
223+ processOptions (confEnvOptions);
224224 }
225225
226226 const char * confEnvMode = getenv (" INFOLOGGER_MODE" );
227227 if (confEnvMode != NULL ) {
228228 getOutputStreamFromString (confEnvMode, mainMode);
229229 }
230-
231- // init main output and fallbacks if needed
230+
231+ // init main output and fallbacks if needed
232232 currentMode = mainMode;
233- for (int it = 0 ; it < 3 ; it++) {
233+ for (int it = 0 ; it < 3 ; it++) {
234234 if (it == 0 ) {
235235 currentMode = mainMode;
236236 } else if (it == 1 ) {
237237 currentMode = fallbackMode;
238238 } else {
239239 currentMode.mode = OutputMode::none;
240- currentMode.path = " /dev/null" ;
240+ currentMode.path = " /dev/null" ;
241241 }
242242 if (verbose) {
243243 printf (" Using output mode %s\n " , getStringFromMode (currentMode.mode ));
244244 }
245-
245+
246246 if (currentMode.mode == OutputMode::file) {
247- if (verbose) {
248- printf (" Logging to file %s\n " , currentMode.path .c_str ());
249- }
250- if (stdLog.setLogFile (currentMode.path .c_str (),0 , 4 , 0 ) == 0 ) {
247+ if (verbose) {
248+ printf (" Logging to file %s\n " , currentMode.path .c_str ());
249+ }
250+ if (stdLog.setLogFile (currentMode.path .c_str (), 0 , 4 , 0 ) == 0 ) {
251251 break ;
252- }
252+ }
253253 } else if (currentMode.mode == OutputMode::stdout) {
254- if (stdLog.setLogFile (nullptr ) == 0 ) {
255- break ;
256- }
254+ if (stdLog.setLogFile (nullptr ) == 0 ) {
255+ break ;
256+ }
257257 } else if (currentMode.mode == OutputMode::none) {
258- if (stdLog.setLogFile (currentMode.path .c_str ()) == 0 ) {
258+ if (stdLog.setLogFile (currentMode.path .c_str ()) == 0 ) {
259259 break ;
260- }
260+ }
261261 } else if (currentMode.mode == OutputMode::infoLoggerD) {
262- client = new InfoLoggerClient;
263- if (client != nullptr ) {
262+ client = new InfoLoggerClient;
263+ if (client != nullptr ) {
264264 if (client->isOk ()) {
265- break ;
266- }
267- }
265+ break ;
266+ }
267+ }
268268 }
269269 if (verbose) {
270- printf (" Output to %s failed\n " , getStringFromMode (currentMode.mode ));
270+ printf (" Output to %s failed\n " , getStringFromMode (currentMode.mode ));
271271 }
272272 }
273-
273+
274274 // todo
275275 // switch mode based on configuration / environment
276276 // connect to client only on first message (or try again after timeout)
@@ -305,59 +305,61 @@ class InfoLogger::Impl
305305 none };
306306
307307 struct OutputStream {
308- OutputMode mode; // selected mode
308+ OutputMode mode; // selected mode
309309 std::string path; // optional path (eg for 'file' mode)
310310 };
311-
311+
312312 // convert a string to a member of the OutputMode enum
313313 // and sets filePath in case of the "file" mode
314314 // throw an integer error code on error
315- void getOutputStreamFromString (const char *s, OutputStream &out) {
315+ void getOutputStreamFromString (const char * s, OutputStream& out)
316+ {
316317 if (s == nullptr ) {
317318 throw __LINE__;
318319 }
319320 out.mode = OutputMode::none;
320321 out.path = " " ;
321- if (!strcmp (s," stdout" )) {
322+ if (!strcmp (s, " stdout" )) {
322323 out.mode = OutputMode::stdout;
323- } else if (!strncmp (s," file" , 4 )) {
324+ } else if (!strncmp (s, " file" , 4 )) {
324325 out.mode = OutputMode::file;
325326 if (s[4 ] == ' :' ) {
326327 out.path = std::string (&s[5 ]);
327328 } else {
328329 out.path = " ./log.txt" ;
329330 }
330- } else if (!strcmp (s," infoLoggerD" )) {
331+ } else if (!strcmp (s, " infoLoggerD" )) {
331332 out.mode = OutputMode::infoLoggerD;
332- } else if (!strcmp (s," raw" )) {
333+ } else if (!strcmp (s, " raw" )) {
333334 out.mode = OutputMode::raw;
334- } else if (!strcmp (s," none" )) {
335+ } else if (!strcmp (s, " none" )) {
335336 out.mode = OutputMode::none;
336337 } else {
337338 throw __LINE__;
338339 }
339340 return ;
340341 };
341-
342- const char * getStringFromMode (OutputMode m) {
343- if (m==OutputMode::stdout) {
342+
343+ const char * getStringFromMode (OutputMode m)
344+ {
345+ if (m == OutputMode::stdout) {
344346 return " stdout" ;
345- } else if (m== OutputMode::file) {
347+ } else if (m == OutputMode::file) {
346348 return " file" ;
347- } else if (m== OutputMode::infoLoggerD) {
349+ } else if (m == OutputMode::infoLoggerD) {
348350 return " infoLoggerD" ;
349- } else if (m== OutputMode::none) {
351+ } else if (m == OutputMode::none) {
350352 return " none" ;
351- }
353+ }
352354 return " unknown" ;
353355 }
354-
355- OutputStream currentMode; // current option for output
356- OutputStream mainMode = {OutputMode::infoLoggerD, " " }; // main output mode
357- OutputStream fallbackMode = {OutputMode::stdout, " " }; // in case main mode is not available
358-
356+
357+ OutputStream currentMode; // current option for output
358+ OutputStream mainMode = { OutputMode::infoLoggerD, " " }; // main output mode
359+ OutputStream fallbackMode = { OutputMode::stdout, " " }; // in case main mode is not available
360+
359361 bool verbose = 0 ; // in verbose mode, more info printed on stdout
360-
362+
361363 // / Log a message, with a list of arguments of type va_list.
362364 // / \param message NUL-terminated string message to push to the log system. It uses the same format as specified for printf(), and the function accepts additionnal formatting parameters.
363365 // / \param ap Variable list of arguments (c.f. vprintf)
@@ -729,7 +731,7 @@ InfoLogger::InfoLogger()
729731 }
730732}
731733
732- InfoLogger::InfoLogger (const std::string & options)
734+ InfoLogger::InfoLogger (const std::string& options)
733735{
734736 mPimpl = std::make_unique<InfoLogger::Impl>(options);
735737 if (mPimpl == NULL ) {
0 commit comments