INTERNAL, DO NOT USE
| 325 | |
| 326 | // INTERNAL, DO NOT USE |
| 327 | inline FILE *log_handler1_impl(bool change = false, LogTriState append = LogTriStateSame, LogTriState disable = LogTriStateSame, const std::string & filename = LOG_DEFAULT_FILE_NAME, FILE *target = nullptr) |
| 328 | { |
| 329 | static bool _initialized = false; |
| 330 | static bool _append = false; |
| 331 | static bool _disabled = filename.empty() && target == nullptr; |
| 332 | static std::string log_current_filename{filename}; |
| 333 | static FILE *log_current_target{target}; |
| 334 | static FILE *logfile = nullptr; |
| 335 | |
| 336 | if (change) |
| 337 | { |
| 338 | if (append != LogTriStateSame) |
| 339 | { |
| 340 | _append = append == LogTriStateTrue; |
| 341 | return logfile; |
| 342 | } |
| 343 | |
| 344 | if (disable == LogTriStateTrue) |
| 345 | { |
| 346 | // Disable primary target |
| 347 | _disabled = true; |
| 348 | } |
| 349 | // If previously disabled, only enable, and keep previous target |
| 350 | else if (disable == LogTriStateFalse) |
| 351 | { |
| 352 | _disabled = false; |
| 353 | } |
| 354 | // Otherwise, process the arguments |
| 355 | else if (log_current_filename != filename || log_current_target != target) |
| 356 | { |
| 357 | _initialized = false; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | if (_disabled) |
| 362 | { |
| 363 | // Log is disabled |
| 364 | return nullptr; |
| 365 | } |
| 366 | |
| 367 | if (_initialized) |
| 368 | { |
| 369 | // with fallback in case something went wrong |
| 370 | return logfile ? logfile : stderr; |
| 371 | } |
| 372 | |
| 373 | // do the (re)initialization |
| 374 | if (target != nullptr) |
| 375 | { |
| 376 | if (logfile != nullptr && logfile != stdout && logfile != stderr) |
| 377 | { |
| 378 | fclose(logfile); |
| 379 | } |
| 380 | |
| 381 | log_current_filename = LOG_DEFAULT_FILE_NAME; |
| 382 | log_current_target = target; |
| 383 | |
| 384 | logfile = target; |
no test coverage detected