Fray Engine
Loading...
Searching...
No Matches
fray::log Namespace Reference

Classes

class  EngineLogSink
 Captures Engine logs before managers exist and forwards them once attached. Construct before startup logging. The attachment must be destroyed before its managers. More...
class  ProjectScope
 Temporarily tag log lines on the calling thread, then restore its previous tag. Construct and destroy the scope on the same thread. More...
class  SinkSuppression
 Keeps the calling thread's printed lines out of the sink while it lives, then restores the previous setting. Used for lines that are recorded elsewhere under their own identity. Construct and destroy on the same thread. More...
class  ConsoleSuppression
 Keeps lines in the persistent log but out of the Console for this thread's scope. More...

Typedefs

using TimestampBuffer = F_char[TIMESTAMP_SIZE]
 Timestamp buffer type.
using dateBuffer = F_char[DATE_SIZE]
 Date buffer type.
using timeBuffer = F_char[TIME_SIZE]
 Time buffer type.
using Sink = std::function<void(const F_char *PID, const F_char *level, F_long thread, const std::string &project, const F_char *message, bool consoleVisible)>
 Receives each printed line synchronously on the logging thread; it must not log. The sink runs without the output or sink mutex held; concurrent calls may overlap.

Functions

F_void generateTimestamp (F_char *timestamp, std::chrono::system_clock::time_point now=std::chrono::system_clock::now())
 Write "[HH:MM:SS:mmm] [YY.MM.DD]" into buffer.
F_void getDate (F_char *date)
 Write "YY.MM.DD" into buffer.
F_void getTime (F_char *time, std::chrono::system_clock::time_point now=std::chrono::system_clock::now())
 Write "HH:MM:SS.mmm" into buffer.
F_long threadId ()
 Small sequential id for the calling thread, assigned on its first call (the first caller is 0).
std::mutex & sinkMutex ()
 Return the mutex protecting access to the shared sink slot.
std::shared_ptr< Sink > & sinkSlot ()
 Return the shared sink slot; callers must hold sinkMutex when accessing it.
F_void setSink (Sink sink)
 Replace the sink; an empty function removes it. Locks sinkMutex; an in-flight logging call may still invoke the previous sink.
std::string & threadProject ()
 Return the calling thread's project tag; an empty tag denotes the application.
bool & sinkSuppressed ()
 Whether the calling thread's printed lines skip the sink, so they reach stdout only.
bool & consoleVisible ()
 Whether the calling thread's log entries may be shown in the Console.
F_void printf (const F_char *PID, const F_char *PIDColor, const F_char *level, const F_char *levelColor, const F_char *message)
 Print a formatted log line with PID, level and colors. Serializes and flushes stdout, then invokes a snapshot of the sink on the calling thread without holding either mutex. The sink must not log and may run concurrently.
F_void vprintf_helper (const F_char *PID, const F_char *PIDColor, const F_char *level, const F_char *levelColor, const F_char *fmt, va_list args)
 Format up to 1023 message bytes and delegate to printf().
F_void electronInfo (const F_char *fmt,...)
 Log info for Electron.
F_void electronWarn (const F_char *fmt,...)
 Log warning for Electron.
F_void electronError (const F_char *fmt,...)
 Log error for Electron.
F_void electronFatal (const F_char *fmt,...)
 Log fatal for Electron.
F_void engineInfo (const F_char *fmt,...)
 Log info for Engine.
F_void engineSession (const std::string &name)
 Marks the start of a log session under the calling thread's project tag. The Engine records it as a session row, which the Console shows as a divider before the session's entries.
F_void engineInfo (const std::string &message)
 Print an Engine info line without interpreting the message as a format string.
F_void engineWarn (const F_char *fmt,...)
 Log warning for Engine.
F_void engineError (const F_char *fmt,...)
 Log error for Engine.
F_void engineFatal (const F_char *fmt,...)
 Log fatal for Engine.

Variables

constexpr const F_char * ANSI_RESET = "\033[0m"
 ANSI reset code.
constexpr const F_char * ANSI_BOLD = "\033[1m"
 ANSI bold.
constexpr const F_char * ANSI_UNDERLINE = "\033[4m"
 ANSI underline.
constexpr const F_char * ANSI_BLINK = "\033[5m"
 ANSI blink.
constexpr const F_char * ANSI_INVERSE = "\033[7m"
 ANSI inverse.
constexpr const F_char * ANSI_FG_BLACK = "\033[30m"
 ANSI FG black.
constexpr const F_char * ANSI_FG_RED = "\033[31m"
 ANSI FG red.
constexpr const F_char * ANSI_FG_GREEN = "\033[32m"
 ANSI FG green.
constexpr const F_char * ANSI_FG_YELLOW = "\033[33m"
 ANSI FG yellow.
