summaryrefslogtreecommitdiff
path: root/src/logger.hh
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
committerJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
commit6232d13f5321b87ddf12a1aa36b4545da45f173d (patch)
tree23f3316470a14136debd9d02f9e920ca2b06f4cc /src/logger.hh
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in memroy.
Diffstat (limited to 'src/logger.hh')
-rw-r--r--src/logger.hh57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/logger.hh b/src/logger.hh
new file mode 100644
index 0000000..47bbedd
--- /dev/null
+++ b/src/logger.hh
@@ -0,0 +1,57 @@
+#ifndef LOGGER_HH
+#define LOGGER_HH
+
+#include <filesystem>
+#include <memory>
+#include <string>
+
+class Logger {
+public:
+ virtual ~Logger() = default;
+
+ static std::unique_ptr<Logger> create_stdio();
+ // Can return nullptr, will write reason to fallback.
+ static std::unique_ptr<Logger> create_file(std::filesystem::path const& path,
+ Logger* fallback);
+ static std::unique_ptr<Logger> create_syslog(std::string const& prgname);
+ static std::unique_ptr<Logger> create_null();
+
+ virtual void err(char const* format, ...)
+#if HAVE_ATTRIBUTE_FORMAT
+ __attribute__((format(printf, 2, 3))) // this takes up 1
+#endif // HAVE_ATTRIBUTE_FORMAT
+ = 0;
+
+ virtual void warn(char const* format, ...)
+#if HAVE_ATTRIBUTE_FORMAT
+ __attribute__((format(printf, 2, 3)))
+#endif // HAVE_ATTRIBUTE_FORMAT
+ = 0;
+
+ virtual void info(char const* format, ...)
+#if HAVE_ATTRIBUTE_FORMAT
+ __attribute__((format(printf, 2, 3)))
+#endif // HAVE_ATTRIBUTE_FORMAT
+ = 0;
+
+#ifdef NDEBUG
+ void dbg(char const* format, ...)
+#if HAVE_ATTRIBUTE_FORMAT
+ __attribute__((format(printf, 2, 3)))
+#endif // HAVE_ATTRIBUTE_FORMAT
+ {}
+#else
+ virtual void dbg(char const* format, ...)
+#if HAVE_ATTRIBUTE_FORMAT
+ __attribute__((format(printf, 2, 3)))
+#endif // HAVE_ATTRIBUTE_FORMAT
+ = 0;
+#endif
+
+protected:
+ Logger() = default;
+ Logger(Logger const&) = delete;
+ Logger& operator=(Logger const&) = delete;
+};
+
+#endif // LOGGER_HH