Add file, line & function information to journald log
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 28 Jan 2015 09:19:38 +0000 (10:19 +0100)
committerMaciej J. Karpiuk <m.karpiuk2@samsung.com>
Tue, 17 Feb 2015 11:09:37 +0000 (12:09 +0100)
[Issue#] N/A
[Feature/Bug] N/A
[Problem] File, line & function not visible in default journalctl log
[Cause] Default log format does not display this information and other formats
are unreadable
[Solution] File, line & function information added to log message content

[Verification] Create /etc/sysconfig/central-key-manager with following content
"
CKM_LOG_LEVEL=3
CKM_LOG_PROVIDER=JOURNALD
"

Restart the service and see if journalctl logs contain file, line & function
info:
journalctl -f -u central-key-manager

Change-Id: I01389eda9f7db390f6ca00c8f44e1a5c097e59c8

src/manager/dpl/log/src/journal_log_provider.cpp
src/manager/dpl/log/src/log.cpp

index b298b79..8f7af57 100644 (file)
@@ -52,18 +52,21 @@ void JournalLogProvider::Log(AbstractLogProvider::LogLevel level,
 {
     try {
         sd_journal_send("PRIORITY=%d", journalLevel.at(level),
-                        "CODE_FILE=%s", fileName,
-                        "CODE_FUNC=%s", function,
-                        "CODE_LINE=%d", line,
-                        "MESSAGE=%s", message,
-                        NULL);
+                "CODE_FILE=%s", fileName,
+                "CODE_FUNC=%s", function,
+                "CODE_LINE=%d", line,
+                // add file, line & function info to log message
+                "MESSAGE=[%s:%d] %s(): %s", fileName, line, function, message,
+                NULL);
     } catch (const std::out_of_range&) {
-        sd_journal_send("PRIORITY=%d", LOG_ERR,
-                        "CODE_FILE=%s", fileName,
-                        "CODE_FUNC=%s", function,
-                        "CODE_LINE=%d", line,
-                        "MESSAGE=Unsupported log level %d", level,
-                        NULL);
+        sd_journal_send(
+                "PRIORITY=%d", LOG_ERR,
+                "CODE_FILE=%s", fileName,
+                "CODE_FUNC=%s", function,
+                "CODE_LINE=%d", line,
+                // add file, line & function info to log message
+                "MESSAGE=[%s:%d] %s(): Unsupported log level %d", fileName, line, function, level,
+                NULL);
     }
 }
 
index 5bfaacb..6b5b8a1 100644 (file)
@@ -39,6 +39,14 @@ namespace CKM {
 namespace Log {
 namespace // anonymous
 {
+/*
+ * Set these variables to desired values in /etc/sysconfig/central-key-manager and restart
+ * central-key-manager service to use them.
+ *
+ * Example:
+ * CKM_LOG_LEVEL=3
+ * CKM_LOG_PROVIDER=JOURNALD
+ */
 const char * const CKM_LOG_LEVEL =      "CKM_LOG_LEVEL";
 const char * const CKM_LOG_PROVIDER =   "CKM_LOG_PROVIDER";