constexpr const F_char * ANSI_FG_BLUE = "\033[34m"
 ANSI FG blue.
constexpr const F_char * ANSI_FG_MAGENTA = "\033[35m"
 ANSI FG magenta.
constexpr const F_char * ANSI_FG_CYAN = "\033[36m"
 ANSI FG cyan.
constexpr const F_char * ANSI_FG_WHITE = "\033[37m"
 ANSI FG white.
constexpr const F_char * ANSI_FG_ORANGE = "\x1b[38;5;208m"
 ANSI FG orange (256-color).
constexpr const F_char * ANSI_BG_BLACK = "\033[40m"
 ANSI BG black.
constexpr const F_char * ANSI_BG_RED = "\033[41m"
 ANSI BG red.
constexpr const F_char * ANSI_BG_GREEN = "\033[42m"
 ANSI BG green.
constexpr const F_char * ANSI_BG_YELLOW = "\033[43m"
 ANSI BG yellow.
constexpr const F_char * ANSI_BG_BLUE = "\033[44m"
 ANSI BG blue.
constexpr const F_char * ANSI_BG_MAGENTA = "\033[45m"
 ANSI BG magenta.
constexpr const F_char * ANSI_BG_CYAN = "\033[46m"
 ANSI BG cyan.
constexpr const F_char * ANSI_BG_WHITE = "\033[47m"
 ANSI BG white.
constexpr const F_char * ANSI_BG_ORANGE = "\033[48;5;208m"
 ANSI BG orange (256-color).
constexpr F_long TIMESTAMP_SIZE = 32
 Timestamp buffer size.
constexpr F_long DATE_SIZE = 32
 Date buffer size.
constexpr F_long TIME_SIZE = 32
 Time buffer size.

Typedef Documentation

◆ dateBuffer

Date buffer type.

Definition at line 133 of file log_manager.hpp.

◆ Sink

using fray::log::Sink = std::function<void(const F_char *PID, const F_char *level, F_long thread, const std::string &project, const F_char *message, bool consoleVisible)>

Receives each printed line synchronously on the logging thread; it must not log. The sink runs without the output or sink mutex held; concurrent calls may overlap.

Parameters
PIDBorrowed process label.
levelBorrowed severity label.
threadCalling thread's logging id.
projectCalling thread's project tag; empty denotes the application.
messageBorrowed formatted message, valid for the call.
consoleVisibleWhether the line may be shown in the Console.

Definition at line 241 of file log_manager.hpp.

◆ timeBuffer

Time buffer type.

Definition at line 141 of file log_manager.hpp.

◆ TimestampBuffer

Timestamp buffer type.

Definition at line 125 of file log_manager.hpp.

Function Documentation

◆ consoleVisible()

bool & fray::log::consoleVisible ( )
inline

Whether the calling thread's log entries may be shown in the Console.

Definition at line 368 of file log_manager.hpp.

◆ electronError()

F_void fray::log::electronError ( const F_char * fmt,
... )
inline

Log error for Electron.

Parameters
fmtFormat string.
...Variadic args.

Definition at line 496 of file log_manager.hpp.

◆ electronFatal()

F_void fray::log::electronFatal ( const F_char * fmt,
... )
inline

Log fatal for Electron.

Parameters
fmtFormat string.
...Variadic args.

Definition at line 511 of file log_manager.hpp.

◆ electronInfo()

F_void fray::log::electronInfo ( const F_char * fmt,
... )
inline

Log info for Electron.

Parameters
fmtFormat string.
...Variadic args.

Definition at line 466 of file log_manager.hpp.

◆ electronWarn()

F_void fray::log::electronWarn ( const F_char * fmt,
... )
inline

Log warning for Electron.

Parameters
fmtFormat string.
...Variadic args.

Definition at line 481 of file log_manager.hpp.

◆ engineError()

F_void fray::log::engineError ( const F_char * fmt,
... )
inline

Log error for Engine.

Parameters
fmtFormat string.
...Variadic args.

Definition at line 577 of file log_manager.hpp.

◆ engineFatal()

F_void fray::log::engineFatal ( const F_char * fmt,
... )
inline

Log fatal for Engine.

Parameters
fmtFormat string.
...Variadic args.

Definition at line 592 of file log_manager.hpp.

◆ engineInfo() [1/2]

F_void fray::log::engineInfo ( const F_char * fmt,
... )
inline

Log info for Engine.

Parameters
fmtFormat string.
...Variadic args.

Definition at line 526 of file log_manager.hpp.

◆ engineInfo() [2/2]

F_void fray::log::engineInfo ( const std::string & message)
inline

Print an Engine info line without interpreting the message as a format string.

Parameters
messagePreformatted message text.

