LogIt++
Loading...
Searching...
No Matches
logit::FormatInstruction Struct Reference

Structure to store log formatting instructions. More...

#include <PatternCompiler.hpp>

Public Types

enum class  FormatType {
  StaticText , Year , Month , Day ,
  Hour , Minute , Second , Millisecond ,
  TwoDigitYear , DateTime , ShortDate , TimeISO8601 ,
  DateISO8601 , TimeStamp , MilliSecondTimeStamp , AbbreviatedMonthName ,
  FullMonthName , AbbreviatedWeekdayName , FullWeekdayName , LogLevel ,
  ShortLogLevel , FileName , FullFileName , SourceFileAndLine ,
  LineNumber , FunctionName , ThreadId , StartColor ,
  EndColor , Message
}
 Possible types of instructions for log formatting. More...
 

Public Member Functions

 FormatInstruction (const std::string &text, const bool &strip_ansi)
 Constructor for static text.
 
 FormatInstruction (const FormatType &type, const int &width=0, const bool &left=false, const bool &center=false, const bool &trunc=false, const bool &strip_ansi=false)
 Constructor for other types.
 
template<class StreamType >
void apply (StreamType &oss, const LogRecord &record, const time_shield::DateTimeStruct &dt) const
 Apply formatting considering alignment and width.
 

Public Attributes

FormatType type
 The type of the format instruction.
 
std::string static_text
 Used only if type == StaticText.
 
int width = 0
 Width for formatting.
 
bool left_align = false
 Left alignment flag.
 
bool center_align = false
 Center alignment flag.
 
bool truncate = false
 Truncation flag.
 
bool strip_ansi = false
 Removes ANSI escape codes (e.g., colors) if true.
 

Private Member Functions

std::string remove_ansi_escape_codes (const std::string &input) const
 Removes ANSI escape codes (including color codes and cursor movement) from a string.
 

Detailed Description

Structure to store log formatting instructions.

Definition at line 17 of file PatternCompiler.hpp.

Member Enumeration Documentation

◆ FormatType

Possible types of instructions for log formatting.

Enumerator
StaticText 

Static text.

Year 

Y: Year

Month 

m: Month

Day 

d: Day

Hour 

H: Hour

Minute 

M: Minute

Second 

S: Second

Millisecond 

e: Millisecond

TwoDigitYear 

C: Two-digit year

DateTime 

c: Date and time

ShortDate 

D: Short date (m/d/y)

TimeISO8601 

T or X: Time in ISO 8601 format (H:M:S)

DateISO8601 

F: Date in ISO 8601 format (Y-m-d)

TimeStamp 

s or E: Timestamp in seconds

MilliSecondTimeStamp 

ms: Timestamp in milliseconds

AbbreviatedMonthName 

b: Abbreviated month name

FullMonthName 

B: Full month name

AbbreviatedWeekdayName 

a: Abbreviated weekday name

FullWeekdayName 

A: Full weekday name

LogLevel 

l: Log level

ShortLogLevel 

L: Short log level

FileName 

f, fn, bs: Basename of the source file

FullFileName 

g, ffn: Full file path

SourceFileAndLine 

%@: Source file and line number

LineNumber 

%#: Line number

FunctionName 

%!: Function name

ThreadId 

t: Thread identifier

StartColor 

%^: Start of color range

EndColor 

$: End of color range

Message 

v: Message

Definition at line 21 of file PatternCompiler.hpp.

Constructor & Destructor Documentation

◆ FormatInstruction() [1/2]

logit::FormatInstruction::FormatInstruction ( const std::string & text,
const bool & strip_ansi )
inlineexplicit

Constructor for static text.

Parameters
textThe static text.
strip_ansiIf true, removes ANSI escape codes (e.g., colors).

Definition at line 82 of file PatternCompiler.hpp.

◆ FormatInstruction() [2/2]

logit::FormatInstruction::FormatInstruction ( const FormatType & type,
const int & width = 0,
const bool & left = false,
const bool & center = false,
const bool & trunc = false,
const bool & strip_ansi = false )
inlineexplicit

Constructor for other types.

Parameters
typeThe format type.
widthThe width for formatting.
leftLeft alignment flag.
centerCenter alignment flag.
truncTruncation flag.
strip_ansiIf true, removes ANSI escape codes (e.g., colors).

Definition at line 93 of file PatternCompiler.hpp.

Member Function Documentation

◆ apply()

template<class StreamType >
void logit::FormatInstruction::apply ( StreamType & oss,
const LogRecord & record,
const time_shield::DateTimeStruct & dt ) const
inline

Apply formatting considering alignment and width.

Template Parameters
StreamTypeThe type of the output stream.
Parameters
ossThe output stream.
recordThe log record.
dtThe date and time structure.

Definition at line 111 of file PatternCompiler.hpp.

◆ remove_ansi_escape_codes()

std::string logit::FormatInstruction::remove_ansi_escape_codes ( const std::string & input) const
inlineprivate

Removes ANSI escape codes (including color codes and cursor movement) from a string.

Parameters
inputThe input string containing possible ANSI escape codes.
Returns
A string with all ANSI escape codes removed.

Definition at line 341 of file PatternCompiler.hpp.

Member Data Documentation

◆ center_align

bool logit::FormatInstruction::center_align = false

Center alignment flag.

Definition at line 75 of file PatternCompiler.hpp.

◆ left_align

bool logit::FormatInstruction::left_align = false

Left alignment flag.

Definition at line 74 of file PatternCompiler.hpp.

◆ static_text

std::string logit::FormatInstruction::static_text

Used only if type == StaticText.

Definition at line 70 of file PatternCompiler.hpp.

◆ strip_ansi

bool logit::FormatInstruction::strip_ansi = false

Removes ANSI escape codes (e.g., colors) if true.

Definition at line 77 of file PatternCompiler.hpp.

◆ truncate

bool logit::FormatInstruction::truncate = false

Truncation flag.

Definition at line 76 of file PatternCompiler.hpp.

◆ type

FormatType logit::FormatInstruction::type

The type of the format instruction.

Definition at line 69 of file PatternCompiler.hpp.

◆ width

int logit::FormatInstruction::width = 0

Width for formatting.

Definition at line 73 of file PatternCompiler.hpp.


The documentation for this struct was generated from the following file: