-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Introduce lv_log - Refine logging mechanism
- Loading branch information
Showing
9 changed files
with
153 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
#include <optional> | ||
#include <string> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
#include <fmt/core.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <iostream> | ||
#include "fmt/core.h" | ||
#include "lv_log.hh" | ||
|
||
LogLv g_log_lv = LogLv::INFO; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef _LV_LOG_H | ||
#define _LV_LOG_H | ||
|
||
#include <iostream> | ||
#include "fmt/core.h" | ||
|
||
enum LogLv | ||
{ | ||
ERROR = 1, | ||
WARNING = 2, | ||
INFO = 3, | ||
DEBUG = 4, | ||
}; | ||
|
||
extern LogLv g_log_lv; | ||
|
||
template <class... Args> | ||
void | ||
lv_log (LogLv lv, fmt::format_string<Args...> fmt, Args &&...args); | ||
|
||
template <class... Args> | ||
void | ||
log_flush (fmt::format_string<Args...> fmt, Args &&...args); | ||
|
||
template <class... Args> | ||
void | ||
lv_log (LogLv lv, fmt::format_string<Args...> fmt, Args &&...args) | ||
{ | ||
if (g_log_lv >= lv) | ||
{ | ||
constexpr std::string_view header{"[tf-focusd] "}; | ||
std::cout << header << fmt::format (fmt, std::forward<Args> (args)...) | ||
<< std::endl; | ||
} | ||
} | ||
|
||
template <class... Args> | ||
void | ||
log_flush (fmt::format_string<Args...> fmt, Args &&...args) | ||
{ | ||
constexpr std::string_view header{"[tf-focusd] "}; | ||
std::cout << header << fmt::format (fmt, args...) << std::flush; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.