Definition at line 551 of file log_manager.hpp.

◆ engineSession()

F_void fray::log::engineSession ( const std::string & name)
inline

Marks the start of a log session under the calling thread's project tag. The Engine records it as a session row, which the Console shows as a divider before the session's entries.

Parameters
name"Fray" for the application, or the project's name.

Definition at line 541 of file log_manager.hpp.

◆ engineWarn()

F_void fray::log::engineWarn ( const F_char * fmt,
... )
inline

Log warning for Engine.

Parameters
fmtFormat string.
...Variadic args.

Definition at line 562 of file log_manager.hpp.

◆ generateTimestamp()

F_void fray::log::generateTimestamp ( F_char * timestamp,
std::chrono::system_clock::time_point now = std::chrono::system_clock::now() )
inline

Write "[HH:MM:SS:mmm] [YY.MM.DD]" into buffer.

Parameters
timestampOutput buffer (>=32 bytes).
nowTime point formatted in local time; defaults to the current time.

Definition at line 148 of file log_manager.hpp.

◆ getDate()

F_void fray::log::getDate ( F_char * date)
inline

Write "YY.MM.DD" into buffer.

Parameters
dateOutput buffer (>=32 bytes).

Definition at line 174 of file log_manager.hpp.

◆ getTime()

F_void fray::log::getTime ( F_char * time,
std::chrono::system_clock::time_point now = std::chrono::system_clock::now() )
inline

Write "HH:MM:SS.mmm" into buffer.

Parameters
timeOutput buffer (>=32 bytes).
nowTime point formatted in local time; defaults to the current time.

Definition at line 197 of file log_manager.hpp.

◆ printf()

F_void fray::log::printf ( const F_char * PID,
const F_char * PIDColor,
const F_char * level,
const F_char * levelColor,
const F_char * message )
inline

Print a formatted log line with PID, level and colors. Serializes and flushes stdout, then invokes a snapshot of the sink on the calling thread without holding either mutex. The sink must not log and may run concurrently.

Parameters
PIDPID label (e.g., "ENG", "ELC").
PIDColorANSI color for PID.
levelLevel label (e.g., "INF").
levelColorANSI color for level.
messagePreformatted message text.

Definition at line 397 of file log_manager.hpp.

◆ setSink()

F_void fray::log::setSink ( Sink sink)
inline

Replace the sink; an empty function removes it. Locks sinkMutex; an in-flight logging call may still invoke the previous sink.

Parameters
sinkCallback to own and invoke after printing, or an empty function to remove it.

Definition at line 268 of file log_manager.hpp.

◆ sinkMutex()

std::mutex & fray::log::sinkMutex ( )
inline

Return the mutex protecting access to the shared sink slot.

Definition at line 246 of file log_manager.hpp.

◆ sinkSlot()

std::shared_ptr< Sink > & fray::log::sinkSlot ( )
inline

Return the shared sink slot; callers must hold sinkMutex when accessing it.

Definition at line 255 of file log_manager.hpp.

◆ sinkSuppressed()

bool & fray::log::sinkSuppressed ( )
inline

Whether the calling thread's printed lines skip the sink, so they reach stdout only.

Returns
Mutable thread-local flag.

Definition at line 334 of file log_manager.hpp.

◆ threadId()

F_long fray::log::threadId ( )
inline

Small sequential id for the calling thread, assigned on its first call (the first caller is 0).

Returns
This thread's stable id for the lifetime of the thread.

Definition at line 222 of file log_manager.hpp.

◆ threadProject()

std::string & fray::log::threadProject ( )
inline

Return the calling thread's project tag; an empty tag denotes the application.

Returns
Mutable thread-local project identifier used for subsequent log lines.

Definition at line 281 of file log_manager.hpp.

◆ vprintf_helper()

F_void fray::log::vprintf_helper ( const F_char * PID,
const F_char * PIDColor,
const F_char * level,
const F_char * levelColor,
const F_char * fmt,
va_list args )
inline

Format up to 1023 message bytes and delegate to printf().

Parameters
PIDPID label.
PIDColorANSI color for PID.
levelLevel label.
levelColorANSI color for level.
fmtFormat string.
argsva_list of arguments.

Definition at line 448 of file log_manager.hpp.

Variable Documentation

◆ ANSI_BG_BLACK

const F_char* fray::log::ANSI_BG_BLACK = "\033[40m"
constexpr

ANSI BG black.

Definition at line 84 of file log_manager.hpp.

◆ ANSI_BG_BLUE

const F_char* fray::log::ANSI_BG_BLUE = "\033[44m"
constexpr

ANSI BG blue.

Definition at line 100 of file log_manager.hpp.

◆ ANSI_BG_CYAN

const F_char* fray::log::ANSI_BG_CYAN = "\033[46m"
constexpr

