MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / log_handler1_impl

Function log_handler1_impl

common/log.h:327–414  ·  view source on GitHub ↗

INTERNAL, DO NOT USE

Source from the content-addressed store, hash-verified

325
326// INTERNAL, DO NOT USE
327inline 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;

Callers 6

log_handler2_implFunction · 0.85
log_disable_implFunction · 0.85
log_enable_implFunction · 0.85
log_set_target_implFunction · 0.85
log_handlerFunction · 0.85
log_append_implFunction · 0.85

Calls 3

fprintfFunction · 0.85
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected