Merge lp:~mandel/ubuntu-download-manager/use-log-dir into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 240
Merged at revision: 243
Proposed branch: lp:~mandel/ubuntu-download-manager/use-log-dir
Merge into: lp:ubuntu-download-manager
Diff against target: 114 lines (+35/-11)
3 files modified
ubuntu-download-manager-priv/downloads/daemon.cpp (+17/-4)
ubuntu-download-manager-priv/system/logger.cpp (+17/-6)
ubuntu-download-manager-priv/system/logger.h (+1/-1)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/use-log-dir
Reviewer Review Type Date Requested Status
Mike McCracken (community) Abstain
PS Jenkins bot continuous-integration Approve
Diego Sarmentero (community) Approve
Review via email: mp+206051@code.launchpad.net

Commit message

Fix login and allow to pass the path via the command line.

Description of the change

Fix login and allow to pass the path via the command line.

To post a comment you must log in.
238. By Manuel de la Peña

Fix small logging issue.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
239. By Manuel de la Peña

Bump num.

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

this still names the file UNKNOWN.INFO

I looked into the glog source to see why - InitGoogleLogging() expects to be sent argv[0], which will always be around, so it just stores a pointer to it - it doesn't copy the string or take ownership or anything.

So I'm guessing that the QString you get from applicationName goes out of scope or something, before the filename is generated, and when it checks for the app name, it sees null and just goes with UNKNOWN. (see
https://code.google.com/p/google-glog/source/browse/trunk/src/utilities.cc#162 )

so maybe you need to hand it a heap allocated char array?

PS, I tried messing with it a bit to try to use -log-dir, and I couldn't get that to work, but I wasn't sure I was runnign it correctly. I just ran build/ubuntu-download-manager/ubuntu-download-manager -log-dir=/tmp/foo but it still used the default.

review: Needs Fixing
240. By Manuel de la Peña

Create the passed dir.

Revision history for this message
Manuel de la Peña (mandel) wrote :

On Thu, Feb 13, 2014 at 1:45 AM, Mike McCracken <
<email address hidden>> wrote:

