Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for configuring FILENAME with %fbase. #724

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [9.96.8] - 22-08-2019
- Adds support for configuring `FILENAME` with `%fbase` in `conf` file.
- Set level output with fixed width.

## [9.96.7] - 24-11-2018
- Adds support for compiling easyloggingpp using Emscripten. This allows the library to be compiled into Javascript or WebAssembly and run in the browser while logging to the browser's Javascript console.

Expand Down
17 changes: 15 additions & 2 deletions src/easylogging++.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ namespace consts {

// Level log values - These are values that are replaced in place of %level format specifier
// Extra spaces after format specifiers are only for readability purposes in log files
static const base::type::char_t* kInfoLevelLogValue = ELPP_LITERAL("INFO");
static const base::type::char_t* kInfoLevelLogValue = ELPP_LITERAL(" INFO");
static const base::type::char_t* kDebugLevelLogValue = ELPP_LITERAL("DEBUG");
static const base::type::char_t* kWarningLevelLogValue = ELPP_LITERAL("WARNING");
static const base::type::char_t* kWarningLevelLogValue = ELPP_LITERAL(" WARN");
static const base::type::char_t* kErrorLevelLogValue = ELPP_LITERAL("ERROR");
static const base::type::char_t* kFatalLevelLogValue = ELPP_LITERAL("FATAL");
static const base::type::char_t* kVerboseLevelLogValue =
Expand Down Expand Up @@ -61,6 +61,7 @@ static const base::type::char_t* kCurrentHostFormatSpecifier = ELPP_LI
static const base::type::char_t* kMessageFormatSpecifier = ELPP_LITERAL("%msg");
static const base::type::char_t* kVerboseLevelFormatSpecifier = ELPP_LITERAL("%vlevel");
static const char* kDateTimeFormatSpecifierForFilename = "%datetime";
static const char* kFileBaseFormatSpecifierForFilename = "%fbase";
// Date/time
static const char* kDays[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
static const char* kDaysAbbrev[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
Expand Down Expand Up @@ -1743,7 +1744,10 @@ unsigned long TypedConfigurations::getULong(std::string confVal) {
std::string TypedConfigurations::resolveFilename(const std::string& filename) {
std::string resultingFilename = filename;
std::size_t dateIndex = std::string::npos;
std::size_t fBaseIndex = std::string::npos;
std::string dateTimeFormatSpecifierStr = std::string(base::consts::kDateTimeFormatSpecifierForFilename);
std::string fileBaseFormatSpecifierStr = std::string(base::consts::kFileBaseFormatSpecifierForFilename);

if ((dateIndex = resultingFilename.find(dateTimeFormatSpecifierStr.c_str())) != std::string::npos) {
while (dateIndex > 0 && resultingFilename[dateIndex - 1] == base::consts::kFormatSpecifierChar) {
dateIndex = resultingFilename.find(dateTimeFormatSpecifierStr.c_str(), dateIndex + 1);
Expand Down Expand Up @@ -1776,6 +1780,15 @@ std::string TypedConfigurations::resolveFilename(const std::string& filename) {
base::utils::Str::replaceAll(resultingFilename, dateTimeFormatSpecifierStr, now);
}
}

if((fBaseIndex = resultingFilename.find(fileBaseFormatSpecifierStr.c_str())) != std::string::npos ){
std::string fbase;
char *fullPathCharArray = new char[1024];
fullPathCharArray = getenv("_");
std::string fullPath(std::move(fullPathCharArray));
fbase = fullPath.substr( fullPath.find_last_of(base::consts::kFilePathSeperator)+1, fullPath.size()-1 );
base::utils::Str::replaceAll(resultingFilename, fileBaseFormatSpecifierStr, fbase);
}
return resultingFilename;
}

Expand Down