18 #ifndef PSTORE_OS_LOGGING_HPP 19 #define PSTORE_OS_LOGGING_HPP 52 constexpr
explicit operator gsl::czstring ()
const noexcept {
return str_; }
62 virtual ~
logger () noexcept =
default;
67 void set_priority (
priority const p) noexcept { priority_ = p; }
68 priority get_priority ()
const noexcept {
return priority_; }
70 virtual void log (
priority p, std::string
const & message) = 0;
72 virtual void log (
priority p, gsl::czstring message,
int d);
73 virtual void log (
priority p, gsl::czstring message,
unsigned d);
74 virtual void log (
priority p, gsl::czstring message,
long d);
75 virtual void log (
priority p, gsl::czstring message,
unsigned long d);
76 virtual void log (
priority p, gsl::czstring message,
long long d);
77 virtual void log (
priority p, gsl::czstring message,
unsigned long long d);
79 virtual void log (
priority p, gsl::czstring message);
80 virtual void log (
priority p, gsl::czstring part1, gsl::czstring part2);
83 void log (
priority const p, gsl::czstring
const message, std::string
const & d) {
84 this->log (p, message, d.c_str ());
89 static std::string to_string (gsl::czstring
const message, T
const t) {
90 return message + std::to_string (t);
106 static gsl::czstring priority_string (
priority p) noexcept;
107 static std::string get_current_thread_name ();
109 static constexpr std::size_t
const time_buffer_size =
sizeof "YYYY-MM-DDTHH:mm:SS+ZZZZ";
110 static std::size_t time_string (std::time_t t,
114 void log (
priority p, std::string
const & message)
final;
117 virtual void log_impl (std::string
const & message) = 0;
119 static std::mutex mutex_;
120 std::string thread_name_ = get_current_thread_name ();
133 void log_impl (std::string
const & message)
override;
175 static void rename (std::string
const & from, std::string
const & to) {
182 using stream_type = std::ofstream;
184 static void open (stream_type & s, std::string
const & name,
185 std::ios_base::openmode
const mode) {
188 static void close (stream_type & s) { s.close (); }
189 static void clear (stream_type &) {}
193 void create_log_stream (std::string
const & ident);
198 using logger_collection = std::vector<std::unique_ptr<logger>>;
199 extern thread_local logger_collection * log_destinations;
204 inline bool logging_enabled () noexcept {
return details::log_destinations !=
nullptr; }
207 if (details::log_destinations !=
nullptr) {
208 for (std::unique_ptr<logger> & destination : *details::log_destinations) {
209 destination->log (p, message);
213 template <
typename T>
215 if (details::log_destinations !=
nullptr) {
216 for (std::unique_ptr<logger> & destination : *details::log_destinations) {
217 destination->log (p, message, d);
223 #endif // PSTORE_OS_LOGGING_HPP Definition: logging.hpp:181
Definition: logging.hpp:173
action must be taken immediately
priority
Definition: logging.hpp:37
Definition: logging.hpp:141
Definition: logging.hpp:158
Cross platform file management functions and classes.
Definition: logging.hpp:102
normal, but significant, condition
Implements a portable file access API.
Definition: file.hpp:566
bool exists(std::string const &path)
Returns true if the file system contains an object at the location given by path. ...
Definition: file_posix.cpp:505
bool rename(std::string const &new_name)
Renames a file from one UTF-8 encoded path to another.
Definition: file_posix.cpp:355
Definition: nonpod2.cpp:40
The base class for logging streams.
Definition: logging.hpp:35
void unlink(std::string const &path, bool allow_noent=false)
Deletes the file system object at the location given by path.
Definition: file_posix.cpp:507
Definition: logging.hpp:127
Definition: logging.hpp:48