> Review: Needs Fixing
>
> this still names the file UNKNOWN.INFO
>
> I looked into the glog source to see why - InitGoogleLogging() expects to
> be sent argv[0], which will always be around, so it just stores a pointer
> to it - it doesn't copy the string or take ownership or anything.
>
> So I'm guessing that the QString you get from applicationName goes out of
> scope or something, before the filename is generated, and when it checks
> for the app name, it sees null and just goes with UNKNOWN. (see
>
> https://code.google.com/p/google-glog/source/browse/trunk/src/utilities.cc#162)
>

I have tested the current code in the branch and it works in my system:

mandel@ironman:~/Desktop$ ubuntu-download-manager -log-dir
~/Desktop/udm-testing
^C
mandel@ironman:~/Desktop$ ls ~/Desktop/udm-testing/
ubuntu-download-manager.INFO
ubuntu-download-manager.log20140213-120124.20614
mandel@ironman:~/Desktop$

Can you please double check, I'm sure it is ok.

> so maybe you need to hand it a heap allocated char array?
>
> PS, I tried messing with it a bit to try to use -log-dir, and I couldn't
> get that to work, but I wasn't sure I was runnign it correctly. I just ran
> build/ubuntu-download-manager/ubuntu-download-manager -log-dir=/tmp/foo but
> it still used the default.
>

Sorry, that was a bug, the code was expecting to find the path and would
fall back in the default one. I have changed the code to create the path
when is possible, if the dir cannot be created (user rights etc..) it will
use the default one.

> --
>
> https://code.launchpad.net/~mandel/ubuntu-download-manager/use-log-dir/+merge/206051
> You are the owner of lp:~mandel/ubuntu-download-manager/use-log-dir.
>

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

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

abstain to unblock, I couldn't get it to work and don't have time to try again right now

review: Abstain

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu-download-manager-priv/downloads/daemon.cpp'
2--- ubuntu-download-manager-priv/downloads/daemon.cpp 2014-02-03 15:30:58 +0000
3+++ ubuntu-download-manager-priv/downloads/daemon.cpp 2014-02-13 11:02:05 +0000
4@@ -31,6 +31,7 @@
5 const QString DISABLE_TIMEOUT = "-disable-timeout";
6 const QString SELFSIGNED_CERT = "-self-signed-certs";
7 const QString STOPPABLE = "-stoppable";
8+ const QString LOG_DIR= "-log-dir";
9 }
10
11 namespace Ubuntu {
12@@ -161,8 +162,23 @@
13 private:
14 void parseCommandLine() {
15 QStringList args = _app->arguments();
16+ int index;
17+
18+ // set logging
19+ if (args.contains(LOG_DIR)) {
20+ index = args.indexOf(LOG_DIR);
21+ if (args.count() > index + 1) {
22+ auto logPath = args[index + 1];
23+ Logger::setupLogging(logPath);
24+ LOG(INFO) << "Log path is" << logPath;
25+ } else {
26+ LOG(ERROR) << "Missing log dir path.";
27+ Logger::setupLogging();
28+ }
29+ }
30+
31 if (args.contains(SELFSIGNED_CERT)) {
32- int index = args.indexOf(SELFSIGNED_CERT);
33+ index = args.indexOf(SELFSIGNED_CERT);
34 if (args.count() > index + 1) {
35 QString certsRegex = args[index + 1];
36 _certs = QSslCertificate::fromPath(certsRegex);
37@@ -200,9 +216,6 @@
38 q->connect(_downInterface,
39 SIGNAL(sizeChanged(int)), // NOLINT (readability/function)
40 q, SLOT(onDownloadManagerSizeChanged(int))); // NOLINT (readability/function)
41-
42- // set logging
43- Logger::setupLogging();
44 }
45
46 private:
47
48=== modified file 'ubuntu-download-manager-priv/system/logger.cpp'
49--- ubuntu-download-manager-priv/system/logger.cpp 2014-01-24 11:48:06 +0000
50+++ ubuntu-download-manager-priv/system/logger.cpp 2014-02-13 11:02:05 +0000
51@@ -25,7 +25,6 @@
52 #include <QStringList>
53 #include <QUrl>
54 #include <QSslError>
55-#include <syslog.h>
56 #include <sys/types.h>
57 #include <unistd.h>
58 #include "logger.h"
59@@ -64,6 +63,10 @@
60 return out;
61 }
62
63+namespace {
64+ const QString LOG_NAME = "ubuntu-download-manager.log";
65+}
66+
67 namespace Ubuntu {
68
69 namespace DownloadManager {
70@@ -73,18 +76,26 @@
71 static bool _init = false;
72
73 void
74-Logger::setupLogging(const QString filename) {
75- auto path = filename;
76- if (filename == "" ){
77- path = getLogDir() + "/ubuntu-download-manager.log";
78+Logger::setupLogging(const QString logDir) {
79+ auto path = logDir;
80+ if (path == "" ){
81+ path = getLogDir() + QDir::separator() + LOG_NAME;
82+ } else {
83+ bool wasCreated = QDir().mkpath(logDir);
84+ if (wasCreated) {
85+ path = QDir(logDir).absoluteFilePath(LOG_NAME);
86+ } else {
87+ qCritical() << "Could not create the logging path" << logDir;
88+ path = getLogDir() + QDir::separator() + LOG_NAME;
89+ }
90 }
91
92 auto appName = QCoreApplication::instance()->applicationName();
93
94- google::SetLogDestination(google::INFO, toStdString(path).c_str());
95 if (!_init) {
96 _init = true;
97 google::InitGoogleLogging(toStdString(appName).c_str());
98+ google::SetLogDestination(google::INFO, toStdString(path).c_str());
99 }
100 }
101
102
103=== modified file 'ubuntu-download-manager-priv/system/logger.h'
104--- ubuntu-download-manager-priv/system/logger.h 2014-01-28 16:03:24 +0000
105+++ ubuntu-download-manager-priv/system/logger.h 2014-02-13 11:02:05 +0000
106@@ -53,7 +53,7 @@
107
108 public:
109
110- static void setupLogging(const QString filename = "");
111+ static void setupLogging(const QString logDir= "");
112 static bool setLogLevel(QtMsgType level);
113 static QString getLogDir();
114 static std::string toStdString(const QString& str);

Subscribers

People subscribed via source and target branches