ANSI BG cyan.

Definition at line 108 of file log_manager.hpp.

◆ ANSI_BG_GREEN

const F_char* fray::log::ANSI_BG_GREEN = "\033[42m"
constexpr

ANSI BG green.

Definition at line 92 of file log_manager.hpp.

◆ ANSI_BG_MAGENTA

const F_char* fray::log::ANSI_BG_MAGENTA = "\033[45m"
constexpr

ANSI BG magenta.

Definition at line 104 of file log_manager.hpp.

◆ ANSI_BG_ORANGE

const F_char* fray::log::ANSI_BG_ORANGE = "\033[48;5;208m"
constexpr

ANSI BG orange (256-color).

Definition at line 116 of file log_manager.hpp.

◆ ANSI_BG_RED

const F_char* fray::log::ANSI_BG_RED = "\033[41m"
constexpr

ANSI BG red.

Definition at line 88 of file log_manager.hpp.

◆ ANSI_BG_WHITE

const F_char* fray::log::ANSI_BG_WHITE = "\033[47m"
constexpr

ANSI BG white.

Definition at line 112 of file log_manager.hpp.

◆ ANSI_BG_YELLOW

const F_char* fray::log::ANSI_BG_YELLOW = "\033[43m"
constexpr

ANSI BG yellow.

Definition at line 96 of file log_manager.hpp.

◆ ANSI_BLINK

const F_char* fray::log::ANSI_BLINK = "\033[5m"
constexpr

ANSI blink.

Definition at line 38 of file log_manager.hpp.

◆ ANSI_BOLD

const F_char* fray::log::ANSI_BOLD = "\033[1m"
constexpr

ANSI bold.

Definition at line 30 of file log_manager.hpp.

◆ ANSI_FG_BLACK

const F_char* fray::log::ANSI_FG_BLACK = "\033[30m"
constexpr

ANSI FG black.

Definition at line 47 of file log_manager.hpp.

◆ ANSI_FG_BLUE

const F_char* fray::log::ANSI_FG_BLUE = "\033[34m"
constexpr

ANSI FG blue.

Definition at line 63 of file log_manager.hpp.

◆ ANSI_FG_CYAN

const F_char* fray::log::ANSI_FG_CYAN = "\033[36m"
constexpr

ANSI FG cyan.

Definition at line 71 of file log_manager.hpp.

◆ ANSI_FG_GREEN

const F_char* fray::log::ANSI_FG_GREEN = "\033[32m"
constexpr

ANSI FG green.

Definition at line 55 of file log_manager.hpp.

◆ ANSI_FG_MAGENTA

const F_char* fray::log::ANSI_FG_MAGENTA = "\033[35m"
constexpr

ANSI FG magenta.

Definition at line 67 of file log_manager.hpp.

◆ ANSI_FG_ORANGE

const F_char* fray::log::ANSI_FG_ORANGE = "\x1b[38;5;208m"
constexpr

ANSI FG orange (256-color).

Definition at line 79 of file log_manager.hpp.

◆ ANSI_FG_RED

const F_char* fray::log::ANSI_FG_RED = "\033[31m"
constexpr

ANSI FG red.

Definition at line 51 of file log_manager.hpp.

◆ ANSI_FG_WHITE

const F_char* fray::log::ANSI_FG_WHITE = "\033[37m"
constexpr

ANSI FG white.

Definition at line 75 of file log_manager.hpp.

◆ ANSI_FG_YELLOW

const F_char* fray::log::ANSI_FG_YELLOW = "\033[33m"
constexpr

ANSI FG yellow.

Definition at line 59 of file log_manager.hpp.

◆ ANSI_INVERSE

const F_char* fray::log::ANSI_INVERSE = "\033[7m"
constexpr

ANSI inverse.

Definition at line 42 of file log_manager.hpp.

◆ ANSI_RESET

const F_char* fray::log::ANSI_RESET = "\033[0m"
constexpr

ANSI reset code.

Definition at line 26 of file log_manager.hpp.

◆ ANSI_UNDERLINE

const F_char* fray::log::ANSI_UNDERLINE = "\033[4m"
constexpr

ANSI underline.

Definition at line 34 of file log_manager.hpp.

◆ DATE_SIZE

F_long fray::log::DATE_SIZE = 32
constexpr

Date buffer size.

Definition at line 129 of file log_manager.hpp.

◆ TIME_SIZE

F_long fray::log::TIME_SIZE = 32
constexpr

Time buffer size.

Definition at line 137 of file log_manager.hpp.

◆ TIMESTAMP_SIZE

F_long fray::log::TIMESTAMP_SIZE = 32
constexpr

Timestamp buffer size.

Definition at line 121 of file log_manager.hpp.