From 337d819782c93ffae082eb33cf0ea61b5c0dea1b Mon Sep 17 00:00:00 2001 From: mmichalek Date: Fri, 9 Oct 2015 12:01:11 -0400 Subject: [PATCH] Logging fixes. --- symmetric-client-clib/src/common/SymLog.c | 10 +++++++--- symmetric-client-clib/src/db/SymDialectFactory.c | 5 +++++ symmetric-client-clib/src/service/DataLoaderService.c | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/symmetric-client-clib/src/common/SymLog.c b/symmetric-client-clib/src/common/SymLog.c index d33739ddbf..ebf20744cc 100644 --- a/symmetric-client-clib/src/common/SymLog.c +++ b/symmetric-client-clib/src/common/SymLog.c @@ -58,10 +58,10 @@ char *generateTimestamp() { void SymLog_log(LogLevel logLevel, const char *functionName, const char *fileName, int lineNumber, const char* message, ...) { FILE *destination; if (logLevel <= INFO) { - destination = stdin; + destination = stdout; } else { - destination = stdout; + destination = stderr; } char* levelDescription = logLevelDescription(logLevel); @@ -87,7 +87,11 @@ void SymLog_log(LogLevel logLevel, const char *functionName, const char *fileNam messageBuffer->append(messageBuffer, "\n"); - printf("%s", messageBuffer->toString(messageBuffer)); + fprintf(destination, "%s", messageBuffer->toString(messageBuffer)); + + // stdout may not flush before stderr does. + // Do this to keep log messages more or less in order. + fflush(destination); messageBuffer->destroy(messageBuffer); free(logTimestamp); diff --git a/symmetric-client-clib/src/db/SymDialectFactory.c b/symmetric-client-clib/src/db/SymDialectFactory.c index 23dd7cc9f8..a4f8017e57 100644 --- a/symmetric-client-clib/src/db/SymDialectFactory.c +++ b/symmetric-client-clib/src/db/SymDialectFactory.c @@ -23,6 +23,11 @@ SymDialect * SymDialectFactory_create(SymDatabasePlatform *platform) { SymDialect *dialect = NULL; + + if (platform == NULL) { + SymLog_error("No Database platform provided. (platform == NULL)"); + } + if (strcmp(platform->name, SYM_DATABASE_SQLITE) == 0) { dialect = (SymDialect *) SymSqliteDialect_new(NULL, platform); } else { diff --git a/symmetric-client-clib/src/service/DataLoaderService.c b/symmetric-client-clib/src/service/DataLoaderService.c index 9641f50e95..54336ca9fa 100644 --- a/symmetric-client-clib/src/service/DataLoaderService.c +++ b/symmetric-client-clib/src/service/DataLoaderService.c @@ -67,7 +67,7 @@ void SymDataLoaderService_loadDataFromRegistration(SymDataLoaderService *this, S char *registrationUrl = this->parameterService->getRegistrationUrl(this->parameterService); SymIncomingTransport *transport = this->transportManager->getRegisterTransport(this->transportManager, local, registrationUrl); - SymLog_info("Using registration URL of %s\n", transport->getUrl(transport)); + SymLog_info("Using registration URL of %s", transport->getUrl(transport)); SymNode *remote = SymNode_new(NULL); remote->syncUrl = registrationUrl;