aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/logger/system.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/logger/system.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/logger/system.h')
-rw-r--r--library/cpp/logger/system.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/library/cpp/logger/system.h b/library/cpp/logger/system.h
new file mode 100644
index 0000000000..b8c60b3023
--- /dev/null
+++ b/library/cpp/logger/system.h
@@ -0,0 +1,66 @@
+#pragma once
+
+#include "log.h"
+#include "backend.h"
+#include "priority.h"
+
+#define YSYSLOG(priority, ...) SysLogInstance().AddLog((priority), __VA_ARGS__)
+#define YSYSLOGINIT_FLAGS(ident, facility, flags) \
+ struct TLogIniter { \
+ TLogIniter() { \
+ SysLogInstance().ResetBackend(THolder<TLogBackend>( \
+ (ident) ? (TLogBackend*)(new TSysLogBackend((ident), (facility), (flags))) : (TLogBackend*)(new TNullLogBackend())));\
+ } \
+ } Y_CAT(loginit, __LINE__);
+
+#define YSYSLOGINIT(ident, facility) YSYSLOGINIT_FLAGS((ident), (facility), 0)
+
+class TSysLogBackend: public TLogBackend {
+public:
+ enum EFacility {
+ TSYSLOG_LOCAL0 = 0,
+ TSYSLOG_LOCAL1 = 1,
+ TSYSLOG_LOCAL2 = 2,
+ TSYSLOG_LOCAL3 = 3,
+ TSYSLOG_LOCAL4 = 4,
+ TSYSLOG_LOCAL5 = 5,
+ TSYSLOG_LOCAL6 = 6,
+ TSYSLOG_LOCAL7 = 7
+ };
+
+ enum EFlags {
+ LogPerror = 1,
+ LogCons = 2
+ };
+
+ TSysLogBackend(const char* ident, EFacility facility, int flags = 0);
+ ~TSysLogBackend() override;
+
+ void WriteData(const TLogRecord& rec) override;
+ void ReopenLog() override;
+
+ virtual TString GetIdent() const {
+ return Ident;
+ }
+
+ virtual EFacility GetFacility() const {
+ return Facility;
+ }
+
+ virtual int GetFlags() const {
+ return Flags;
+ }
+
+protected:
+ int ELogPriority2SyslogPriority(ELogPriority priority);
+
+ TString Ident;
+ EFacility Facility;
+ int Flags;
+};
+
+/*
+ * return system-wide logger instance
+ * better do not use in real programs(instead of robot, of course)
+ */
+TLog& SysLogInstance();