Skip to content

Commit

Permalink
Add template keyword to the log macro. Add option to to append date a…
Browse files Browse the repository at this point in the history
…nd time to the file.
  • Loading branch information
odygrd committed Apr 23, 2022
1 parent 7703f46 commit fe01be4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
- [v1.1.0](#v1.1.0)
- [v1.0.0](#v1.0.0)

## v1.7.1 (in progress)
## v1.7.1

**Improvements/Fixes**

- Fix support for wide characters on Windows ([#168](https://github.com/odygrd/quill/issues/168))
- Fix compilation error when `Quill::Logger*` is stored as a class member in templated classes
- Add `FilenameAppend::DateTime` as an option when creating a file handler

## v1.7.0

Expand Down
1 change: 1 addition & 0 deletions quill/include/quill/LogLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ QUILL_NODISCARD char const* to_string(LogLevel log_level);
/**
* Converts a string to a LogLevel enum value
* @param log_level the log level string to convert
* "tracel3", "tracel2", "tracel1", "debug", "info", "warning", "error", "backtrace", "none"
* @return the corresponding LogLevel enum value
*/
QUILL_NODISCARD LogLevel from_string(std::string log_level);
Expand Down
3 changes: 2 additions & 1 deletion quill/include/quill/Quill.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ QUILL_NODISCARD QUILL_ATTRIBUTE_COLD Handler* create_handler(filename_t const& h
* Creates or returns an existing handler to a file.
* If the file is already opened the existing handler for this file is returned instead
* @param filename the name of the file
* @param append_to_filename additional info to append to the name of the file. FilenameAppend::None or FilenameAppend::Date
* @param append_to_filename additional info to append to the name of the file.
* FilenameAppend::None, FilenameAppend::Date, FilenameAppend::DateTime
* @param mode Used only when the file is opened for the first time. Otherwise the value is ignored
* If no value is specified during the file creation "a" is used as default.
* @return A handler to a file
Expand Down
17 changes: 10 additions & 7 deletions quill/include/quill/detail/LogMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// Main Log Macros

#if defined(QUILL_NOFN_MACROS)
// clang-format off
// clang-format off
#define QUILL_LOGGER_CALL_NOFN(likelyhood, logger, log_statement_level, fmt, ...) \
do { \
struct { \
Expand All @@ -39,11 +39,12 @@
"n/a", fmt, log_statement_level}; } \
} anonymous_log_record_info; \
\
if (likelyhood(logger->should_log<log_statement_level>())) \
if (likelyhood(logger->template should_log<log_statement_level>())) \
{ \
constexpr bool try_fast_queue {true}; /* Available in dual queue mode only */ \
constexpr bool is_backtrace_log_record {false}; \
logger->log<try_fast_queue, is_backtrace_log_record, decltype(anonymous_log_record_info)> \
logger->template log<try_fast_queue, is_backtrace_log_record, \
decltype(anonymous_log_record_info)> \
(FMT_STRING(fmt), ##__VA_ARGS__); \
} \
} while (0)
Expand All @@ -60,11 +61,12 @@
function_name, fmt, log_statement_level}; } \
} anonymous_log_record_info; \
\
if (likelyhood(logger->should_log<log_statement_level>())) \
if (likelyhood(logger->template should_log<log_statement_level>())) \
{ \
constexpr bool try_fast_queue {true}; /* Available in dual queue mode only */ \
constexpr bool is_backtrace_log_record {false}; \
logger->log<try_fast_queue, is_backtrace_log_record, decltype(anonymous_log_record_info)> \
logger->template log<try_fast_queue, is_backtrace_log_record, \
decltype(anonymous_log_record_info)> \
(FMT_STRING(fmt), ##__VA_ARGS__); \
} \
} while (0)
Expand All @@ -78,11 +80,12 @@
function_name, fmt, quill::LogLevel::Backtrace}; } \
} anonymous_log_record_info; \
\
if (QUILL_LIKELY(logger->should_log<quill::LogLevel::Backtrace>())) \
if (QUILL_LIKELY(logger->template should_log<quill::LogLevel::Backtrace>())) \
{ \
constexpr bool try_fast_queue {true}; /* Available in dual queue mode only */ \
constexpr bool is_backtrace_log_record {true}; \
logger->log<try_fast_queue, is_backtrace_log_record, decltype(anonymous_log_record_info)> \
logger->template log<try_fast_queue, is_backtrace_log_record, \
decltype(anonymous_log_record_info)> \
(FMT_STRING(fmt), ##__VA_ARGS__); \
} \
} while (0)
Expand Down
1 change: 1 addition & 0 deletions quill/include/quill/handlers/FileHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace quill

enum class FilenameAppend
{
DateTime,
Date,
None
};
Expand Down
5 changes: 5 additions & 0 deletions quill/src/handlers/FileHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ FileHandler::FileHandler(filename_t const& filename, std::string const& mode, Fi
{
_current_filename = detail::file_utilities::append_date_to_filename(_filename);
}
else if (append_to_filename == FilenameAppend::DateTime)
{
_current_filename =
detail::file_utilities::append_date_to_filename(_filename, std::chrono::system_clock::now(), true);
}

// _file is the base file*
_file = detail::file_utilities::open(_current_filename, mode);
Expand Down

0 comments on commit fe01be4

Please sign in to comment.