From Andrew Lindesay <apl@xxxxxxxxxxxxxx>:
Andrew Lindesay has uploaded this change for review. (
https://review.haiku-os.org/c/haiku/+/3018 ;)
Change subject: HaikuDepot: Better Logging
......................................................................
HaikuDepot: Better Logging
Changes the logging in HD to use a macro for the
various log levels to declutter the code and to
make it easier to more systematically log.
---
M src/apps/haikudepot/model/Captcha.cpp
M src/apps/haikudepot/model/LanguageModel.cpp
M src/apps/haikudepot/model/Logger.cpp
M src/apps/haikudepot/model/Logger.h
M src/apps/haikudepot/model/Model.cpp
M src/apps/haikudepot/model/PackageInfo.cpp
M src/apps/haikudepot/model/PackageManager.cpp
M src/apps/haikudepot/model/UserUsageConditions.cpp
M src/apps/haikudepot/server/AbstractProcess.cpp
M src/apps/haikudepot/server/AbstractServerProcess.cpp
M src/apps/haikudepot/server/AbstractSingleFileServerProcess.cpp
M src/apps/haikudepot/server/LocalPkgDataLoadProcess.cpp
M src/apps/haikudepot/server/LocalRepositoryUpdateProcess.cpp
M src/apps/haikudepot/server/ProcessCoordinator.cpp
M src/apps/haikudepot/server/ProcessCoordinatorFactory.cpp
M src/apps/haikudepot/server/ProcessNode.cpp
M src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp
M src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp
M src/apps/haikudepot/server/ServerReferenceDataUpdateProcess.cpp
M src/apps/haikudepot/server/ServerRepositoryDataUpdateProcess.cpp
M src/apps/haikudepot/server/ServerSettings.cpp
M src/apps/haikudepot/server/StandardMetaDataJsonEventListener.cpp
M src/apps/haikudepot/server/UserDetailVerifierProcess.cpp
M src/apps/haikudepot/server/WebAppInterface.cpp
M src/apps/haikudepot/tar/TarArchiveHeader.cpp
M src/apps/haikudepot/tar/TarArchiveService.cpp
M src/apps/haikudepot/ui/App.cpp
M src/apps/haikudepot/ui/FeaturedPackagesView.cpp
M src/apps/haikudepot/ui/MainWindow.cpp
M src/apps/haikudepot/ui/PackageContentsView.cpp
M src/apps/haikudepot/ui/PackageInfoView.cpp
M src/apps/haikudepot/ui/RatePackageWindow.cpp
M src/apps/haikudepot/ui/ScreenshotWindow.cpp
M src/apps/haikudepot/ui/ToLatestUserUsageConditionsWindow.cpp
M src/apps/haikudepot/ui/UserLoginWindow.cpp
M src/apps/haikudepot/ui/UserUsageConditionsWindow.cpp
M src/apps/haikudepot/ui_generic/SharedBitmap.cpp
M src/apps/haikudepot/util/LanguageMenuUtils.cpp
M src/apps/haikudepot/util/StorageUtils.cpp
M src/apps/haikudepot/util/ToFileUrlProtocolListener.cpp
40 files changed, 552 insertions(+), 610 deletions(-)
git pull ssh://git.haiku-os.org:22/haiku refs/changes/18/3018/1
diff --git a/src/apps/haikudepot/model/Captcha.cpp
b/src/apps/haikudepot/model/Captcha.cpp
index 4bf5022..8b3afda 100644
--- a/src/apps/haikudepot/model/Captcha.cpp
+++ b/src/apps/haikudepot/model/Captcha.cpp
@@ -1,14 +1,14 @@
/*
- * Copyright 2019, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2019-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
*
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "Captcha.h"
-#include <stdio.h>
-
#include <DataIO.h>
+#include "Logger.h"
+
// These are keys that are used to store this object's data into a BMessage
// instance.
@@ -22,15 +22,15 @@
fPngImageData(NULL)
{
if (from->FindString(KEY_TOKEN, &fToken) != B_OK) {
- printf("expected key [%s] in the message data when creating a "
- "Captcha\n", KEY_TOKEN);
+ HDERROR1("expected key [%s] in the message data when creating a
"
+ "captcha", KEY_TOKEN)
}
const void* data;
ssize_t len;
if (from->FindData(KEY_PNG_IMAGE_DATA, B_ANY_TYPE, &data, &len) != B_OK)
- printf("expected key [%s] in the message data\n",
KEY_PNG_IMAGE_DATA);
+ HDERROR1("expected key [%s] in the message data",
KEY_PNG_IMAGE_DATA)
else
SetPngImageData(data, len);
}
diff --git a/src/apps/haikudepot/model/LanguageModel.cpp
b/src/apps/haikudepot/model/LanguageModel.cpp
index 1bce38c..016d928 100644
--- a/src/apps/haikudepot/model/LanguageModel.cpp
+++ b/src/apps/haikudepot/model/LanguageModel.cpp
@@ -70,8 +70,7 @@
LanguageModel::_SetPreferredLanguage(const Language& language)
{
fPreferredLanguage = LanguageRef(new Language(language));
- if(Logger::IsDebugEnabled())
- printf("set preferred language [%s]\n", language.Code());
+ HDDEBUG1("set preferred language [%s]", language.Code())
}
@@ -98,11 +97,7 @@
LanguageModel::_DeriveDefaultLanguage() const
{
Language defaultLanguage = _DeriveSystemDefaultLanguage();
-
- if(Logger::IsDebugEnabled()) {
- printf("derived system default language [%s]\n",
- defaultLanguage.Code());
- }
+ HDDEBUG1("derived system default language [%s]", defaultLanguage.Code())
// if there are no supported languages; as is the case to start with as
the
// application starts, the default language from the system is used
anyway.
@@ -119,15 +114,15 @@
defaultLanguage.Code());
if (foundSupportedLanguage == NULL) {
- printf("unable to find the language [%s] - looking for app
default",
- defaultLanguage.Code());
+ HDERROR1("unable to find the language [%s] - looking for app
default",
+ defaultLanguage.Code())
foundSupportedLanguage = _FindSupportedLanguage(
LANGUAGE_DEFAULT.Code());
}
if (foundSupportedLanguage == NULL) {
- printf("unable to find the app default language - using the
first "
- "supported language");
+ HDERROR0("unable to find the app default language - using the
first "
+ "supported language")
foundSupportedLanguage = fSupportedLanguages.ItemAt(0);
}
diff --git a/src/apps/haikudepot/model/Logger.cpp
b/src/apps/haikudepot/model/Logger.cpp
index 78512bb..9256118 100644
--- a/src/apps/haikudepot/model/Logger.cpp
+++ b/src/apps/haikudepot/model/Logger.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2017, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2017-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "Logger.h"
@@ -22,7 +22,28 @@
}
-bool
+/*static*/
+const char*
+Logger::NameForLevel(log_level value)
+{
+ switch (value) {
+ case LOG_LEVEL_OFF:
+ return "off";
+ case LOG_LEVEL_INFO:
+ return "info";
+ case LOG_LEVEL_DEBUG:
+ return "debug";
+ case LOG_LEVEL_TRACE:
+ return "trace";
+ case LOG_LEVEL_ERROR:
+ return "error";
+ default:
+ return "?";
+ }
+}
+
+
+/*static*/ bool
Logger::SetLevelByName(const char *name)
{
if (strcmp(name, "off") == 0) {
@@ -33,6 +54,8 @@
fLevel = LOG_LEVEL_DEBUG;
} else if (strcmp(name, "trace") == 0) {
fLevel = LOG_LEVEL_TRACE;
+ } else if (strcmp(name, "error") == 0) {
+ fLevel = LOG_LEVEL_ERROR;
} else {
return false;
}
@@ -41,22 +64,30 @@
}
+/*static*/
+bool
+Logger::IsLevelEnabled(log_level value)
+{
+ return fLevel >= value;
+}
+
+
bool
Logger::IsInfoEnabled()
{
- return fLevel >= LOG_LEVEL_INFO;
+ return IsLevelEnabled(LOG_LEVEL_INFO);
}
bool
Logger::IsDebugEnabled()
{
- return fLevel >= LOG_LEVEL_DEBUG;
+ return IsLevelEnabled(LOG_LEVEL_DEBUG);
}
bool
Logger::IsTraceEnabled()
{
- return fLevel >= LOG_LEVEL_TRACE;
+ return IsLevelEnabled(LOG_LEVEL_TRACE);
}
\ No newline at end of file
diff --git a/src/apps/haikudepot/model/Logger.h
b/src/apps/haikudepot/model/Logger.h
index 95237cd..5b1049e 100644
--- a/src/apps/haikudepot/model/Logger.h
+++ b/src/apps/haikudepot/model/Logger.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2017, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2017-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef LOGGER_H
@@ -9,14 +9,76 @@
#include <File.h>
#include <Path.h>
-#include "PackageInfo.h"
+#include <ctype.h>
+#include <stdio.h>
+
+
+// These macros allow for standardized logging to be output. Depending on the
+// number of arguments to your "printf" format, you will use the appropriate
+// macro; for example HDINFO0 would be used for no arguments and HDINFO3 would
+// be used for a case where there is three arguments to the format.
+// The use of macros in this way means that the use of the log is concise where
+// it is used and also because the macro unwraps to a block contained with a
+// condition statement, if the log level is not sufficient to trigger the log
+// line then there is no computational cost to running over the log space.
This
+// is because the arguments will not be evaluated. Avoiding all of the
+// conditional clauses in the code to prevent this otherwise would be
+// cumbersome.
+
+#define HDLOGPREFIX(L) printf("{%c} ", toupper(Logger::NameForLevel(L)[0]));
+
+#define HDLOG0(L, M) if (Logger::IsLevelEnabled(L)) { \
+ printf("%c| %s\n", Logger::NameForLevel(L)[0], M); \
+}
+#define HDLOG1(L, M, A0) if (Logger::IsLevelEnabled(L)) { \
+ HDLOGPREFIX(L); \
+ printf(M, A0); \
+ printf("\n"); \
+}
+#define HDLOG2(L, M, A0, A1) if (Logger::IsLevelEnabled(L)) { \
+ HDLOGPREFIX(L); \
+ printf(M, A0, A1); \
+ printf("\n"); \
+}
+#define HDLOG3(L, M, A0, A1, A2) if (Logger::IsLevelEnabled(L)) { \
+ HDLOGPREFIX(L); \
+ printf(M, A0, A1, A2); \
+ printf("\n"); \
+}
+#define HDLOG4(L, M, A0, A1, A2, A3) if (Logger::IsLevelEnabled(L)) { \
+ HDLOGPREFIX(L); \
+ printf(M, A0, A1, A2, A3); \
+ printf("\n"); \
+}
+
+#define HDINFO0(M) HDLOG0(LOG_LEVEL_INFO, M)
+#define HDINFO1(M, A0) HDLOG1(LOG_LEVEL_INFO, M, A0)
+#define HDINFO2(M, A0, A1) HDLOG2(LOG_LEVEL_INFO, M, A0, A1)
+#define HDINFO3(M, A0, A1, A2) HDLOG3(LOG_LEVEL_INFO, M, A0, A1, A2)
+
+#define HDDEBUG0(M) HDLOG0(LOG_LEVEL_DEBUG, M)
+#define HDDEBUG1(M, A0) HDLOG1(LOG_LEVEL_DEBUG, M, A0)
+#define HDDEBUG2(M, A0, A1) HDLOG2(LOG_LEVEL_DEBUG, M, A0, A1)
+#define HDDEBUG3(M, A0, A1, A2) HDLOG3(LOG_LEVEL_DEBUG, M, A0, A1, A2)
+#define HDDEBUG4(M, A0, A1, A2, A3) HDLOG4(LOG_LEVEL_DEBUG, M, A0, A1, A2, A3)
+
+#define HDTRACE0(M) HDLOG0(LOG_LEVEL_TRACE, M)
+#define HDTRACE1(M, A0) HDLOG1(LOG_LEVEL_TRACE, M, A0)
+#define HDTRACE2(M, A0, A1) HDLOG2(LOG_LEVEL_TRACE, M, A0, A1)
+#define HDTRACE3(M, A0, A1, A2) HDLOG3(LOG_LEVEL_TRACE, M, A0, A1, A2)
+
+#define HDERROR0(M) HDLOG0(LOG_LEVEL_ERROR, M)
+#define HDERROR1(M, A0) HDLOG1(LOG_LEVEL_ERROR, M, A0)
+#define HDERROR2(M, A0, A1) HDLOG2(LOG_LEVEL_ERROR, M, A0, A1)
+#define HDERROR3(M, A0, A1, A2) HDLOG3(LOG_LEVEL_ERROR, M, A0, A1, A2)
typedef enum log_level {
LOG_LEVEL_OFF = 1,
- LOG_LEVEL_INFO = 2,
- LOG_LEVEL_DEBUG = 3,
- LOG_LEVEL_TRACE = 4
+ LOG_LEVEL_ERROR = 2,
+ LOG_LEVEL_INFO = 3,
+ LOG_LEVEL_DEBUG = 4,
+ LOG_LEVEL_TRACE = 5
} log_level;
@@ -26,6 +88,9 @@
static void SetLevel(log_level value);
static bool SetLevelByName(const char
*name);
+ static const char* NameForLevel(log_level value);
+
+ static bool IsLevelEnabled(log_level value);
static bool IsInfoEnabled();
static bool IsDebugEnabled();
static bool IsTraceEnabled();
diff --git a/src/apps/haikudepot/model/Model.cpp
b/src/apps/haikudepot/model/Model.cpp
index cf97979..4ca3441 100644
--- a/src/apps/haikudepot/model/Model.cpp
+++ b/src/apps/haikudepot/model/Model.cpp
@@ -9,7 +9,6 @@
#include <ctime>
#include <stdarg.h>
-#include <stdio.h>
#include <time.h>
#include <Autolock.h>
@@ -187,13 +186,9 @@
if (package.Get() == NULL)
return false;
- printf("TEST %s\n", package->Name().String());
-
for (int32 i = 0; i < fPackageLists.CountItems(); i++) {
- if (fPackageLists.ItemAtFast(i)->Contains(package)) {
- printf(" contained in %" B_PRId32 "\n", i);
+ if (fPackageLists.ItemAtFast(i)->Contains(package))
return false;
- }
}
return true;
}
@@ -649,8 +644,8 @@
BString code;
if (item.FindString("code", &code) !=
B_OK) {
- printf("corrupt user rating at
index %" B_PRIi32 "\n",
- index);
+ HDERROR1("corrupt user rating
at index %" B_PRIi32,
+ index)
continue;
}
@@ -658,8 +653,8 @@
BMessage userInfo;
if (item.FindMessage("user", &userInfo)
!= B_OK
||
userInfo.FindString("nickname", &user) != B_OK) {
- printf("ignored user rating
[%s] without a user "
- "nickname\n",
code.String());
+ HDERROR1("ignored user rating
[%s] without a user "
+ "nickname",
code.String())
continue;
}
@@ -672,8 +667,8 @@
if (item.FindDouble("rating", &rating)
!= B_OK)
rating = -1;
if (comment.Length() == 0 && rating ==
-1) {
- printf("rating [%s] has no
comment or rating so will be"
- "ignored\n",
code.String());
+ HDERROR1("rating [%s] has no
comment or rating so will"
+ " be ignored",
code.String())
continue;
}
@@ -717,22 +712,15 @@
comment, languageCode,
versionString,
(uint64) createTimestamp);
package->AddUserRating(userRating);
-
- if (Logger::IsDebugEnabled()) {
- printf("rating [%s] retrieved
from server\n",
- code.String());
- }
+ HDDEBUG1("rating [%s] retrieved from
server", code.String())
}
-
- if (Logger::IsDebugEnabled()) {
- printf("did retrieve %" B_PRIi32 " user
ratings for [%s]\n",
- index - 1,
packageName.String());
- }
+ HDDEBUG2("did retrieve %" B_PRIi32 " user
ratings for [%s]",
+ index - 1, packageName.String())
} else {
_MaybeLogJsonRpcError(info, "retrieve user
ratings");
}
} else {
- printf("unable to retrieve user ratings\n");
+ HDERROR0("unable to retrieve user ratings")
}
}
@@ -773,22 +761,16 @@
&& 0 != content.Length()) {
BAutolock locker(&fLock);
package->SetChangelog(content);
- if (Logger::IsDebugEnabled()) {
- fprintf(stdout, "changelog populated
for [%s]\n",
- packageName.String());
- }
+ HDDEBUG1("changelog populated for [%s]",
packageName.String())
} else {
- if (Logger::IsDebugEnabled()) {
- fprintf(stdout, "no changelog present
for [%s]\n",
- packageName.String());
- }
+ HDDEBUG1("no changelog present for [%s]",
packageName.String())
}
} else {
_MaybeLogJsonRpcError(info, "populate package
changelog");
}
} else {
- fprintf(stdout, "unable to obtain the changelog for the package"
- " [%s]\n", packageName.String());
+ HDERROR1("unable to obtain the changelog for the package [%s]",
+ packageName.String())
}
}
@@ -809,15 +791,15 @@
case B_OK:
result = keyStore.RemoveKey(kHaikuDepotKeyring, key);
if (result != B_OK) {
- printf("! error occurred when removing password
for nickname "
- "[%s] : %s\n", nickname.String(),
strerror(result));
+ HDERROR2("error occurred when removing password
for nickname "
+ "[%s] : %s", nickname.String(),
strerror(result))
}
break;
case B_ENTRY_NOT_FOUND:
return;
default:
- printf("! error occurred when finding password for
nickname "
- "[%s] : %s\n", nickname.String(),
strerror(result));
+ HDERROR2("error occurred when finding password for
nickname "
+ "[%s] : %s", nickname.String(),
strerror(result))
break;
}
}
@@ -956,7 +938,7 @@
"Screenshots", screenshotCachePath);
if (result != B_OK) {
- printf("[!] unable to get the screenshot dir - unable to
proceed");
+ HDERROR0("unable to get the screenshot dir - unable to proceed")
return;
}
@@ -1007,9 +989,9 @@
screenshotFile.Write(buffer.Buffer(),
buffer.BufferLength());
}
} else {
- fprintf(stderr, "Failed to retrieve screenshot for code '%s' "
- "at %" B_PRIi32 "x%" B_PRIi32 ".\n",
info.Code().String(),
- scaledWidth, scaledHeight);
+ HDERROR3("Failed to retrieve screenshot for code '%s' "
+ "at %" B_PRIi32 "x%" B_PRIi32 ".", info.Code().String(),
+ scaledWidth, scaledHeight)
}
}
@@ -1070,13 +1052,15 @@
const DepotInfo& depot = fDepots.ItemAt(i);
if (depot.WebAppRepositoryCode().Length() == 0) {
- printf("depot [%s]", depot.Name().String());
-
- if (depot.URL().Length() > 0)
- printf(" (%s)", depot.URL().String());
-
- printf(" correlates with no repository in the haiku"
- "depot server system\n");
+ if (depot.URL().Length() > 0) {
+ HDINFO2("depot [%s] (%s) correlates with no
repository in the"
+ " the haiku depot server system",
depot.Name().String(),
+ depot.URL().String())
+ }
+ else {
+ HDINFO1("depot [%s] correlates with no
repository in the"
+ " the haiku depot server system",
depot.Name().String())
+ }
}
}
}
@@ -1093,11 +1077,10 @@
if (responsePayload.FindMessage("error", &error) == B_OK
&& error.FindString("message", &errorMessage) == B_OK
&& error.FindDouble("code", &errorCode) == B_OK) {
- printf("[%s] --> error : [%s] (%f)\n", sourceDescription,
- errorMessage.String(), errorCode);
-
+ HDERROR3("[%s] --> error : [%s] (%f)", sourceDescription,
+ errorMessage.String(), errorCode)
} else {
- printf("[%s] --> an undefined error has occurred\n",
sourceDescription);
+ HDERROR1("[%s] --> an undefined error has occurred",
sourceDescription)
}
}
diff --git a/src/apps/haikudepot/model/PackageInfo.cpp
b/src/apps/haikudepot/model/PackageInfo.cpp
index 3fc39d3..76e0aab 100644
--- a/src/apps/haikudepot/model/PackageInfo.cpp
+++ b/src/apps/haikudepot/model/PackageInfo.cpp
@@ -7,13 +7,12 @@
#include "PackageInfo.h"
-#include <stdio.h>
-
#include <FindDirectory.h>
#include <package/PackageDefs.h>
#include <package/PackageFlags.h>
#include <Path.h>
+#include "Logger.h"
// #pragma mark - Language
@@ -1176,16 +1175,16 @@
}
}
if (!found) {
- printf("%s: new package: '%s'\n", fName.String(),
- otherPackage->Name().String());
+ HDINFO2("%s: new package: '%s'", fName.String(),
+ otherPackage->Name().String())
fPackages.Add(otherPackage);
}
}
for (int32 i = packages.CountItems() - 1; i >= 0; i--) {
const PackageInfoRef& package = packages.ItemAtFast(i);
- printf("%s: removing package: '%s'\n", fName.String(),
- package->Name().String());
+ HDINFO2("%s: removing package: '%s'", fName.String(),
+ package->Name().String())
fPackages.Remove(package);
}
}
diff --git a/src/apps/haikudepot/model/PackageManager.cpp
b/src/apps/haikudepot/model/PackageManager.cpp
index e84e704..4357a77 100644
--- a/src/apps/haikudepot/model/PackageManager.cpp
+++ b/src/apps/haikudepot/model/PackageManager.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2017, Haiku, Inc. All Rights Reserved.
+ * Copyright 2013-2020, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -7,13 +7,12 @@
* Stephan Aßmus <superstippi@xxxxxx>
* Rene Gollent <rene@xxxxxxxxxxx>
* Julian Harnath <julian.harnath@xxxxxxxxxxxxxx>
+ * Andrew Lindesay <apl@xxxxxxxxxxxxxx>
*/
#include "PackageManager.h"
-#include <stdio.h>
-
#include <Alert.h>
#include <Catalog.h>
#include <Entry.h>
@@ -36,6 +35,7 @@
#include "AutoDeleter.h"
#include "AutoLocker.h"
+#include "Logger.h"
#include "Model.h"
#include "PackageInfo.h"
#include "ProblemWindow.h"
@@ -163,19 +163,18 @@
ref->SetState(state);
return ex.Error();
} catch (BAbortedByUserException& ex) {
- fprintf(stderr, "Installation of package "
- "%s aborted by user: %s\n", packageNameString,
- ex.Message().String());
+ HDINFO2("Installation of package %s is aborted by user:
%s",
+ packageNameString, ex.Message().String())
_SetDownloadedPackagesState(NONE);
ref->SetState(state);
return B_OK;
} catch (BNothingToDoException& ex) {
- fprintf(stderr, "Nothing to do while installing package
"
- "%s: %s\n", packageNameString,
ex.Message().String());
+ HDINFO2("Nothing to do while installing package %s: %s",
+ packageNameString, ex.Message().String())
return B_OK;
} catch (BException& ex) {
- fprintf(stderr, "Exception occurred while installing
package "
- "%s: %s\n", packageNameString,
ex.Message().String());
+ HDERROR2("Exception occurred while installing package
%s: %s",
+ packageNameString, ex.Message().String())
_SetDownloadedPackagesState(NONE);
ref->SetState(state);
return B_ERROR;
@@ -291,8 +290,8 @@
} catch (BNothingToDoException& ex) {
return B_OK;
} catch (BException& ex) {
- fprintf(stderr, "Exception occurred while uninstalling
package "
- "%s: %s\n", packageName, ex.Message().String());
+ HDERROR2("Exception occurred while uninstalling package
%s: %s",
+ packageName, ex.Message().String())
ref->SetState(state);
return B_ERROR;
}
@@ -390,9 +389,9 @@
{
BString path = MakePath(entry);
if (path.FindFirst("data/deskbar/menu") == 0
- && entry->SymlinkPath() != NULL) {
- printf("found deskbar entry: %s -> %s\n", path.String(),
- entry->SymlinkPath());
+ && entry->SymlinkPath() != NULL) {
+ HDINFO2("found deskbar entry: %s -> %s",
+ path.String(), entry->SymlinkPath())
fDeskbarLinks.Add(DeskbarLink(path,
entry->SymlinkPath()));
}
return B_OK;
@@ -464,7 +463,7 @@
BPath path;
if (fDeskbarLink.link.FindFirst('/') == 0) {
status = path.SetTo(fDeskbarLink.link);
- printf("trying to launch (absolute link): %s\n",
path.Path());
+ HDINFO1("trying to launch (absolute link): %s",
path.Path())
} else {
int32 location = InstallLocation();
if (location == B_PACKAGE_INSTALLATION_LOCATION_SYSTEM)
{
@@ -484,7 +483,7 @@
status = path.GetParent(&path);
if (status == B_OK) {
status = path.Append(fDeskbarLink.link, true);
- printf("trying to launch: %s\n", path.Path());
+ HDINFO1("trying to launch: %s", path.Path())
}
}
@@ -518,8 +517,8 @@
return false;
}
} else {
- printf("OpenPackageAction::FindAppToLaunch(): "
- "unknown install location");
+ HDINFO0("OpenPackageAction::FindAppToLaunch(): "
+ "unknown install location")
return false;
}
@@ -530,9 +529,9 @@
status_t status = reader.Init(packagePath.Path());
if (status != B_OK) {
- printf("OpenPackageAction::FindAppToLaunch(): "
- "failed to init BPackageReader(%s): %s\n",
- packagePath.Path(), strerror(status));
+ HDINFO2("OpenPackageAction::FindAppToLaunch(): "
+ "failed to init BPackageReader(%s): %s",
+ packagePath.Path(), strerror(status))
return false;
}
@@ -540,9 +539,9 @@
DeskbarLinkFinder contentHandler(foundLinks);
status = reader.ParseContent(&contentHandler);
if (status != B_OK) {
- printf("OpenPackageAction::FindAppToLaunch(): "
- "failed parse package contents (%s): %s\n",
- packagePath.Path(), strerror(status));
+ HDINFO2("OpenPackageAction::FindAppToLaunch(): "
+ "failed parse package contents (%s): %s",
+ packagePath.Path(), strerror(status))
return false;
}
@@ -635,12 +634,12 @@
try {
result = BPackageManager::RefreshRepository(repoConfig);
} catch (BFatalErrorException& ex) {
- fprintf(stderr, "Fatal error occurred while refreshing
repository: "
- "%s (%s)\n", ex.Message().String(),
ex.Details().String());
+ HDERROR2("Fatal error occurred while refreshing repository: "
+ "%s (%s)", ex.Message().String(), ex.Details().String())
result = ex.Error();
} catch (BException& ex) {
- fprintf(stderr, "Exception occurred while refreshing "
- "repository: %s\n", ex.Message().String());
+ HDERROR1("Exception occurred while refreshing "
+ "repository: %s\n", ex.Message().String())
result = B_ERROR;
}
@@ -657,13 +656,13 @@
result = BPackageManager::DownloadPackage(fileURL, targetEntry,
checksum);
} catch (BFatalErrorException& ex) {
- fprintf(stderr, "Fatal error occurred while downloading
package: "
- "%s: %s (%s)\n", fileURL.String(),
ex.Message().String(),
- ex.Details().String());
+ HDERROR3("Fatal error occurred while downloading package: "
+ "%s: %s (%s)", fileURL.String(), ex.Message().String(),
+ ex.Details().String())
result = ex.Error();
} catch (BException& ex) {
- fprintf(stderr, "Exception occurred while downloading package "
- "%s: %s\n", fileURL.String(), ex.Message().String());
+ HDERROR2("Exception occurred while downloading package "
+ "%s: %s", fileURL.String(), ex.Message().String())
result = B_ERROR;
}
diff --git a/src/apps/haikudepot/model/UserUsageConditions.cpp
b/src/apps/haikudepot/model/UserUsageConditions.cpp
index d3008fd..77e19f7 100644
--- a/src/apps/haikudepot/model/UserUsageConditions.cpp
+++ b/src/apps/haikudepot/model/UserUsageConditions.cpp
@@ -1,11 +1,11 @@
/*
- * Copyright 2019, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2019-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
*
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "UserUsageConditions.h"
-#include <stdio.h>
+#include "Logger.h"
// These are keys that are used to store this object's data into a BMessage
// instance.
@@ -24,14 +24,14 @@
int16 minimumAge;
if (from->FindInt16(KEY_MINIMUM_AGE, &minimumAge) != B_OK)
- printf("expected key [%s] in the message data\n",
KEY_MINIMUM_AGE);
+ HDERROR1("expected key [%s] in the message data",
KEY_MINIMUM_AGE)
fMinimumAge = (uint8) minimumAge;
if (from->FindString(KEY_CODE, &fCode) != B_OK)
- printf("expected key [%s] in the message data\n", KEY_CODE);
+ HDERROR1("expected key [%s] in the message data", KEY_CODE)
if (from->FindString(KEY_COPY_MARKDOWN, &fCopyMarkdown) != B_OK)
- printf("expected key [%s] in the message data\n",
KEY_COPY_MARKDOWN);
+ HDERROR1("expected key [%s] in the message data",
KEY_COPY_MARKDOWN)
}
diff --git a/src/apps/haikudepot/server/AbstractProcess.cpp
b/src/apps/haikudepot/server/AbstractProcess.cpp
index 2316f50..bbd85b9 100644
--- a/src/apps/haikudepot/server/AbstractProcess.cpp
+++ b/src/apps/haikudepot/server/AbstractProcess.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2018, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2018-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "AbstractProcess.h"
@@ -47,12 +47,12 @@
AutoLocker<BLocker> locker(&fLock);
if (ProcessState() != PROCESS_INITIAL) {
- printf("cannot start process as it is not idle");
+ HDINFO0("cannot start process as it is not idle")
return B_NOT_ALLOWED;
}
if (fWasStopped) {
- printf("cannot start process as it was stopped");
+ HDINFO0("cannot start process as it was stopped")
return B_CANCELED;
}
@@ -62,7 +62,7 @@
status_t runResult = RunInternal();
if (runResult != B_OK)
- printf("[%s] an error has arisen; %s\n", Name(),
strerror(runResult));
+ HDERROR2("[%s] an error has arisen; %s", Name(),
strerror(runResult))
BReference<AbstractProcessListener> listener;
diff --git a/src/apps/haikudepot/server/AbstractServerProcess.cpp
b/src/apps/haikudepot/server/AbstractServerProcess.cpp
index c6cd574..58a8f8b 100644
--- a/src/apps/haikudepot/server/AbstractServerProcess.cpp
+++ b/src/apps/haikudepot/server/AbstractServerProcess.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2018, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2017-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
@@ -122,9 +122,9 @@
headerValue.SetTo(modifiedHttpTime
.ToString(BPrivate::B_HTTP_TIME_FORMAT_COOKIE));
} else {
- fprintf(stderr, "unable to parse the meta-data date and time
from [%s]"
- " - cannot set the 'If-Modified-Since' header\n",
- metaDataPath.Path());
+ HDERROR1("unable to parse the meta-data date and time from [%s]"
+ " - cannot set the 'If-Modified-Since' header",
+ metaDataPath.Path())
}
return result;
@@ -148,8 +148,8 @@
return result;
if (!metaData.IsPopulated()) {
- fprintf(stderr, "the meta data was read from [%s], but no
values "
- "were extracted\n", path.Path());
+ HDERROR1("the meta data was read from [%s], but no values "
+ "were extracted", path.Path())
return B_BAD_DATA;
}
@@ -179,8 +179,8 @@
FILE* file = fopen(pathStr, "rb");
if (file == NULL) {
- printf("[%s] unable to find the meta data file at [%s]\n",
Name(),
- path.Path());
+ HDERROR2("[%s] unable to find the meta data file at [%s]",
Name(),
+ path.Path())
return B_FILE_NOT_FOUND;
}
@@ -240,8 +240,8 @@
if (result == B_OK && hasFile && size > 0) {
if (rename(temporaryFilePath.Path(),
targetFilePath.Path()) != 0) {
- printf("[%s] did rename [%s] --> [%s]\n",
- Name(), temporaryFilePath.Path(),
targetFilePath.Path());
+ HDINFO3("[%s] did rename [%s] --> [%s]",
+ Name(), temporaryFilePath.Path(),
targetFilePath.Path())
result = B_IO_ERROR;
}
}
@@ -259,18 +259,18 @@
return B_CANCELED;
if (redirects > MAX_REDIRECTS) {
- printf("[%s] exceeded %d redirects --> failure\n", Name(),
- MAX_REDIRECTS);
+ HDINFO2("[%s] exceeded %d redirects --> failure", Name(),
+ MAX_REDIRECTS)
return B_IO_ERROR;
}
if (failures > MAX_FAILURES) {
- printf("[%s] exceeded %d failures\n", Name(), MAX_FAILURES);
+ HDINFO2("[%s] exceeded %d failures", Name(), MAX_FAILURES)
return B_IO_ERROR;
}
- printf("[%s] will stream '%s' to [%s]\n", Name(),
url.UrlString().String(),
- targetFilePath.Path());
+ HDINFO3("[%s] will stream '%s' to [%s]", Name(),
url.UrlString().String(),
+ targetFilePath.Path())
ToFileUrlProtocolListener listener(targetFilePath, Name(),
Logger::IsTraceEnabled());
@@ -314,12 +314,12 @@
fRequest = NULL;
if (BHttpRequest::IsSuccessStatusCode(statusCode)) {
- fprintf(stdout, "[%s] did complete streaming data [%"
- B_PRIdSSIZE " bytes]\n", Name(),
listener.ContentLength());
+ HDINFO2("[%s] did complete streaming data [%"
+ B_PRIdSSIZE " bytes]", Name(), listener.ContentLength())
return B_OK;
} else if (statusCode == B_HTTP_STATUS_NOT_MODIFIED) {
- fprintf(stdout, "[%s] remote data has not changed since [%s]\n",
- Name(), ifModifiedSinceHeader.String());
+ HDINFO2("[%s] remote data has not changed since [%s]", Name(),
+ ifModifiedSinceHeader.String())
return HD_ERR_NOT_MODIFIED;
} else if (statusCode == B_HTTP_STATUS_PRECONDITION_FAILED) {
ServerHelper::NotifyClientTooOld(responseHeaders);
@@ -327,25 +327,24 @@
} else if (BHttpRequest::IsRedirectionStatusCode(statusCode)) {
if (location.Length() != 0) {
BUrl redirectUrl(result.Url(), location);
- fprintf(stdout, "[%s] will redirect to; %s\n",
- Name(), redirectUrl.UrlString().String());
+ HDINFO2("[%s] will redirect to; %s",
+ Name(), redirectUrl.UrlString().String())
return DownloadToLocalFile(targetFilePath, redirectUrl,
redirects + 1, 0);
}
- fprintf(stdout, "[%s] unable to find 'Location' header for
redirect\n",
- Name());
+ HDERROR1("[%s] unable to find 'Location' header for redirect",
Name())
return B_IO_ERROR;
} else {
if (statusCode == 0 || (statusCode / 100) == 5) {
- fprintf(stdout, "error response from server [%"
B_PRId32 "] --> "
- "retry...\n", statusCode);
+ HDERROR1("error response from server [%" B_PRId32 "]
--> retry...",
+ statusCode)
return DownloadToLocalFile(targetFilePath, url,
redirects,
failures + 1);
}
- fprintf(stdout, "[%s] unexpected response from server [%"
B_PRId32 "]\n",
- Name(), statusCode);
+ HDERROR2("[%s] unexpected response from server [%" B_PRId32 "]",
+ Name(), statusCode)
return B_IO_ERROR;
}
}
@@ -378,13 +377,13 @@
damagedFilePath.Append(damagedLeaf.String());
if (0 != rename(currentFilePath.Path(), damagedFilePath.Path())) {
- printf("[%s] unable to move damaged file [%s] aside to [%s]\n",
- Name(), currentFilePath.Path(), damagedFilePath.Path());
+ HDERROR3("[%s] unable to move damaged file [%s] aside to [%s]",
+ Name(), currentFilePath.Path(), damagedFilePath.Path())
return B_IO_ERROR;
}
- printf("[%s] did move damaged file [%s] aside to [%s]\n",
- Name(), currentFilePath.Path(), damagedFilePath.Path());
+ HDINFO3("[%s] did move damaged file [%s] aside to [%s]",
+ Name(), currentFilePath.Path(), damagedFilePath.Path())
return B_OK;
}
diff --git a/src/apps/haikudepot/server/AbstractSingleFileServerProcess.cpp
b/src/apps/haikudepot/server/AbstractSingleFileServerProcess.cpp
index 1bd16f0..2e8b189 100644
--- a/src/apps/haikudepot/server/AbstractSingleFileServerProcess.cpp
+++ b/src/apps/haikudepot/server/AbstractSingleFileServerProcess.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2018, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2017-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
@@ -29,9 +29,7 @@
status_t
AbstractSingleFileServerProcess::RunInternal()
{
- if (Logger::IsInfoEnabled())
- printf("[%s] will fetch data\n", Name());
-
+ HDINFO1("[%s] will fetch data", Name())
BPath localPath;
status_t result = GetLocalPath(localPath);
@@ -58,15 +56,14 @@
if (!IsSuccess(result)) {
if (hasData) {
- printf("[%s] failed to update data, but have
old data "
- "anyway so carry on with that\n",
Name());
+ HDINFO1("[%s] failed to update data, but have
old data "
+ "anyway so carry on with that", Name())
result = B_OK;
} else {
- printf("[%s] failed to obtain data\n", Name());
+ HDERROR1("[%s] failed to obtain data", Name())
}
} else {
- if (Logger::IsInfoEnabled())
- printf("[%s] did fetch data\n", Name());
+ HDINFO1("[%s] did fetch data", Name())
}
}
@@ -81,12 +78,12 @@
}
if (IsSuccess(result)) {
- printf("[%s] will process data\n", Name());
+ HDINFO1("[%s] will process data", Name())
result = ProcessLocalData();
switch (result) {
case B_OK:
- printf("[%s] did process data\n", Name());
+ HDINFO1("[%s] did process data", Name())
break;
default:
MoveDamagedFileAside(localPath);
diff --git a/src/apps/haikudepot/server/LocalPkgDataLoadProcess.cpp
b/src/apps/haikudepot/server/LocalPkgDataLoadProcess.cpp
index 55e89e7..ab542bf 100644
--- a/src/apps/haikudepot/server/LocalPkgDataLoadProcess.cpp
+++ b/src/apps/haikudepot/server/LocalPkgDataLoadProcess.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2018, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2018-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
@@ -89,9 +89,7 @@
status_t
LocalPkgDataLoadProcess::RunInternal()
{
- if (Logger::IsDebugEnabled())
- printf("[%s] will refresh the package list\n", Name());
-
+ HDDEBUG1("[%s] will refresh the package list", Name())
BPackageRoster roster;
BStringList repositoryNames;
@@ -111,16 +109,12 @@
if (getRepositoryConfigStatus == B_OK) {
depotInfo.SetURL(repoConfig.Identifier());
-
- if (Logger::IsDebugEnabled()) {
- printf("[%s] local repository [%s] info;\n"
- " * url [%s]\n", Name(),
repoName.String(),
- repoConfig.Identifier().String());
- }
+ HDDEBUG3("[%s] local repository [%s] identifier; [%s]",
+ Name(), repoName.String(),
repoConfig.Identifier().String())
} else {
- printf("[%s] unable to obtain the repository config for
local "
- "repository '%s'; %s\n", Name(),
- repoName.String(),
strerror(getRepositoryConfigStatus));
+ HDINFO3("[%s] unable to obtain the repository config
for local "
+ "repository '%s'; %s", Name(),
+ repoName.String(),
strerror(getRepositoryConfigStatus))
}
depots[i] = depotInfo;
@@ -226,18 +220,12 @@
}
if (it == depots.end()) {
- if (Logger::IsDebugEnabled()) {
- printf("pkg [%s] repository [%s] not
recognized"
- " --> ignored\n",
- modelInfo->Name().String(),
repositoryName.String());
- }
+ HDDEBUG2("pkg [%s] repository [%s] not
recognized --> ignored",
+ modelInfo->Name().String(),
repositoryName.String())
} else {
it->AddPackage(modelInfo);
-
- if (Logger::IsTraceEnabled()) {
- printf("pkg [%s] assigned to [%s]\n",
- modelInfo->Name().String(),
repositoryName.String());
- }
+ HDTRACE2("pkg [%s] assigned to [%s]",
+ modelInfo->Name().String(),
repositoryName.String());
}
remotePackages[modelInfo->Name()] = modelInfo;
@@ -363,20 +351,19 @@
}
}
} catch (BFatalErrorException& ex) {
- printf("Fatal exception occurred while resolving system
dependencies: "
- "%s, details: %s\n", strerror(ex.Error()),
ex.Details().String());
+ HDERROR2("Fatal exception occurred while resolving system
dependencies: "
+ "%s, details: %s", strerror(ex.Error()),
ex.Details().String())
} catch (BNothingToDoException&) {
// do nothing
} catch (BException& ex) {
- printf("Exception occurred while resolving system dependencies:
%s\n",
- ex.Message().String());
+ HDERROR1("Exception occurred while resolving system
dependencies: %s",
+ ex.Message().String())
} catch (...) {
- printf("Unknown exception occurred while resolving system "
- "dependencies.\n");
+ HDERROR0("Unknown exception occurred while resolving system "
+ "dependencies.")
}
- if (Logger::IsDebugEnabled())
- printf("did refresh the package list\n");
+ HDDEBUG0("did refresh the package list")
return B_OK;
}
@@ -385,8 +372,8 @@
void
LocalPkgDataLoadProcess::_NotifyError(const BString& messageText) const
{
- printf("an error has arisen loading data of packages from local : %s\n",
- messageText.String());
+ HDERROR1("an error has arisen loading data of packages from local : %s",
+ messageText.String())
AppUtils::NotifySimpleError(
B_TRANSLATE("Local repository load error"),
messageText);
diff --git a/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.cpp
b/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.cpp
index 9804599..1c809fe 100644
--- a/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.cpp
+++ b/src/apps/haikudepot/server/LocalRepositoryUpdateProcess.cpp
@@ -66,10 +66,7 @@
{
BPackageRoster roster;
BStringList repoNames;
-
- if (Logger::IsInfoEnabled()) {
- printf("[%s] will update local repositories' caches\n", Name());
- }
+ HDINFO1("[%s] will update local repositories' caches", Name())
status_t result = roster.GetRepositoryNames(repoNames);
@@ -91,9 +88,9 @@
result = B_ERROR;
}
- if (result == B_OK && Logger::IsInfoEnabled()) {
- printf("[%s] did update %" B_PRIi32 " local repositories'
caches\n",
- Name(), repoNames.CountStrings());
+ if (result == B_OK) {
+ HDINFO2("[%s] did update %" B_PRIi32 " local repositories'
caches",
+ Name(), repoNames.CountStrings())
}
return result;
@@ -106,34 +103,25 @@
BPackageKit::BRepositoryCache* cache)
{
if (fForce) {
- if (Logger::IsInfoEnabled()) {
- printf("[%s] am refreshing cache for repo [%s] as it
was forced\n",
- Name(), repoName.String());
- }
+ HDINFO2("[%s] am refreshing cache for repo [%s] as it was
forced",
+ Name(), repoName.String())
return true;
}
if (roster.GetRepositoryCache(repoName, cache) != B_OK) {
- if (Logger::IsInfoEnabled()) {
- printf("[%s] am updating cache for repo [%s] as there
was no"
- " cache\n", Name(), repoName.String());
- }
+ HDINFO2("[%s] am updating cache for repo [%s] as there was no
cache",
+ Name(), repoName.String())
return true;
}
if (static_cast<App*>(be_app)->IsFirstRun()) {
- if (Logger::IsInfoEnabled()) {
- printf("[%s] am updating cache for repo [%s] as this is
the first"
- " time that the application has run\n", Name(),
- repoName.String());
- }
+ HDINFO2("[%s] am updating cache for repo [%s] as this is the
first"
+ " time that the application has run", Name(),
repoName.String())
return true;
}
- if (Logger::IsDebugEnabled()) {
- printf("[%s] skipped update local repo [%s] cache\n", Name(),
- repoName.String());
- }
+ HDDEBUG2("[%s] skipped update local repo [%s] cache", Name(),
+ repoName.String())
return false;
}
@@ -152,10 +140,8 @@
try {
BRefreshRepositoryRequest
refreshRequest(context, repoConfig);
result = refreshRequest.Process();
- if (Logger::IsInfoEnabled()) {
- printf("[%s] did update local repo [%s]
cache\n", Name(),
- repoName.String());
- }
+ HDINFO2("[%s] did update local repo [%s]
cache", Name(),
+ repoName.String());
result = B_OK;
} catch (BFatalErrorException& ex) {
_NotifyError(ex.Message(), ex.Details());
@@ -182,8 +168,8 @@
LocalRepositoryUpdateProcess::_NotifyError(const BString& error,
const BString& details) const
{
- printf("an error has arisen updating the local repositories : %s\n",
- error.String());
+ HDINFO1("an error has arisen updating the local repositories : %s",
+ error.String())
BString alertText(B_TRANSLATE("An error occurred while refreshing the "
"repository: %error%"));
diff --git a/src/apps/haikudepot/server/ProcessCoordinator.cpp
b/src/apps/haikudepot/server/ProcessCoordinator.cpp
index dad63c7..52b8248 100644
--- a/src/apps/haikudepot/server/ProcessCoordinator.cpp
+++ b/src/apps/haikudepot/server/ProcessCoordinator.cpp
@@ -142,13 +142,16 @@
AutoLocker<BLocker> locker(&fLock);
if (!fWasStopped) {
fWasStopped = true;
- printf("[Coordinator] will stop process coordinator\n");
+ HDINFO0("[Coordinator] will stop process coordinator")
for (int32 i = 0; i < fNodes.CountItems(); i++) {
ProcessNode* node = fNodes.ItemAt(i);
- printf("[%s] stopping process",
node->Process()->Name());
- if (node->Process()->ErrorStatus() != B_OK)
- printf(" (error)\n");
- printf("\n");
+ if (node->Process()->ErrorStatus() != B_OK) {
+ HDINFO1("[Coordinator] stopping process [%s]
(owing to error)",
+ node->Process()->Name());
+ } else {
+ HDINFO1("[Coordinator] stopping process [%s]",
+ node->Process()->Name());
+ }
node->StopProcess();
}
}
@@ -260,11 +263,8 @@
ProcessCoordinatorState
ProcessCoordinator::_Coordinate()
{
- if (Logger::IsTraceEnabled())
- printf("[Coordinator] will coordinate nodes\n");
-
+ HDTRACE0("[Coordinator] will coordinate nodes")
AutoLocker<BLocker> locker(&fLock);
-
_StopSuccessorNodesToErroredOrStoppedNodes();
// go through the nodes and find those that are still to be run and
@@ -276,16 +276,12 @@
if (node->AllPredecessorsComplete())
node->StartProcess();
else {
- if (Logger::IsTraceEnabled()) {
- printf("[Coordinator] all predecessors
not complete -> "
- "[%s] not started\n",
node->Process()->Name());
- }
+ HDTRACE1("[Coordinator] all predecessors not
complete -> "
+ "[%s] not started",
node->Process()->Name());
}
} else {
- if (Logger::IsTraceEnabled()) {
- printf("[Coordinator] process [%s] running or
complete\n",
- node->Process()->Name());
- }
+ HDTRACE1("[Coordinator] process [%s] running or
complete",
+ node->Process()->Name());
}
}
@@ -318,10 +314,8 @@
AbstractProcess* process = node->Process();
if (process->ProcessState() == PROCESS_INITIAL) {
- if (Logger::IsDebugEnabled()) {
- printf("[Coordinator] [%s] (failed) --> [%s]
(stopping)\n",
- predecessorNode->Process()->Name(),
process->Name());
- }
+ HDDEBUG2("[Coordinator] [%s] (failed) --> [%s]
(stopping)",
+ predecessorNode->Process()->Name(),
process->Name())
node->StopProcess();
_StopSuccessorNodes(node);
}
diff --git a/src/apps/haikudepot/server/ProcessCoordinatorFactory.cpp
b/src/apps/haikudepot/server/ProcessCoordinatorFactory.cpp
index dfe4246..5a8fae6 100644
--- a/src/apps/haikudepot/server/ProcessCoordinatorFactory.cpp
+++ b/src/apps/haikudepot/server/ProcessCoordinatorFactory.cpp
@@ -16,6 +16,7 @@
#include "HaikuDepotConstants.h"
#include "LocalPkgDataLoadProcess.h"
#include "LocalRepositoryUpdateProcess.h"
+#include "Logger.h"
#include "Model.h"
#include "PackageInfoListener.h"
#include "ProcessCoordinator.h"
@@ -114,7 +115,7 @@
processCoordinator->AddNode(processNode);
}
} else {
- printf("a problem has arisen getting the repository
names.\n");
+ HDERROR0("a problem has arisen getting the repository
names.")
}
}
@@ -128,8 +129,8 @@
uint32 processOptions = 0;
if (ServerSettings::IsClientTooOld()) {
- printf("bulk load proceeding without network communications "
- "because the client is too old\n");
+ HDINFO0("bulk load proceeding without network communications "
+ "because the client is too old")
processOptions |= SERVER_PROCESS_NO_NETWORKING;
}
diff --git a/src/apps/haikudepot/server/ProcessNode.cpp
b/src/apps/haikudepot/server/ProcessNode.cpp
index edabc20..acf8119 100644
--- a/src/apps/haikudepot/server/ProcessNode.cpp
+++ b/src/apps/haikudepot/server/ProcessNode.cpp
@@ -58,8 +58,8 @@
usleep(SPIN_UNTIL_STARTED_DELAY_MI);
if (real_time_clock() - start > timeoutSeconds) {
- printf("[Node<%s>] timeout waiting for process state\n",
- Process()->Name());
+ HDERROR1("[Node<%s>] timeout waiting for process state",
+ Process()->Name())
return B_ERROR;
}
}
@@ -75,8 +75,7 @@
if (fWorker != B_BAD_THREAD_ID)
return B_BUSY;
- if (Logger::IsInfoEnabled())
- printf("[Node<%s>] initiating\n", Process()->Name());
+ HDINFO1("[Node<%s>] initiating", Process()->Name())
fWorker = spawn_thread(&_StartProcess, Process()->Name(),
B_NORMAL_PRIORITY, Process());
@@ -106,8 +105,8 @@
// down.
if (waitResult != B_OK) {
- printf("[%s] process did not stop within timeout - will be
stopped "
- "uncleanly", Process()->Name());
+ HDINFO1("[%s] process did not stop within timeout - will be
stopped "
+ "uncleanly", Process()->Name())
kill_thread(fWorker);
}
@@ -130,9 +129,7 @@
{
AbstractProcess* process = static_cast<AbstractProcess*>(cookie);
- if (Logger::IsInfoEnabled()) {
- printf("[Node<%s>] starting process\n", process->Name());
- }
+ HDINFO1("[Node<%s>] starting process", process->Name())
process->Run();
return B_OK;
diff --git a/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp
b/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp
index d1d59d1..4222504 100644
--- a/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp
+++ b/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp
@@ -1,12 +1,11 @@
/*
- * Copyright 2017-2018, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2017-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "ServerIconExportUpdateProcess.h"
-#include <stdio.h>
#include <sys/stat.h>
#include <time.h>
@@ -40,7 +39,7 @@
{
AutoLocker<BLocker> locker(fModel->Lock());
if (fModel->IconStoragePath(fLocalIconStoragePath) != B_OK) {
- printf("[%s] unable to obtain the path for storing icons\n",
Name());
+ HDINFO1("[%s] unable to obtain the path for storing icons",
Name())
fLocalIconStoragePath.Unset();
fLocalIconStore = NULL;
} else {
@@ -116,10 +115,8 @@
depots = fModel->Depots();
}
- if (Logger::IsDebugEnabled()) {
- printf("[%s] will populate icons for %" B_PRId32 " depots\n",
Name(),
- depots.CountItems());
- }
+ HDDEBUG2("[%s] will populate icons for %" B_PRId32 " depots", Name(),
+ depots.CountItems())
for (int32 i = 0;
(i < depots.CountItems()) && !WasStopped() && (result == B_OK);
@@ -131,8 +128,8 @@
if (Logger::IsInfoEnabled()) {
double secs = watch.ElapsedTime() / 1000000.0;
- printf("[%s] did populate %" B_PRId32 " packages' icons (%6.3g
secs)\n",
- Name(), fCountIconsSet, secs);
+ HDINFO3("[%s] did populate %" B_PRId32 " packages' icons (%6.3g
secs)",
+ Name(), fCountIconsSet, secs)
}
return result;
@@ -144,8 +141,8 @@
status_t
ServerIconExportUpdateProcess::PopulateForDepot(const DepotInfo& depot)
{
- printf("[%s] will populate icons for depot [%s]\n",
- Name(), depot.Name().String());
+ HDINFO2("[%s] will populate icons for depot [%s]",
+ Name(), depot.Name().String())
status_t result = B_OK;
const PackageList& packages = depot.Packages();
for(int32 j = 0;
@@ -176,20 +173,16 @@
BitmapRef
bitmapRef(new(std::nothrow)SharedBitmap(bestIconFile), true);
package->SetIcon(bitmapRef);
- if (Logger::IsDebugEnabled()) {
- printf("[%s] have set the package icon for [%s] from
[%s]\n",
- Name(), package->Name().String(),
bestIconPath.Path());
- }
+ HDDEBUG3("[%s] have set the package icon for [%s] from [%s]",
+ Name(), package->Name().String(), bestIconPath.Path())
fCountIconsSet++;
return B_OK;
}
- if (Logger::IsDebugEnabled()) {
- printf("[%s] did not set the package icon for [%s]; no data\n",
- Name(), package->Name().String());
- }
+ HDDEBUG2("[%s] did not set the package icon for [%s]; no data",
+ Name(), package->Name().String())
return B_FILE_NOT_FOUND;
}
@@ -201,13 +194,13 @@
BPath tarGzFilePath(tmpnam(NULL));
status_t result = B_OK;
- printf("[%s] will start fetching icons\n", Name());
+ HDINFO1("[%s] will start fetching icons", Name())
result = _Download(tarGzFilePath);
switch (result) {
case HD_ERR_NOT_MODIFIED:
- printf("[%s] icons not modified - will use existing\n",
Name());
+ HDINFO1("[%s] icons not modified - will use existing",
Name())
return result;
break;
case B_OK:
@@ -231,14 +224,14 @@
if (result == B_OK) {
if (hasData) {
- printf("[%s] failed to update data, but have old data
anyway "
- "so will carry on with that\n", Name());
+ HDINFO1("[%s] failed to update data, but have old data
anyway "
+ "so will carry on with that", Name())
} else {
- printf("[%s] failed to obtain data\n", Name());
+ HDINFO1("[%s] failed to obtain data", Name())
result = HD_ERR_NO_DATA;
}
} else {
- printf("[%s] unable to detect if there is local data\n",
Name());
+ HDERROR1("[%s] unable to detect if there is local data\n",
Name())
}
return result;
@@ -253,7 +246,7 @@
ServerIconExportUpdateProcess::_Unpack(BPath& tarGzFilePath)
{
status_t result;
- printf("[%s] delete any existing stored data\n", Name());
+ HDINFO1("[%s] delete any existing stored data", Name())
StorageUtils::RemoveDirectoryContents(fLocalIconStoragePath);
BFile *tarGzFile = new BFile(tarGzFilePath.Path(), O_RDONLY);
@@ -276,18 +269,17 @@
if (result == B_OK) {
double secs = watch.ElapsedTime() / 1000000.0;
- printf("[%s] did unpack icon tgz in (%6.3g secs)\n",
Name(),
- secs);
+ HDINFO2("[%s] did unpack icon tgz in (%6.3g secs)",
Name(), secs)
if (0 != remove(tarGzFilePath.Path())) {
- printf("unable to delete the temporary tgz
path; %s\n",
- tarGzFilePath.Path());
+ HDERROR2("[%s] unable to delete the temporary
tgz path; %s",
+ Name(), tarGzFilePath.Path())
}
}
}
delete tarGzFile;
- printf("[%s] did complete unpacking icons\n", Name());
+ HDINFO1("[%s] did complete unpacking icons", Name())
return result;
}
diff --git a/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp
b/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp
index ed62557..d6b8909 100644
--- a/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp
+++ b/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp
@@ -143,8 +143,8 @@
int categoryIndex = IndexOfCategoryByCode(*(categoryCode));
if (categoryIndex == -1) {
- printf("unable to find the category for [%s]\n",
- categoryCode->String());
+ HDERROR1("unable to find the category for [%s]",
+ categoryCode->String())
} else {
package->AddCategory(
fCategories.ItemAtFast(categoryIndex));
@@ -176,10 +176,8 @@
));
}
- if (fDebugEnabled) {
- printf("did populate data for [%s] (%s)\n",
pkg->Name()->String(),
- fDepotName.String());
- }
+ HDDEBUG2("did populate data for [%s] (%s)", pkg->Name()->String(),
+ fDepotName.String())
fCount++;
@@ -213,12 +211,12 @@
AutoLocker<BLocker> locker(fModel->Lock());
ConsumePackage(packageInfoRef, pkg);
} else {
- printf("[PackageFillingPkgListener] unable to find the
pkg [%s]\n",
- packageName.String());
+ HDINFO1("[PackageFillingPkgListener] unable to find the
pkg [%s]",
+ packageName.String())
}
} else {
- printf("[PackageFillingPkgListener] unable to find the depot
[%s]\n",
- fDepotName.String());
+ HDINFO1("[PackageFillingPkgListener] unable to find the depot
[%s]",
+ fDepotName.String())
}
return !fStoppable->WasStopped();
@@ -322,8 +320,8 @@
if (Logger::IsInfoEnabled()) {
double secs = watch.ElapsedTime() / 1000000.0;
- printf("[%s] did process %" B_PRIi32 " packages' data "
- "in (%6.3g secs)\n", Name(), itemListener->Count(),
secs);
+ HDINFO3("[%s] did process %" B_PRIi32 " packages' data "
+ "in (%6.3g secs)", Name(), itemListener->Count(), secs)
}
return listener->ErrorStatus();
@@ -362,11 +360,9 @@
ServerPkgDataUpdateProcess::RunInternal()
{
if (_DeriveWebAppRepositorySourceCode().IsEmpty()) {
- if (Logger::IsInfoEnabled()) {
- printf("[%s] am not updating data for depot [%s] as
there is no"
- " web app repository source code available\n",
- Name(), fDepotName.String());
- }
+ HDINFO2("[%s] am not updating data for depot [%s] as there is
no"
+ " web app repository source code available",
+ Name(), fDepotName.String())
return B_OK;
}
diff --git a/src/apps/haikudepot/server/ServerReferenceDataUpdateProcess.cpp
b/src/apps/haikudepot/server/ServerReferenceDataUpdateProcess.cpp
index 0930a15..12eee91 100644
--- a/src/apps/haikudepot/server/ServerReferenceDataUpdateProcess.cpp
+++ b/src/apps/haikudepot/server/ServerReferenceDataUpdateProcess.cpp
@@ -121,8 +121,8 @@
ServerReferenceDataUpdateProcess::_ProcessNaturalLanguages(
DumpExportReference* data)
{
- printf("[%s] will populate %" B_PRId32 " natural languages\n",
- Name(), data->CountNaturalLanguages());
+ HDINFO2("[%s] will populate %" B_PRId32 " natural languages",
+ Name(), data->CountNaturalLanguages())
LanguageList result;
@@ -143,8 +143,8 @@
fModel->Language().AddSupportedLanguages(result);
}
- printf("[%s] did add %" B_PRId32 " supported languages\n",
- Name(), result.CountItems());
+ HDINFO2("[%s] did add %" B_PRId32 " supported languages",
+ Name(), result.CountItems())
return B_OK;
}
@@ -154,8 +154,8 @@
ServerReferenceDataUpdateProcess::_ProcessPkgCategories(
DumpExportReference* data)
{
- printf("[%s] will populate %" B_PRId32 " pkg categories\n",
- Name(), data->CountPkgCategories());
+ HDINFO2("[%s] will populate %" B_PRId32 " pkg categories",
+ Name(), data->CountPkgCategories())
CategoryList result;
diff --git a/src/apps/haikudepot/server/ServerRepositoryDataUpdateProcess.cpp
b/src/apps/haikudepot/server/ServerRepositoryDataUpdateProcess.cpp
index c18eb79..258655b 100644
--- a/src/apps/haikudepot/server/ServerRepositoryDataUpdateProcess.cpp
+++ b/src/apps/haikudepot/server/ServerRepositoryDataUpdateProcess.cpp
@@ -102,18 +102,18 @@
BString(*repositorySourceCode));
if (Logger::IsDebugEnabled()) {
- printf("[DepotMatchingRepositoryListener] associated depot [%s]
(%s) "
- "with server repository source [%s] (%s)\n",
+ HDDEBUG4("[DepotMatchingRepositoryListener] associated depot
[%s] (%s) "
+ "with server repository source [%s] (%s)",
modifiedDepotInfo.Name().String(),
modifiedDepotInfo.URL().String(),
repositorySourceCode->String(),
repositoryAndRepositorySource
- ->repositorySource->Identifier()->String());
+ ->repositorySource->Identifier()->String())
} else {
- printf("[DepotMatchingRepositoryListener] associated depot [%s]
with "
- "server repository source [%s]\n",
+ HDINFO2("[DepotMatchingRepositoryListener] associated depot
[%s] with "
+ "server repository source [%s]",
modifiedDepotInfo.Name().String(),
- repositorySourceCode->String());
+ repositorySourceCode->String())
}
return modifiedDepotInfo;
@@ -133,7 +133,8 @@
void
DepotMatchingRepositoryListener::Handle(repository_and_repository_source& pair)
{
- Handle(*(pair.repositorySource->Identifier()), pair);
+ if (!pair.repositorySource->IdentifierIsNull())
+ Handle(*(pair.repositorySource->Identifier()), pair);
// there may be additional identifiers for the remote repository and
// these should also be taken into consideration.
diff --git a/src/apps/haikudepot/server/ServerSettings.cpp
b/src/apps/haikudepot/server/ServerSettings.cpp
index 3d80bad..8d5ea25 100644
--- a/src/apps/haikudepot/server/ServerSettings.cpp
+++ b/src/apps/haikudepot/server/ServerSettings.cpp
@@ -1,11 +1,10 @@
/*
- * Copyright 2017-2018, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2017-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "ServerSettings.h"
-#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
@@ -17,6 +16,8 @@
#include <Roster.h>
#include <Url.h>
+#include "Logger.h"
+
#define BASEURL_DEFAULT "https://depot.haiku-os.org";
#define USERAGENT_FALLBACK_VERSION "0.0.0"
@@ -36,12 +37,12 @@
ServerSettings::SetBaseUrl(const BUrl& value)
{
if (!value.IsValid()) {
- fprintf(stderr, "the url is not valid\n");
+ HDERROR0("the url is not valid")
return B_BAD_VALUE;
}
if (value.Protocol() != "http" && value.Protocol() != "https") {
- fprintf(stderr, "the url protocol must be 'http' or 'https'\n");
+ HDERROR0("the url protocol must be 'http' or 'https'")
return B_BAD_VALUE;
}
@@ -82,7 +83,7 @@
app_info info;
if (be_app->GetAppInfo(&info) != B_OK) {
- fprintf(stderr, "Unable to get the application info\n");
+ HDERROR0("Unable to get the application info")
be_app->Quit();
return BString(USERAGENT_FALLBACK_VERSION);
}
@@ -90,7 +91,7 @@
BFile file(&info.ref, B_READ_ONLY);
if (file.InitCheck() != B_OK) {
- fprintf(stderr, "Unable to access the application info file\n");
+ HDERROR0("Unable to access the application info file")
be_app->Quit();
return BString(USERAGENT_FALLBACK_VERSION);
}
@@ -100,7 +101,7 @@
if (appFileInfo.GetVersionInfo(
&versionInfo, B_APP_VERSION_KIND) != B_OK) {
- fprintf(stderr, "Unable to establish the application
version\n");
+ HDERROR0("Unable to establish the application version")
be_app->Quit();
return BString(USERAGENT_FALLBACK_VERSION);
}
diff --git a/src/apps/haikudepot/server/StandardMetaDataJsonEventListener.cpp
b/src/apps/haikudepot/server/StandardMetaDataJsonEventListener.cpp
index e2feb83..166a444 100644
--- a/src/apps/haikudepot/server/StandardMetaDataJsonEventListener.cpp
+++ b/src/apps/haikudepot/server/StandardMetaDataJsonEventListener.cpp
@@ -1,12 +1,12 @@
/*
- * Copyright 2017, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2017-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "StandardMetaDataJsonEventListener.h"
-#include "stdio.h"
+#include "Logger.h"
#define KEY_CREATE_TIMESTAMP "createTimestamp"
@@ -384,8 +384,8 @@
StandardMetaDataJsonEventListener::HandleError(status_t status, int32 line,
const char* message)
{
- fprintf(stderr, "an error has arisen processing the standard "
- "meta data; %s\n", message);
+ HDERROR1("an error has arisen processing the standard "
+ "meta data; %s", message)
fErrorStatus = status;
}
diff --git a/src/apps/haikudepot/server/UserDetailVerifierProcess.cpp
b/src/apps/haikudepot/server/UserDetailVerifierProcess.cpp
index fad55c7..6fe1cab 100644
--- a/src/apps/haikudepot/server/UserDetailVerifierProcess.cpp
+++ b/src/apps/haikudepot/server/UserDetailVerifierProcess.cpp
@@ -62,8 +62,8 @@
break;
case B_OK:
if (!userDetail.Agreement().IsLatest()) {
- printf("! the user has not agreed to
the latest user usage"
- " conditions.\n");
+ HDINFO0("the user has not agreed to the
latest user usage"
+ " conditions.")
fListener->UserUsageConditionsNotLatest(userDetail);
}
break;
@@ -80,14 +80,14 @@
UserDetailVerifierProcess::_ShouldVerify()
{
if (!ServerHelper::IsNetworkAvailable()) {
- printf("no network --> will not verify user\n");
+ HDINFO0("no network --> will not verify user")
return false;
}
{
AutoLocker<BLocker> locker(fModel->Lock());
if (fModel->Nickname().IsEmpty()) {
- printf("no nickname --> will not verify user\n");
+ HDINFO0("no nickname --> will not verify user");
return false;
}
}
@@ -105,8 +105,8 @@
result = interface.RetrieveCurrentUserDetail(userDetailResponse);
if (result != B_OK) {
- printf("a problem has arisen retrieving the current user
detail: %s\n",
- strerror(result));
+ HDERROR1("a problem has arisen retrieving the current user
detail: %s",
+ strerror(result))
}
if (result == B_OK) {
@@ -118,9 +118,9 @@
result = B_PERMISSION_DENIED;
break;
default:
- printf("! a problem has arisen retrieving the
current user "
- "detail for user [%s]: jrpc error code
%" B_PRId32 "\n",
- fModel->Nickname().String(), errorCode);
+ HDERROR2("a problem has arisen retrieving the
current user "
+ "detail for user [%s]: jrpc error code
%" B_PRId32 "",
+ fModel->Nickname().String(), errorCode)
result = B_ERROR;
break;
}
@@ -134,7 +134,7 @@
result = interface.UnpackUserDetail(userDetailResponse,
userDetail);
if (result != B_OK)
- printf("! it was not possible to unpack the user
details.\n");
+ HDERROR0("it was not possible to unpack the user
details.")
}
return result;
diff --git a/src/apps/haikudepot/server/WebAppInterface.cpp
b/src/apps/haikudepot/server/WebAppInterface.cpp
index 6805980..2148ed0 100644
--- a/src/apps/haikudepot/server/WebAppInterface.cpp
+++ b/src/apps/haikudepot/server/WebAppInterface.cpp
@@ -6,8 +6,6 @@
#include "WebAppInterface.h"
-#include <stdio.h>
-
#include <Application.h>
#include <HttpHeaders.h>
#include <HttpRequest.h>
@@ -35,10 +33,9 @@
class ProtocolListener : public BUrlProtocolListener {
public:
- ProtocolListener(bool traceLogging)
+ ProtocolListener()
:
- fDownloadIO(NULL),
- fTraceLogging(traceLogging)
+ fDownloadIO(NULL)
{
}
@@ -86,8 +83,7 @@
virtual void DebugMessage(BUrlRequest* caller,
BUrlProtocolDebugMessage type, const char* text)
{
- if (fTraceLogging)
- printf("jrpc: %s\n", text);
+ HDTRACE1("jrpc: %s", text)
}
void SetDownloadIO(BDataIO* downloadIO)
@@ -97,7 +93,6 @@
private:
BDataIO* fDownloadIO;
- bool fTraceLogging;
};
@@ -342,7 +337,7 @@
"result", &resultMessage);
if (result != B_OK) {
- fprintf(stderr, "bad response envelope missing 'result'
entry\n");
+ HDERROR0("bad response envelope missing 'result' entry");
return result;
}
@@ -405,7 +400,7 @@
BMessage resultMessage;
if (responseEnvelopeMessage.FindMessage("result", &resultMessage) !=
B_OK) {
- fprintf(stderr, "bad response envelope missing 'result'
entry\n");
+ HDERROR0("bad response envelope missing 'result' entry")
return B_BAD_DATA;
}
@@ -414,10 +409,10 @@
BString copyMarkdown;
if ( (resultMessage.FindString("code", &metaDataCode) != B_OK)
- || (resultMessage.FindDouble(
- "minimumAge", &metaDataMinimumAge) != B_OK) ) {
- printf("unexpected response from server with missing user usage
"
- "conditions data\n");
+ || (resultMessage.FindDouble(
+ "minimumAge", &metaDataMinimumAge) != B_OK) ) {
+ HDERROR0("unexpected response from server with missing user
usage "
+ "conditions data")
return B_BAD_DATA;
}
@@ -811,48 +806,40 @@
size_t requestDataSize, uint32 flags, BMessage& reply) const
{
if (requestDataSize == 0) {
- if (Logger::IsInfoEnabled())
- printf("jrpc; empty request payload\n");
+ HDINFO0("jrpc; empty request payload")
return B_ERROR;
}
if (!ServerHelper::IsNetworkAvailable()) {
- if (Logger::IsDebugEnabled()) {
- printf("jrpc; dropping request to ...[%s] as network is
not "
- "available\n", domain);
- }
+ HDDEBUG1("jrpc; dropping request to ...[%s] as network is not"
+ " available", domain)
delete requestData;
return HD_NETWORK_INACCESSIBLE;
}
if (ServerSettings::IsClientTooOld()) {
- if (Logger::IsDebugEnabled()) {
- printf("jrpc; dropping request to ...[%s] as client is
too "
- "old\n", domain);
- }
+ HDDEBUG1("jrpc; dropping request to ...[%s] as client is too
old",
+ domain)
delete requestData;
return HD_CLIENT_TOO_OLD;
}
BUrl url = ServerSettings::CreateFullUrl(BString("/__api/v1/") <<
domain);
bool isSecure = url.Protocol() == "https";
-
- if (Logger::IsDebugEnabled()) {
- printf("jrpc; will make request to [%s]\n",
- url.UrlString().String());
- }
+ HDDEBUG1("jrpc; will make request to [%s]", url.UrlString().String())
// If the request payload is logged then it must be copied to local
memory
// from the stream. This then requires that the request data is then
// delivered from memory.
if (Logger::IsTraceEnabled()) {
+ HDLOGPREFIX(LOG_LEVEL_TRACE)
printf("jrpc request; ");
_LogPayload(requestData, requestDataSize);
printf("\n");
}
- ProtocolListener listener(Logger::IsTraceEnabled());
+ ProtocolListener listener;
BUrlContext context;
BHttpHeaders headers;
@@ -886,10 +873,8 @@
int32 statusCode = result.StatusCode();
- if (Logger::IsDebugEnabled()) {
- printf("jrpc; did receive http-status [%" B_PRId32 "] "
- "from [%s]\n", statusCode, url.UrlString().String());
- }
+ HDDEBUG2("jrpc; did receive http-status [%" B_PRId32 "] from [%s]",
+ statusCode, url.UrlString().String())
switch (statusCode) {
case B_HTTP_STATUS_OK:
@@ -900,14 +885,15 @@
return HD_CLIENT_TOO_OLD;
default:
- printf("jrpc request to endpoint [.../%s] failed with
http "
- "status [%" B_PRId32 "]\n", domain, statusCode);
+ HDERROR2("jrpc request to endpoint [.../%s] failed with
http "
+ "status [%" B_PRId32 "]\n", domain, statusCode)
return B_ERROR;
}
replyData.Seek(0, SEEK_SET);
if (Logger::IsTraceEnabled()) {
+ HDLOGPREFIX(LOG_LEVEL_TRACE)
printf("jrpc response; ");
_LogPayload(&replyData, replyData.BufferLength());
printf("\n");
@@ -920,7 +906,7 @@
if (Logger::IsTraceEnabled() && status == B_BAD_DATA) {
BString resultString(static_cast<const char
*>(replyData.Buffer()),
replyData.BufferLength());
- printf("Parser choked on JSON:\n%s\n", resultString.String());
+ HDERROR1("Parser choked on JSON:\n%s", resultString.String())
}
return status;
}
@@ -946,7 +932,7 @@
BUrl url = ServerSettings::CreateFullUrl(urlPathComponents);
bool isSecure = url.Protocol() == "https";
- ProtocolListener listener(Logger::IsTraceEnabled());
+ ProtocolListener listener;
listener.SetDownloadIO(stream);
BHttpHeaders headers;
@@ -967,8 +953,8 @@
if (statusCode == 200)
return B_OK;
- fprintf(stderr, "failed to get data from '%s': %" B_PRIi32 "\n",
- url.UrlString().String(), statusCode);
+ HDERROR2("failed to get data from '%s': %" B_PRIi32 "",
+ url.UrlString().String(), statusCode)
return B_ERROR;
}
@@ -983,7 +969,7 @@
size = LOG_PAYLOAD_LIMIT;
if (B_OK != requestData->ReadExactly(buffer, size)) {
- printf("jrpc; error logging payload\n");
+ printf("jrpc; error logging payload");
} else {
for (uint32 i = 0; i < size; i++) {
bool esc = buffer[i] > 126 ||
diff --git a/src/apps/haikudepot/tar/TarArchiveHeader.cpp
b/src/apps/haikudepot/tar/TarArchiveHeader.cpp
index 75030d3..4da1e99 100644
--- a/src/apps/haikudepot/tar/TarArchiveHeader.cpp
+++ b/src/apps/haikudepot/tar/TarArchiveHeader.cpp
@@ -1,12 +1,11 @@
/*
- * Copyright 2017, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2017-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "TarArchiveHeader.h"
-#include <stdio.h>
-
+#include "Logger.h"
#define OFFSET_FILENAME 0
#define OFFSET_LENGTH 124
@@ -116,9 +115,9 @@
LENGTH_CHECKSUM);
if(actualChecksum != expectedChecksum) {
- fprintf(stderr, "tar archive header has bad checksum;"
- "expected %" B_PRIu32 " actual %" B_PRIu32 "\n",
- expectedChecksum, actualChecksum);
+ HDERROR2("tar archive header has bad checksum;"
+ "expected %" B_PRIu32 " actual %" B_PRIu32,
+ expectedChecksum, actualChecksum)
} else {
return new TarArchiveHeader(
_ReadString(&block[OFFSET_FILENAME], LENGTH_FILENAME),
diff --git a/src/apps/haikudepot/tar/TarArchiveService.cpp
b/src/apps/haikudepot/tar/TarArchiveService.cpp
index aa7e64b..2881495 100644
--- a/src/apps/haikudepot/tar/TarArchiveService.cpp
+++ b/src/apps/haikudepot/tar/TarArchiveService.cpp
@@ -1,13 +1,11 @@
/*
- * Copyright 2017-2018, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2017-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "TarArchiveService.h"
-#include <stdio.h>
-
#include <Directory.h>
#include <File.h>
#include <StringList.h>
@@ -28,7 +26,7 @@
status_t result = B_OK;
uint32_t count_items_read = 0;
- fprintf(stdout, "will unpack to [%s]\n", targetDirectory.Path());
+ HDINFO1("will unpack to [%s]", targetDirectory.Path())
memset(zero_buffer, 0, sizeof zero_buffer);
@@ -39,15 +37,14 @@
count_items_read++;
if (0 == memcmp(zero_buffer, buffer, sizeof zero_buffer)) {
- if (Logger::IsDebugEnabled())
- printf("detected end of tar-ball\n");
+ HDDEBUG0("detected end of tar-ball")
return B_OK; // end of tar-ball.
} else {
TarArchiveHeader* header =
TarArchiveHeader::CreateFromBlock(
buffer);
if (NULL == header) {
- fprintf(stderr, "unable to parse a tar
header\n");
+ HDERROR0("unable to parse a tar header")
result = B_ERROR;
}
@@ -58,11 +55,10 @@
}
}
- fprintf(stdout, "did unpack %d tar items\n", count_items_read);
+ HDERROR1("did unpack %d tar items", count_items_read)
if (B_OK != result) {
- fprintf(stdout, "error occurred unpacking tar items; %s\n",
- strerror(result));
+ HDERROR1("error occurred unpacking tar items; %s",
strerror(result))
}
return result;
@@ -83,7 +79,7 @@
BString component = components.StringAt(i);
if (_ValidatePathComponent(component) != B_OK) {
- fprintf(stdout, "malformed component; [%s]\n",
component.String());
+ HDERROR1("malformed component; [%s]",
component.String())
return B_ERROR;
}
}
@@ -112,10 +108,8 @@
BString entryFileName = header.GetFileName();
uint32 entryLength = header.GetLength();
- if (Logger::IsDebugEnabled()) {
- fprintf(stdout, "will unpack item [%s] length [%" B_PRIu32
"]b\n",
- entryFileName.String(), entryLength);
- }
+ HDDEBUG2("will unpack item [%s] length [%" B_PRIu32 "]b",
+ entryFileName.String(), entryLength)
// if the path ends in "/" then it is a directory and there's no need to
// unpack it although if there is a length, it will need to be skipped.
@@ -172,8 +166,7 @@
}
if (result != B_OK)
- fprintf(stdout, "unable to unpack item data to; [%s]\n",
- targetFilePath.Path());
+ HDERROR1("unable to unpack item data to; [%s]",
targetFilePath.Path())
return result;
}
diff --git a/src/apps/haikudepot/ui/App.cpp b/src/apps/haikudepot/ui/App.cpp
index e2dd2df..0016d6e 100644
--- a/src/apps/haikudepot/ui/App.cpp
+++ b/src/apps/haikudepot/ui/App.cpp
@@ -530,8 +530,9 @@
bool exists = false;
status_t status = StorageUtils::LocalWorkingFilesPath("testfile.txt",
testFilePath, false);
- if (status != B_OK)
- printf("! unable to establish the location of the test file\n");
+ if (status != B_OK) {
+ HDERROR0("unable to establish the location of the test file")
+ }
else
status = StorageUtils::ExistsObject(testFilePath, &exists,
NULL, NULL);
return !exists;
diff --git a/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
b/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
index 1dd9b0f..0443d5c 100644
--- a/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
+++ b/src/apps/haikudepot/ui/FeaturedPackagesView.cpp
@@ -8,7 +8,6 @@
#include "FeaturedPackagesView.h"
#include <algorithm>
-#include <stdio.h>
#include <vector>
#include <Bitmap.h>
@@ -23,6 +22,7 @@
#include "BitmapView.h"
#include "HaikuDepotConstants.h"
+#include "Logger.h"
#include "MainWindow.h"
#include "MarkupTextView.h"
#include "MessagePackageListener.h"
@@ -81,8 +81,9 @@
case MSG_UPDATE_PACKAGE:
{
BString name;
- if (message->FindString("name", &name) != B_OK)
- printf("expected 'name' key on package
update message\n");
+ if (message->FindString("name", &name) != B_OK)
{
+ HDINFO0("expected 'name' key on package
update message")
+ }
else
_HandleUpdatePackage(name);
break;
@@ -653,7 +654,7 @@
void
FeaturedPackagesView::Clear()
{
- printf("did clear the featured packages view\n");
+ HDINFO0("did clear the featured packages view")
fPackagesView->Clear();
_AdjustViews();
}
diff --git a/src/apps/haikudepot/ui/MainWindow.cpp
b/src/apps/haikudepot/ui/MainWindow.cpp
index 3bfd4f5..de8dd05 100644
--- a/src/apps/haikudepot/ui/MainWindow.cpp
+++ b/src/apps/haikudepot/ui/MainWindow.cpp
@@ -302,7 +302,7 @@
if (message->FindInt64(KEY_ERROR_STATUS,
&errorStatus64) == B_OK)
_BulkLoadCompleteReceived((status_t)
errorStatus64);
else
- printf("! expected [%s] value in message\n",
KEY_ERROR_STATUS);
+ HDERROR1("expected [%s] value in message",
KEY_ERROR_STATUS)
break;
}
case B_SIMPLE_DATA:
@@ -412,11 +412,9 @@
if (fPackageInfoView->Package()->Name() ==
name) {
_PopulatePackageAsync(true);
} else {
- if (Logger::IsDebugEnabled()) {
- printf("pkg [%s] is updated on
the server, but is "
- "not selected so will
not be updated.\n",
- name.String());
- }
+ HDDEBUG1("pkg [%s] is updated on the
server, but is "
+ "not selected so will not be
updated.",
+ name.String())
}
}
break;
@@ -823,8 +821,7 @@
void
MainWindow::_AdoptModel()
{
- if (Logger::IsTraceEnabled())
- printf("adopting model to main window ui\n");
+ HDTRACE0("adopting model to main window ui")
if (fSinglePackageMode)
return;
@@ -1039,10 +1036,8 @@
}
release_sem_etc(fPackageToPopulateSem, 1, 0);
- if (Logger::IsDebugEnabled()) {
- printf("pkg [%s] will be updated from the server.\n",
- fPackageToPopulate->Name().String());
- }
+ HDDEBUG1("pkg [%s] will be updated from the server.",
+ fPackageToPopulate->Name().String())
}
@@ -1075,10 +1070,7 @@
window->fModel.PopulatePackage(package, populateFlags);
- if (Logger::IsDebugEnabled()) {
- printf("populating package [%s]\n",
- package->Name().String());
- }
+ HDDEBUG1("populating package [%s]",
package->Name().String())
}
}
@@ -1184,22 +1176,19 @@
const BString depotName = package->DepotName();
if (depotName.IsEmpty()) {
- if (Logger::IsDebugEnabled()) {
- printf("the package [%s] has no depot name\n",
- package->Name().String());
- }
+ HDDEBUG1("the package [%s] has no depot name",
package->Name().String())
} else {
const DepotInfo* depot = fModel.DepotForName(depotName);
if (depot == NULL) {
- printf("the depot [%s] was not able to be found\n",
- depotName.String());
+ HDINFO1("the depot [%s] was not able to be found",
+ depotName.String())
} else {
BString repositoryCode = depot->WebAppRepositoryCode();
if (repositoryCode.IsEmpty()) {
- printf("the depot [%s] has no web app
repository code\n",
- depotName.String());
+ HDINFO1("the depot [%s] has no web app
repository code",
+ depotName.String())
} else {
return true;
}
@@ -1312,7 +1301,7 @@
BMessage detailsMessage;
if (userDetail.Archive(&detailsMessage, true) != B_OK
|| message.AddMessage("userDetail", &detailsMessage) !=
B_OK) {
- printf("!! unable to archive the user detail into a message\n");
+ HDERROR0("unable to archive the user detail into a message")
}
else
BMessenger(this).SendMessage(&message);
@@ -1337,18 +1326,14 @@
if (fCoordinator.Get() == NULL) {
if (acquire_sem(fCoordinatorRunningSem) != B_OK)
debugger("unable to acquire the process coordinator
sem");
- if (Logger::IsInfoEnabled()) {
- printf("adding and starting a process coordinator
[%s]\n",
- item->Name().String());
- }
+ HDINFO1("adding and starting a process coordinator [%s]",
+ item->Name().String())
fCoordinator = BReference<ProcessCoordinator>(item);
fCoordinator->Start();
}
else {
- if (Logger::IsInfoEnabled()) {
- printf("adding process coordinator [%s] to the queue\n",
- item->Name().String());
- }
+ HDINFO1("adding process coordinator [%s] to the queue",
+ item->Name().String());
fCoordinatorQueue.push(item);
}
}
@@ -1374,18 +1359,16 @@
void
MainWindow::_StopProcessCoordinators()
{
- if (Logger::IsInfoEnabled())
- printf("will stop all process coordinators\n");
+ HDINFO0("will stop all process coordinators")
{
AutoLocker<BLocker> lock(&fCoordinatorLock);
while (!fCoordinatorQueue.empty()) {
- BReference<ProcessCoordinator> processCoordinator =
fCoordinatorQueue.front();
- if (Logger::IsInfoEnabled()) {
- printf("will drop queued process coordinator
[%s]\n",
- processCoordinator->Name().String());
- }
+ BReference<ProcessCoordinator> processCoordinator
+ = fCoordinatorQueue.front();
+ HDINFO1("will drop queued process coordinator [%s]",
+ processCoordinator->Name().String())
fCoordinatorQueue.pop();
}
@@ -1394,13 +1377,11 @@
}
}
- if (Logger::IsInfoEnabled())
- printf("will wait until the process coordinator has stopped\n");
+ HDINFO0("will wait until the process coordinator has stopped")
_SpinUntilProcessCoordinatorComplete();
- if (Logger::IsInfoEnabled())
- printf("did stop all process coordinators\n");
+ HDINFO0("did stop all process coordinators")
}
@@ -1419,10 +1400,8 @@
if (!coordinatorState.IsRunning()) {
if (release_sem(fCoordinatorRunningSem) != B_OK)
debugger("unable to release the process
coordinator sem");
- if (Logger::IsInfoEnabled()) {
- printf("process coordinator [%s] did
complete\n",
- fCoordinator->Name().String());
- }
+ HDINFO1("process coordinator [%s] did complete",
+ fCoordinator->Name().String())
// complete the last one that just finished
BMessage* message = fCoordinator->Message();
@@ -1442,10 +1421,8 @@
if (acquire_sem(fCoordinatorRunningSem) != B_OK)
debugger("unable to acquire the process
coordinator sem");
fCoordinator = fCoordinatorQueue.front();
- if (Logger::IsInfoEnabled()) {
- printf("starting next process
coordinator [%s]\n",
- fCoordinator->Name().String());
- }
+ HDINFO1("starting next process coordinator
[%s]",
+ fCoordinator->Name().String());
fCoordinatorQueue.pop();
fCoordinator->Start();
}
@@ -1459,8 +1436,7 @@
// show the progress to the user.
}
} else {
- if (Logger::IsInfoEnabled())
- printf("! unknown process coordinator changed\n");
+ HDINFO0("! unknown process coordinator changed")
}
}
diff --git a/src/apps/haikudepot/ui/PackageContentsView.cpp
b/src/apps/haikudepot/ui/PackageContentsView.cpp
index 3fa151c..73a93e1 100644
--- a/src/apps/haikudepot/ui/PackageContentsView.cpp
+++ b/src/apps/haikudepot/ui/PackageContentsView.cpp
@@ -21,6 +21,8 @@
#include <StringFormat.h>
#include <StringItem.h>
+#include "Logger.h"
+
#include <package/PackageDefs.h>
#include <package/hpkg/NoErrorOutput.h>
#include <package/hpkg/PackageContentHandler.h>
@@ -122,16 +124,11 @@
virtual status_t HandleEntry(BPackageEntry* entry)
{
-// printf("HandleEntry(%s/%s)\n",
-// entry->Parent() != NULL ? entry->Parent()->Name() :
"NULL",
-// entry->Name());
-
if (fListView->LockLooperWithTimeout(1000000) != B_OK)
return B_ERROR;
// Check if we are still supposed to popuplate the list
if (fPackageInfoRef.Get() != fPackageInfoToPopulate) {
-// printf("stopping package content population\n");
fListView->UnlockLooper();
return B_ERROR;
}
@@ -148,17 +145,14 @@
PackageEntryItem* item = new PackageEntryItem(entry, path);
if (entry->Parent() == NULL) {
-// printf(" adding root entry\n");
fListView->AddItem(item);
fLastParentEntry = NULL;
fLastParentItem = NULL;
} else if (entry->Parent() == fLastEntry) {
-// printf(" adding to last entry %s\n",
fLastEntry->Name());
fListView->AddUnder(item, fLastItem);
fLastParentEntry = fLastEntry;
fLastParentItem = fLastItem;
} else if (entry->Parent() == fLastParentEntry) {
-// printf(" adding to last parent %s\n",
fLastParentEntry->Name());
fListView->AddUnder(item, fLastParentItem);
} else {
// Not the last parent entry, need to search for the
parent
@@ -173,7 +167,6 @@
if (listItem->EntryPath() == path) {
fLastParentEntry = entry->Parent();
fLastParentItem = listItem;
-// printf(" found parent %s\n",
listItem->Text());
fListView->AddUnder(item, listItem);
foundParent = true;
break;
@@ -182,8 +175,6 @@
if (!foundParent) {
// NOTE: Should not happen. Just add this entry
at the
// root level.
-// printf("Did not find parent entry for %s
(%s)!\n",
-// entry->Name(), entry->Parent()->Name());
fListView->AddItem(item);
fLastParentEntry = NULL;
fLastParentItem = NULL;
@@ -391,8 +382,8 @@
return false;
}
} else {
-
printf("PackageContentsView::_PopulatePackageContents(): "
- "unknown install location");
+
HDINFO0("PackageContentsView::_PopulatePackageContents(): "
+ "unknown install location")
return false;
}
@@ -405,9 +396,9 @@
status_t status = reader.Init(packagePath.Path());
if (status != B_OK) {
- printf("PackageContentsView::_PopulatePackageContents(): "
- "failed to init BPackageReader(%s): %s\n",
- packagePath.Path(), strerror(status));
+ HDINFO2("PackageContentsView::_PopulatePackageContents(): "
+ "failed to init BPackageReader(%s): %s",
+ packagePath.Path(), strerror(status))
return false;
}
@@ -416,8 +407,8 @@
fPackageLock, fPackage);
status = reader.ParseContent(&contentHandler);
if (status != B_OK) {
- printf("PackageContentsView::_PopulatePackageContents(): "
- "failed parse package contents: %s\n",
strerror(status));
+ HDINFO1("PackageContentsView::_PopulatePackageContents(): "
+ "failed parse package contents: %s", strerror(status))
// NOTE: Do not return false, since it taken to mean this
// is a remote package, but is it not, we simply want to stop
// populating the contents early.
diff --git a/src/apps/haikudepot/ui/PackageInfoView.cpp
b/src/apps/haikudepot/ui/PackageInfoView.cpp
index f45b0b2..442b1de 100644
--- a/src/apps/haikudepot/ui/PackageInfoView.cpp
+++ b/src/apps/haikudepot/ui/PackageInfoView.cpp
@@ -7,7 +7,6 @@
#include "PackageInfoView.h"
#include <algorithm>
-#include <stdio.h>
#include <Alert.h>
#include <Autolock.h>
@@ -39,6 +38,7 @@
#include "LinkView.h"
#include "LinkedBitmapView.h"
#include "LocaleUtils.h"
+#include "Logger.h"
#include "MarkupTextView.h"
#include "MessagePackageListener.h"
#include "PackageActionHandler.h"
@@ -624,10 +624,10 @@
=
fPackageActionHandler->SchedulePackageActions(actions);
if (result != B_OK) {
- fprintf(stderr, "Failed to schedule action: "
- "%s '%s': %s\n", action->Label(),
+ HDERROR3("Failed to schedule action: %s '%s': %s",
+ action->Label(),
action->Package()->Name().String(),
- strerror(result));
+ strerror(result))
BString message(B_TRANSLATE("The package action "
"could not be scheduled: %Error%"));
message.ReplaceAll("%Error%", strerror(result));
diff --git a/src/apps/haikudepot/ui/RatePackageWindow.cpp
b/src/apps/haikudepot/ui/RatePackageWindow.cpp
index a778250..991a555 100644
--- a/src/apps/haikudepot/ui/RatePackageWindow.cpp
+++ b/src/apps/haikudepot/ui/RatePackageWindow.cpp
@@ -24,6 +24,7 @@
#include "HaikuDepotConstants.h"
#include "LanguageMenuUtils.h"
+#include "Logger.h"
#include "MarkupParser.h"
#include "RatingView.h"
#include "ServerHelper.h"
@@ -530,7 +531,7 @@
Unlock();
} else {
- fprintf(stderr, "unable to acquire lock to update the ui\n");
+ HDERROR0("unable to acquire lock to update the ui");
}
}
@@ -539,7 +540,7 @@
RatePackageWindow::_QueryRatingThread()
{
if (!Lock()) {
- fprintf(stderr, "rating query: Failed to lock window\n");
+ HDERROR0("rating query: Failed to lock window");
return;
}
@@ -552,7 +553,7 @@
locker.Unlock();
if (package.Get() == NULL) {
- fprintf(stderr, "rating query: No package\n");
+ HDERROR0("rating query: No package");
_SetWorkerThread(-1);
return;
}
@@ -566,8 +567,8 @@
repositoryCode = depot->WebAppRepositoryCode();
if (repositoryCode.IsEmpty()) {
- printf("unable to obtain the repository code for depot; %s\n",
- package->DepotName().String());
+ HDERROR1("unable to obtain the repository code for depot; %s",
+ package->DepotName().String())
BMessenger(this).SendMessage(B_QUIT_REQUESTED);
} else {
status_t status = interface
@@ -586,8 +587,7 @@
if (info.FindMessage("result", &result)
== B_OK) {
_RelayServerDataToUI(result);
} else {
- fprintf(stderr, "bad response
envelope missing 'result'"
- "entry\n");
+ HDERROR0("bad response envelope
missing 'result' entry")
ServerHelper::NotifyTransportError(B_BAD_VALUE);
BMessenger(this).SendMessage(B_QUIT_REQUESTED);
}
@@ -595,9 +595,9 @@
}
case ERROR_CODE_OBJECTNOTFOUND:
// an expected response
- fprintf(stderr, "there was no previous
rating for this"
+ HDINFO0("there was no previous rating
for this"
" user on this version of this
package so a new rating"
- " will be added.\n");
+ " will be added.")
break;
default:
ServerHelper::NotifyServerJsonRpcError(info);
@@ -605,9 +605,9 @@
break;
}
} else {
- fprintf(stderr, "an error has arisen communicating with
the"
- " server to obtain data for an existing rating
[%s]\n",
- strerror(status));
+ HDERROR1("an error has arisen communicating with the"
+ " server to obtain data for an existing rating
[%s]",
+ strerror(status))
ServerHelper::NotifyTransportError(status);
BMessenger(this).SendMessage(B_QUIT_REQUESTED);
}
@@ -630,7 +630,7 @@
RatePackageWindow::_SendRatingThread()
{
if (!Lock()) {
- fprintf(stderr, "upload rating: Failed to lock window\n");
+ HDERROR0("upload rating: Failed to lock window")
return;
}
@@ -658,9 +658,9 @@
Unlock();
if (repositoryCode.Length() == 0) {
- printf("unable to find the web app repository code for the
local "
- "depot %s\n",
- fPackage->DepotName().String());
+ HDERROR1("unable to find the web app repository code for the
local "
+ "depot %s",
+ fPackage->DepotName().String())
return;
}
@@ -670,13 +670,11 @@
status_t status;
BMessage info;
if (ratingID.Length() > 0) {
- printf("will update the existing user rating [%s]\n",
- ratingID.String());
+ HDINFO1("will update the existing user rating [%s]",
ratingID.String())
status = interface.UpdateUserRating(ratingID,
languageCode, comment, stability, rating, active, info);
} else {
- printf("will create a new user rating for pkg [%s]\n",
- package.String());
+ HDINFO1("will create a new user rating for pkg [%s]",
package.String())
status = interface.CreateUserRating(package,
fPackage->Version(),
architecture, repositoryCode, languageCode, comment,
stability,
rating, info);
@@ -699,9 +697,9 @@
break;
}
} else {
- fprintf(stderr, "an error has arisen communicating with the"
- " server to obtain data for an existing rating [%s]\n",
- strerror(status));
+ HDERROR1("an error has arisen communicating with the"
+ " server to obtain data for an existing rating [%s]",
+ strerror(status))
ServerHelper::NotifyTransportError(status);
}
diff --git a/src/apps/haikudepot/ui/ScreenshotWindow.cpp
b/src/apps/haikudepot/ui/ScreenshotWindow.cpp
index 3ef69a0..23bf9c8 100644
--- a/src/apps/haikudepot/ui/ScreenshotWindow.cpp
+++ b/src/apps/haikudepot/ui/ScreenshotWindow.cpp
@@ -1,13 +1,13 @@
/*
* Copyright 2014, Stephan Aßmus <superstippi@xxxxxx>.
* Copyright 2017, Julian Harnath <julian.harnath@xxxxxxxxxxxxxx>.
+ * Copyright 2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "ScreenshotWindow.h"
#include <algorithm>
-#include <stdio.h>
#include <Autolock.h>
#include <Catalog.h>
@@ -18,6 +18,7 @@
#include "BarberPole.h"
#include "BitmapView.h"
#include "HaikuDepotConstants.h"
+#include "Logger.h"
#include "WebAppInterface.h"
@@ -253,9 +254,8 @@
void
ScreenshotWindow::_DownloadThread()
{
- printf("_DownloadThread()\n");
if (!Lock()) {
- printf(" failed to lock screenshot window\n");
+ HDERROR0("failed to lock screenshot window")
return;
}
@@ -268,7 +268,7 @@
Unlock();
if (screenshotInfos.CountItems() == 0) {
- printf(" package has no screenshots\n");
+ HDINFO0("package has no screenshots")
return;
}
@@ -295,13 +295,13 @@
messenger.SendMessage(MSG_DOWNLOAD_STOP);
if (status == B_OK && Lock()) {
- printf("got screenshot");
+ HDINFO0("got screenshot")
fScreenshot = BitmapRef(new(std::nothrow)SharedBitmap(buffer),
true);
fScreenshotView->SetBitmap(fScreenshot);
_ResizeToFitAndCenter();
Unlock();
} else {
- printf(" failed to download screenshot\n");
+ HDERROR0("failed to download screenshot")
}
}
diff --git a/src/apps/haikudepot/ui/ToLatestUserUsageConditionsWindow.cpp
b/src/apps/haikudepot/ui/ToLatestUserUsageConditionsWindow.cpp
index 430c7a2..fe82850 100644
--- a/src/apps/haikudepot/ui/ToLatestUserUsageConditionsWindow.cpp
+++ b/src/apps/haikudepot/ui/ToLatestUserUsageConditionsWindow.cpp
@@ -211,8 +211,8 @@
if (fWorkerThread >= 0) {
if (Logger::IsDebugEnabled())
- printf("quit requested while worker thread is operating
-- will "
- "try again once the worker thread has
completed\n");
+ HDINFO0("quit requested while worker thread is
operating -- will "
+ "try again once the worker thread has
completed")
fQuitRequestedDuringWorkerThread = true;
return false;
}
diff --git a/src/apps/haikudepot/ui/UserLoginWindow.cpp
b/src/apps/haikudepot/ui/UserLoginWindow.cpp
index c273657..d66fd17 100644
--- a/src/apps/haikudepot/ui/UserLoginWindow.cpp
+++ b/src/apps/haikudepot/ui/UserLoginWindow.cpp
@@ -8,7 +8,6 @@
#include <algorithm>
#include <ctype.h>
-#include <stdio.h>
#include <mail_encoding.h>
@@ -158,8 +157,8 @@
languagesMenu);
languagesMenu->SetTargetForItems(this);
- printf("using preferred language code [%s]\n",
- fPreferredLanguageCode.String());
+ HDINFO1("using preferred language code [%s]",
+ fPreferredLanguageCode.String())
LanguageMenuUtils::MarkLanguageInMenu(fPreferredLanguageCode,
languagesMenu);
}
@@ -299,7 +298,7 @@
}
case MSG_CREATE_ACCOUNT_SETUP_ERROR:
- printf("failed to setup for account setup - window must
quit\n");
+ HDERROR0("failed to setup for account setup - window
must quit")
BMessenger(this).SendMessage(B_QUIT_REQUESTED);
break;
@@ -371,8 +370,8 @@
if (fWorkerThread >= 0) {
if (Logger::IsDebugEnabled())
- printf("quit requested while worker thread is operating
-- will "
- "try again once the worker thread has
completed\n");
+ HDINFO0("quit requested while worker thread is
operating -- will "
+ "try again once the worker thread has
completed")
fQuitRequestedDuringWorkerThread = true;
return false;
}
@@ -531,9 +530,9 @@
if (Logger::IsDebugEnabled()) {
if (token.IsEmpty())
- printf("authentication failed\n");
+ HDINFO0("authentication failed")
else
- printf("authentication successful\n");
+ HDINFO0("authentication successful")
}
BMessenger messenger(this);
@@ -751,9 +750,8 @@
}
}
if (result == B_OK) {
- if (Logger::IsDebugEnabled())
- printf("successfully completed collection of
create account "
- "data from the server in background
thread\n");
+ HDDEBUG0("successfully completed collection of create
account "
+ "data from the server in background thread")
messenger.SendMessage(&message);
} else {
debugger("unable to configure the "
@@ -887,9 +885,7 @@
void
UserLoginWindow::_HandleCreateAccountSetupSuccess(BMessage* message)
{
- if (Logger::IsDebugEnabled())
- printf("handling account setup success\n");
-
+ HDDEBUG0("handling account setup success")
BMessage captchaMessage;
BMessage userUsageConditionsMessage;
@@ -909,8 +905,7 @@
void
UserLoginWindow::_SetCaptcha(Captcha* captcha)
{
- if (Logger::IsDebugEnabled())
- printf("setting captcha\n");
+ HDDEBUG0("setting captcha")
if (fCaptcha != NULL)
delete fCaptcha;
fCaptcha = captcha;
@@ -936,8 +931,7 @@
UserLoginWindow::_SetUserUsageConditions(
UserUsageConditions* userUsageConditions)
{
- if (Logger::IsDebugEnabled())
- printf("setting user usage conditions\n");
+ HDDEBUG0("setting user usage conditions")
if (fUserUsageConditions != NULL)
delete fUserUsageConditions;
fUserUsageConditions = userUsageConditions;
@@ -1275,8 +1269,8 @@
BString debugString;
_ValidationFailuresToString(validationFailures,
debugString);
- printf("create account validation
issues; %s\n",
- debugString.String());
+ HDDEBUG1("create account validation
issues; %s",
+ debugString.String())
}
BMessage validationFailuresMessage;
validationFailures.Archive(&validationFailuresMessage);
diff --git a/src/apps/haikudepot/ui/UserUsageConditionsWindow.cpp
b/src/apps/haikudepot/ui/UserUsageConditionsWindow.cpp
index 2a11afe..dbb2dfc 100644
--- a/src/apps/haikudepot/ui/UserUsageConditionsWindow.cpp
+++ b/src/apps/haikudepot/ui/UserUsageConditionsWindow.cpp
@@ -215,10 +215,8 @@
if (fWorkerThread == -1)
return true;
- if (Logger::IsInfoEnabled()) {
- fprintf(stderr, "unable to quit when the user usage "
- "conditions window is still fetching data\n");
- }
+ HDINFO0("unable to quit when the user usage "
+ "conditions window is still fetching data")
return false;
}
@@ -360,25 +358,21 @@
break;
}
} else {
- fprintf(stderr, "an error has arisen communicating with the"
+ HDERROR1("an error has arisen communicating with the"
" server to obtain data for a user's user usage
conditions"
- " [%s]\n", strerror(result));
+ " [%s]", strerror(result))
ServerHelper::NotifyTransportError(result);
}
if (result == B_OK) {
BString userUsageConditionsCode = userDetail.Agreement().Code();
- if (Logger::IsDebugEnabled()) {
- printf("the user [%s] has agreed to uuc [%s]\n",
- interface.Nickname().String(),
- userUsageConditionsCode.String());
- }
+ HDDEBUG2("the user [%s] has agreed to uuc [%s]",
+ interface.Nickname().String(),
+ userUsageConditionsCode.String())
code.SetTo(userUsageConditionsCode);
} else {
- if (Logger::IsDebugEnabled()) {
- printf("unable to get details of the user [%s]\n",
- interface.Nickname().String());
- }
+ HDDEBUG1("unable to get details of the user [%s]",
+ interface.Nickname().String())
}
return result;
@@ -400,8 +394,7 @@
UserUsageConditionsWindow::_SetWorkerThread(thread_id thread)
{
if (!Lock()) {
- if (Logger::IsInfoEnabled())
- fprintf(stderr, "failed to lock window\n");
+ HDERROR0("failed to lock window")
} else {
fWorkerThread = thread;
Unlock();
diff --git a/src/apps/haikudepot/ui_generic/SharedBitmap.cpp
b/src/apps/haikudepot/ui_generic/SharedBitmap.cpp
index 6bc3f1a..4342e5f 100644
--- a/src/apps/haikudepot/ui_generic/SharedBitmap.cpp
+++ b/src/apps/haikudepot/ui_generic/SharedBitmap.cpp
@@ -1,12 +1,12 @@
/*
* Copyright 2013-2014, Stephan Aßmus <superstippi@xxxxxx>.
+ * Copyright 2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "SharedBitmap.h"
#include <algorithm>
-#include <stdio.h>
#include <Application.h>
#include <Bitmap.h>
@@ -17,6 +17,8 @@
#include <Resources.h>
#include <TranslationUtils.h>
+#include "Logger.h"
+
#include "support.h"
@@ -98,8 +100,8 @@
} else
fSize = 0;
} else {
- fprintf(stderr, "SharedBitmap(): Stream too large: %" B_PRIi64
- ", max: %" B_PRIi64 "\n", fSize, kMaxSize);
+ HDERROR2("SharedBitmap(): Stream too large: %" B_PRIi64
+ ", max: %" B_PRIi64, fSize, kMaxSize)
}
fBitmap[0] = NULL;
diff --git a/src/apps/haikudepot/util/LanguageMenuUtils.cpp
b/src/apps/haikudepot/util/LanguageMenuUtils.cpp
index b2289ef..22aeab7 100644
--- a/src/apps/haikudepot/util/LanguageMenuUtils.cpp
+++ b/src/apps/haikudepot/util/LanguageMenuUtils.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2019, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2019-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "LanguageMenuUtils.h"
@@ -23,8 +23,8 @@
LanguageMenuUtils::AddLanguagesToMenu(
const LanguageList& languages, BMenu* menu)
{
- if (languages.IsEmpty() && Logger::IsInfoEnabled())
- printf("there are no languages defined\n");
+ if (languages.IsEmpty())
+ HDINFO0("there are no languages defined")
int32 addedPopular = LanguageMenuUtils::_AddLanguagesToMenu(
languages, menu, true);
@@ -35,11 +35,9 @@
int32 addedNonPopular = LanguageMenuUtils::_AddLanguagesToMenu(
languages, menu, false);
- if (Logger::IsDebugEnabled()) {
- printf("did add %" B_PRId32 " popular languages and %" B_PRId32
- " non-popular languages to a menu\n", addedPopular,
- addedNonPopular);
- }
+ HDDEBUG2("did add %" B_PRId32 " popular languages and %" B_PRId32
+ " non-popular languages to a menu", addedPopular,
+ addedNonPopular)
}
@@ -56,8 +54,8 @@
languageCode, menu);
if (index == -1) {
- printf("unable to find the language [%s] in the menu\n",
- languageCode.String());
+ HDINFO1("unable to find the language [%s] in the menu",
+ languageCode.String())
menu->ItemAt(0)->SetMarked(true);
}
else
diff --git a/src/apps/haikudepot/util/StorageUtils.cpp
b/src/apps/haikudepot/util/StorageUtils.cpp
index 9f742ea..2a39ff2 100644
--- a/src/apps/haikudepot/util/StorageUtils.cpp
+++ b/src/apps/haikudepot/util/StorageUtils.cpp
@@ -5,7 +5,6 @@
#include "StorageUtils.h"
-#include <stdio.h>
#include <errno.h>
#include <Directory.h>
@@ -86,13 +85,9 @@
RemoveDirectoryContents(directoryEntryPath);
if (remove(directoryEntryPath.Path()) == 0) {
- if (Logger::IsDebugEnabled()) {
- fprintf(stdout, "did delete [%s]\n",
- directoryEntryPath.Path());
- }
+ HDDEBUG1("did delete [%s]",
directoryEntryPath.Path())
} else {
- fprintf(stderr, "unable to delete [%s]\n",
- directoryEntryPath.Path());
+ HDERROR1("unable to delete [%s]",
directoryEntryPath.Path())
result = B_ERROR;
}
}
@@ -167,17 +162,13 @@
result = ExistsObject(path, &exists, NULL, NULL);
if (result == B_OK && exists) {
- if (Logger::IsTraceEnabled()) {
- printf("an object exists at the candidate path "
- "[%s] - it will be deleted\n", path.Path());
- }
+ HDTRACE1("an object exists at the candidate path "
+ "[%s] - it will be deleted", path.Path())
if (remove(path.Path()) == 0) {
- if (Logger::IsTraceEnabled()) {
- printf("did delete the candidate file [%s]\n",
path.Path());
- }
+ HDTRACE1("did delete the candidate file [%s]",
path.Path())
} else {
- printf("unable to delete the candidate file [%s]\n",
path.Path());
+ HDERROR1("unable to delete the candidate file [%s]",
path.Path())
result = B_ERROR;
}
}
@@ -185,8 +176,8 @@
if (result == B_OK) {
BFile file(path.Path(), O_WRONLY | O_CREAT);
if (file.Write(buffer, 16) != 16) {
- printf("unable to write test data to candidate file
[%s]\n",
- path.Path());
+ HDERROR1("unable to write test data to candidate file
[%s]",
+ path.Path())
result = B_ERROR;
}
}
@@ -195,15 +186,15 @@
BFile file(path.Path(), O_RDONLY);
uint8 readBuffer[16];
if (file.Read(readBuffer, 16) != 16) {
- printf("unable to read test data from candidate file
[%s]\n",
- path.Path());
+ HDERROR1("unable to read test data from candidate file
[%s]",
+ path.Path())
result = B_ERROR;
}
for (int i = 0; result == B_OK && i < 16; i++) {
if (readBuffer[i] != buffer[i]) {
- printf("mismatched read..write check on
candidate file [%s]\n",
- path.Path());
+ HDERROR1("mismatched read..write check on
candidate file [%s]",
+ path.Path())
result = B_ERROR;
}
}
@@ -245,8 +236,8 @@
path.SetTo(resultPath.Path());
else {
path.Unset();
- fprintf(stdout, "unable to find the user cache file for "
- "[%s] data; %s\n", leaf.String(), strerror(result));
+ HDERROR2("unable to find the user cache file for "
+ "[%s] data; %s", leaf.String(), strerror(result))
}
return result;
@@ -280,8 +271,8 @@
path.SetTo(resultPath.Path());
else {
path.Unset();
- fprintf(stdout, "unable to find the user cache directory for "
- "[%s] data; %s\n", leaf.String(), strerror(result));
+ HDERROR2("unable to find the user cache directory for "
+ "[%s] data; %s", leaf.String(), strerror(result))
}
return result;
diff --git a/src/apps/haikudepot/util/ToFileUrlProtocolListener.cpp
b/src/apps/haikudepot/util/ToFileUrlProtocolListener.cpp
index 2624f35..1ac6b74 100644
--- a/src/apps/haikudepot/util/ToFileUrlProtocolListener.cpp
+++ b/src/apps/haikudepot/util/ToFileUrlProtocolListener.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2018, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
+ * Copyright 2017-2020, Andrew Lindesay <apl@xxxxxxxxxxxxxx>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
@@ -8,8 +8,7 @@
#include <File.h>
#include <HttpRequest.h>
-#include <stdio.h>
-
+#include "Logger.h"
ToFileUrlProtocolListener::ToFileUrlProtocolListener(BPath path,
BString traceLoggingIdentifier, bool traceLogging)
@@ -59,8 +58,8 @@
int32 statusCode = httpResult.StatusCode();
if (!BHttpRequest::IsSuccessStatusCode(statusCode)) {
- fprintf(stdout, "received http status %" B_PRId32
- " --> will not store download to file\n", statusCode);
+ HDINFO1("received http status %" B_PRId32
+ " --> will not store download to file", statusCode)
fShouldDownload = false;
}
@@ -84,7 +83,7 @@
} while (remaining > 0 && written > 0);
if (remaining > 0)
- fprintf(stdout, "unable to write all of the data to the
file\n");
+ HDERROR0("unable to write all of the data to the file")
}
}
@@ -113,10 +112,7 @@
ToFileUrlProtocolListener::DebugMessage(BUrlRequest* caller,
BUrlProtocolDebugMessage type, const char* text)
{
- if (fTraceLogging) {
- fprintf(stdout, "url->file <%s>; %s\n",
- fTraceLoggingIdentifier.String(), text);
- }
+ HDTRACE2("url->file <%s>; %s", fTraceLoggingIdentifier.String(), text)
}
--
To view, visit https://review.haiku-os.org/c/haiku/+/3018
To unsubscribe, or for help writing mail filters, visit
https://review.haiku-os.org/settings
Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I025970707a0a11e7e3aaa4b52fc91288af0183f5
Gerrit-Change-Number: 3018
Gerrit-PatchSet: 1
Gerrit-Owner: Andrew Lindesay <apl@xxxxxxxxxxxxxx>
Gerrit-MessageType: newchange