Merge lp:~mandel/ubuntu-download-manager/add-syslog into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 139
Merged at revision: 142
Proposed branch: lp:~mandel/ubuntu-download-manager/add-syslog
Merge into: lp:ubuntu-download-manager
Diff against target: 93 lines (+32/-7)
2 files modified
libubuntudownloadmanager/logger.cpp (+31/-6)
libubuntudownloadmanager/logger.h (+1/-1)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/add-syslog
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Alejandro J. Cura (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+187684@code.launchpad.net

Commit message

Use syslog when running as a system bus service rather than logging to a file.

Description of the change

Use syslog when running as a system bus service rather than logging to a file.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:138
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~mandel/ubuntu-download-manager/add-syslog/+merge/187684/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/ubuntu-download-manager-ci/88/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-download-manager-saucy-amd64-ci/88
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-download-manager-saucy-armhf-ci/79

Click here to trigger a rebuild:
http://s-jenkins:8080/job/ubuntu-download-manager-ci/88/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote :

+1

review: Approve
139. By Manuel de la Peña

Add comment to explain why we use %s

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntudownloadmanager/logger.cpp'
2--- libubuntudownloadmanager/logger.cpp 2013-09-23 11:50:04 +0000
3+++ libubuntudownloadmanager/logger.cpp 2013-09-27 21:37:04 +0000
4@@ -18,6 +18,7 @@
5
6 #include <unistd.h>
7 #include <sys/types.h>
8+#include <syslog.h>
9 #include <QDateTime>
10 #include <QDir>
11 #include <QStandardPaths>
12@@ -70,7 +71,8 @@
13
14 void
15 Logger::openSyslogConnection() {
16- // TODO(mandel): init syslog
17+ openlog("ubuntu-download-manager",
18+ LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
19 }
20
21 void
22@@ -82,7 +84,14 @@
23 void
24 Logger::stopLogging() {
25 if (_logger != NULL) {
26- delete reinterpret_cast<Logger*>(_logger);
27+ Logger* log = reinterpret_cast<Logger*>(_logger);
28+ if (log->_isSystemBus) {
29+ closelog();
30+ } else {
31+ log->_logFile.close();
32+ }
33+
34+ delete log;
35 _logger = NULL;
36 }
37 }
38@@ -125,14 +134,30 @@
39 }
40
41 void
42-Logger::logSessionMessage(const QString &message) {
43+Logger::logSessionMessage(const QString& message) {
44 _logStream << message;
45 _logStream.flush();
46 }
47
48 void
49-Logger::logSystemMessage(const QString &message) {
50- Q_UNUSED(message);
51+Logger::logSystemMessage(QtMsgType type, const QString& message) {
52+ const char* msg = message.toUtf8().data();
53+
54+ // we using %s to avoid getting a compiler error when using
55+ // -Wall
56+ switch (type) {
57+ case QtDebugMsg:
58+ syslog(LOG_DEBUG, "%s", msg);
59+ break;
60+ case QtCriticalMsg:
61+ syslog(LOG_CRIT, "%s", msg);
62+ break;
63+ case QtFatalMsg:
64+ syslog(LOG_ALERT, "%s", msg);
65+ break;
66+ default:
67+ break;
68+ }
69 }
70
71 void
72@@ -163,7 +188,7 @@
73 _stdErr.device()->close();
74
75 if (_isSystemBus) {
76- logSystemMessage(logMessage);
77+ logSystemMessage(type, logMessage);
78 } else {
79 logSessionMessage(logMessage);
80 }
81
82=== modified file 'libubuntudownloadmanager/logger.h'
83--- libubuntudownloadmanager/logger.h 2013-09-23 11:50:04 +0000
84+++ libubuntudownloadmanager/logger.h 2013-09-27 21:37:04 +0000
85@@ -51,7 +51,7 @@
86
87 void logSessionMessage(const QString &message);
88
89- void logSystemMessage(const QString &message);
90+ void logSystemMessage(QtMsgType type, const QString &message);
91
92 private:
93 bool _isSystemBus = false;

Subscribers

People subscribed via source and target branches