1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #ifdef ICE_USE_SYSTEMD
6 
7 #include <Ice/SystemdJournalI.h>
8 #include <Ice/LocalException.h>
9 #include <syslog.h>
10 #include <systemd/sd-journal.h>
11 
12 using namespace std;
13 using namespace Ice;
14 using namespace IceInternal;
15 
16 Ice::SystemdJournalI::SystemdJournalI(const string& prefix) :
17     _prefix(prefix)
18 {
19 }
20 
21 void
22 Ice::SystemdJournalI::print(const string& message)
23 {
24     write(LOG_INFO, message);
25 }
26 
27 void
28 Ice::SystemdJournalI::trace(const string& category, const string& message)
29 {
30     write(LOG_INFO, category + ": " + message);
31 }
32 
33 void
34 Ice::SystemdJournalI::warning(const string& message)
35 {
36     write(LOG_WARNING, message);
37 }
38 
39 void
40 Ice::SystemdJournalI::error(const string& message)
41 {
42     write(LOG_ERR, message);
43 }
44 
45 string
46 Ice::SystemdJournalI::getPrefix()
47 {
48     return _prefix;
49 }
50 
51 Ice::LoggerPtr
52 Ice::SystemdJournalI::cloneWithPrefix(const string& prefix)
53 {
54     return ICE_MAKE_SHARED(SystemdJournalI, prefix);
55 }
56 
57 void
58 Ice::SystemdJournalI::write(int priority, const string& message) const
59 {
60     sd_journal_send("MESSAGE=%s", message.c_str(),
61                     "PRIORITY=%i", priority,
62                     "SYSLOG_IDENTIFIER=%s", _prefix.c_str(),
63                     NULL); // Using NULL is necessary for EL7, see #293
64 }
65 
66 #endif
67