bux API Reference 1.6.8
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
bux::C_PathFmtLogSnap Class Reference

#include <FileLog.h>

Inheritance diagram for bux::C_PathFmtLogSnap:
Inheritance graph
[legend]

Public Member Functions

 C_PathFmtLogSnap (const std::string &pathFmt="%Y%m%d.log")
 
 C_PathFmtLogSnap (uintmax_t fsize_in_bytes, const auto &fallbackPaths)
 
void configPath (const std::string &pathFmt)
 
void configPath (uintmax_t fsize_in_bytes, const auto &fallbackPaths)
 
void enableAutoMkDir (bool yes=true)
 
void setBinaryMode (bool enabled)
 
std::ostream * snap () override
 Snap the current T value.
 
- Public Member Functions inherited from bux::I_SnapT< std::ostream * >
virtual ~I_SnapT ()=default
 Pointer deletion is hereby granted.
 
virtual std::ostream * snap ()=0
 Snap the current T value.
 

Detailed Description

Configurable to automatically change the output path according to the current timestamp.

Examples
test/smoke_filtlog.cpp, and test/smoke_paralog.cpp.

Definition at line 16 of file FileLog.h.

Constructor & Destructor Documentation

◆ C_PathFmtLogSnap() [1/2]

bux::C_PathFmtLogSnap::C_PathFmtLogSnap ( const std::string &  pathFmt = "%Y%m%d.log")
inlineexplicit
Parameters
[in]pathFmtPath formatting string. The default string "\%Y\%m\%d.log" is for daily report.

This constructor simply calls configPath(_pathFmt)

Example:

//
// Recommended log file formats according to timestamp
//
C_PathFmtLogSnap BillingLog("./billinglog/%Y%m%d.bil"); // daily
C_PathFmtLogSnap RatingLog("./billinglog/%Y%m/%d_outbound.log"); // daily
C_PathFmtLogSnap ErrorLog("./log/%Y%m%p_err.log"); // half-daily
C_PathFmtLogSnap DbLog("./log/%Y%m%d%H_db.log"); // hourly
C_PathFmtLogSnap ActivityLog("./log/%Y%mcall.log"); // monthly

Definition at line 23 of file FileLog.h.

References configPath().

◆ C_PathFmtLogSnap() [2/2]

bux::C_PathFmtLogSnap::C_PathFmtLogSnap ( uintmax_t  fsize_in_bytes,
const auto &  fallbackPaths 
)
inline
Parameters
[in]fsize_in_bytesSize limit in bytes for each log file.
[in]fallbackPathsFallback path format list, ...

This constructor simply calls configPath(fsize_in_bytes, fallbackPaths)

Example:

//
// Demo fallback file formats from daily to per-minute everytime 16MB file size is reached.
//
C_PathFmtLogSnap snap(16UL<<20, std::array{
"logs/%y%m%d-0000.log",
"logs/%y%m%d-%H00.log",
"logs/%y%m%d-%H%M.log"});
std::ostream * snap() override
Snap the current T value.
Definition: FileLog.cpp:164

Definition at line 45 of file FileLog.h.

References configPath().

Member Function Documentation

◆ configPath() [1/2]

void bux::C_PathFmtLogSnap::configPath ( const std::string &  _pathFmt)

Parameters
[in]_pathFmtThe third argument of ANSI C time function strftime(), see MSDN Library for help. Everytime when virtual method getResource() gets called, the current log path is regenerated according to this format string and the current timestamp to compare with the previous one. Were they different, the internal file stream is reopenned on the new path. Here is the format spec for your convience:

The format argument consists of one or more codes; as in printf(), the formatting codes are preceded by a percent sign (%). Characters that do not begin with % are copied unchangedly. The LC_TIME category of the current locale affects the output formatting of strftime. (For more information on LC_TIME, see setlocale().) The formatting codes for strftime() are listed below:

%a

Abbreviated weekday name

%A

Full weekday name

%b

Abbreviated month name

%B

Full month name

%c

Date and time representation appropriate for locale

%d

Day of month as decimal number (01 - 31)

%H

Hour in 24-hour format (00 - 23)

%I

Hour in 12-hour format (01 - 12)

%j

Day of year as decimal number (001 - 366)

%m

Month as decimal number (01 - 12)

%M

Minute as decimal number (00 - 59)

%p

Current locale's A.M./P.M. indicator for 12-hour clock

%S

Second as decimal number (00 - 59)

%U

Week of year as decimal number, with Sunday as first day of week (00 - 53)

%w

Weekday as decimal number (0 - 6; Sunday is 0)

%W

Week of year as decimal number, with Monday as first day of week (00 - 53)

%x

Date representation for current locale

%X

Time representation for current locale

%y

Year without century, as decimal number (00 - 99)

%Y

Year with century, as decimal number

%z, %Z

Time-zone name or abbreviation; no characters if time zone is unknown

%%

Percent sign

As in the printf function, the # flag may prefix any formatting code. In that case, the meaning of the format code is changed as follows.

Format Code
Meaning
%#a, %#A, %#b, %#B, %#p, %#X, %#z, %#Z, %#%
# flag is ignored.
%#c
Long date and time representation, appropriate for current locale. For example: "Tuesday, March 14, 1995, 12:41:29".
%#x
Long date representation, appropriate to current locale. For example: "Tuesday, March 14, 1995".
%#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#Y
Remove leading zeros (if any).

Example: see construct.

Precondition
_pathFmt is not empty.

Definition at line 10 of file FileLog.cpp.

References RUNTIME_ERROR.

Referenced by C_PathFmtLogSnap().

Here is the caller graph for this function:

◆ configPath() [2/2]

void bux::C_PathFmtLogSnap::configPath ( uintmax_t  fsize_in_bytes,
const auto &  fallbackPaths 
)
inline

Definition at line 67 of file FileLog.h.

◆ enableAutoMkDir()

void bux::C_PathFmtLogSnap::enableAutoMkDir ( bool  yes = true)
Parameters
[in]yesWhether or not to create subdirectory for the openning log path. The default is true.

If enabled, getResource() always creates the subdir before openning the log path no matter how deep the subdir is.

Since constructor always enables it, you hradly need to call this method explicitly.

Definition at line 141 of file FileLog.cpp.

◆ setBinaryMode()

void bux::C_PathFmtLogSnap::setBinaryMode ( bool  enabled)

Definition at line 155 of file FileLog.cpp.

◆ snap()

std::ostream * bux::C_PathFmtLogSnap::snap ( )
overridevirtual

Snap the current T value.

Implements bux::I_SnapT< std::ostream * >.

Definition at line 164 of file FileLog.cpp.

References RUNTIME_ERROR.


The documentation for this class was generated from the following files: