From b60f8b4989b100a97a0182d957368d819f05fadb Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 16 Jan 2016 15:49:58 -0600 Subject: [PATCH] New log class for terrasync --- simgear/debug/debug_types.h | 3 +- simgear/debug/logstream.cxx | 1 + simgear/io/DAVMultiStatus.cxx | 8 ++--- simgear/io/SVNDirectory.cxx | 10 +++--- simgear/io/SVNRepository.cxx | 10 +++--- simgear/scene/tsync/terrasync.cxx | 52 +++++++++++++++---------------- 6 files changed, 43 insertions(+), 41 deletions(-) diff --git a/simgear/debug/debug_types.h b/simgear/debug/debug_types.h index 82773287..c6f31c26 100644 --- a/simgear/debug/debug_types.h +++ b/simgear/debug/debug_types.h @@ -32,7 +32,8 @@ typedef enum { SG_SOUND = 0x00200000, SG_NAVAID = 0x00400000, SG_GUI = 0x00800000, - SG_UNDEFD = 0x01000000, // For range checking + SG_TERRASYNC = 0x01000000, + SG_UNDEFD = 0x02000000, // For range checking SG_ALL = 0xFFFFFFFF } sgDebugClass; diff --git a/simgear/debug/logstream.cxx b/simgear/debug/logstream.cxx index 4290f5ca..699cae06 100644 --- a/simgear/debug/logstream.cxx +++ b/simgear/debug/logstream.cxx @@ -71,6 +71,7 @@ const char* debugClassToString(sgDebugClass c) case SG_SOUND: return "sound"; case SG_NAVAID: return "navaid"; case SG_GUI: return "gui"; + case SG_TERRASYNC: return "terrasync"; default: return "unknown"; } } diff --git a/simgear/io/DAVMultiStatus.cxx b/simgear/io/DAVMultiStatus.cxx index a805a214..6a82a0c5 100644 --- a/simgear/io/DAVMultiStatus.cxx +++ b/simgear/io/DAVMultiStatus.cxx @@ -193,7 +193,7 @@ public: { if (tagStack.empty()) { if (strcmp(name, DAV_MULTISTATUS_TAG)) { - SG_LOG(SG_IO, SG_WARN, "root element is not " << + SG_LOG(SG_TERRASYNC, SG_WARN, "root element is not " << DAV_MULTISTATUS_TAG << ", got:" << name); } else { @@ -202,7 +202,7 @@ public: // not at the root element if (tagStack.back() == DAV_MULTISTATUS_TAG) { if (strcmp(name, DAV_RESPONSE_TAG)) { - SG_LOG(SG_IO, SG_WARN, "multistatus child is not response: saw:" + SG_LOG(SG_TERRASYNC, SG_WARN, "multistatus child is not response: saw:" << name); } } @@ -362,7 +362,7 @@ void DAVMultiStatus::parseXML(const char* data, int size) } if (!XML_Parse(_d->xmlParser, data, size, false)) { - SG_LOG(SG_IO, SG_WARN, "DAV parse error:" << XML_ErrorString(XML_GetErrorCode(_d->xmlParser)) + SG_LOG(SG_TERRASYNC, SG_WARN, "DAV parse error:" << XML_ErrorString(XML_GetErrorCode(_d->xmlParser)) << " at line:" << XML_GetCurrentLineNumber(_d->xmlParser) << " column " << XML_GetCurrentColumnNumber(_d->xmlParser)); @@ -376,7 +376,7 @@ void DAVMultiStatus::finishParse() { if (_d->parserInited) { if (!XML_Parse(_d->xmlParser, NULL, 0, true)) { - SG_LOG(SG_IO, SG_WARN, "DAV parse error:" << XML_ErrorString(XML_GetErrorCode(_d->xmlParser)) + SG_LOG(SG_TERRASYNC, SG_WARN, "DAV parse error:" << XML_ErrorString(XML_GetErrorCode(_d->xmlParser)) << " at line:" << XML_GetCurrentLineNumber(_d->xmlParser) << " column " << XML_GetCurrentColumnNumber(_d->xmlParser)); _d->valid = false; diff --git a/simgear/io/SVNDirectory.cxx b/simgear/io/SVNDirectory.cxx index 5cce0c61..a4ef9bc5 100644 --- a/simgear/io/SVNDirectory.cxx +++ b/simgear/io/SVNDirectory.cxx @@ -96,14 +96,14 @@ void SVNDirectory::parseCache() LineState lineState = LINESTATE_HREF; std::ifstream file(p.c_str()); if (!file.is_open()) { - SG_LOG(SG_IO, SG_WARN, "unable to open cache file for reading:" << p); + SG_LOG(SG_TERRASYNC, SG_WARN, "unable to open cache file for reading:" << p); return; } bool doneSelf = false; file.getline(href, 1024); if (strcmp(CACHE_VERSION_4_TOKEN, href)) { - SG_LOG(SG_IO, SG_WARN, "invalid cache file [missing header token]:" << p << " '" << href << "'"); + SG_LOG(SG_TERRASYNC, SG_WARN, "invalid cache file [missing header token]:" << p << " '" << href << "'"); return; } @@ -183,7 +183,7 @@ void SVNDirectory::writeCache() void SVNDirectory::setBaseUrl(const string& url) { if (_parent) { - SG_LOG(SG_IO, SG_ALERT, "setting base URL on non-root directory " << url); + SG_LOG(SG_TERRASYNC, SG_ALERT, "setting base URL on non-root directory " << url); return; } @@ -248,7 +248,7 @@ void SVNDirectory::deleteChildByName(const std::string& nm) Dir d(path); bool ok = d.remove(true); if (!ok) { - SG_LOG(SG_NETWORK, SG_ALERT, "SVNDirectory::deleteChildByName: failed to remove dir:" + SG_LOG(SG_TERRASYNC, SG_ALERT, "SVNDirectory::deleteChildByName: failed to remove dir:" << nm << " at path:\n\t" << path); } @@ -261,7 +261,7 @@ void SVNDirectory::deleteChildByName(const std::string& nm) } else { bool ok = path.remove(); if (!ok) { - SG_LOG(SG_NETWORK, SG_ALERT, "SVNDirectory::deleteChildByName: failed to remove path:" << nm + SG_LOG(SG_TERRASYNC, SG_ALERT, "SVNDirectory::deleteChildByName: failed to remove path:" << nm << " at path:\n\t" << path); } } diff --git a/simgear/io/SVNRepository.cxx b/simgear/io/SVNRepository.cxx index c67f6007..88a70c7a 100644 --- a/simgear/io/SVNRepository.cxx +++ b/simgear/io/SVNRepository.cxx @@ -73,7 +73,7 @@ public: void updateFailed(HTTP::Request* req, SVNRepository::ResultCode err) { - SG_LOG(SG_IO, SG_WARN, "SVN: failed to update from:" << req->url() + SG_LOG(SG_TERRASYNC, SG_WARN, "SVN: failed to update from:" << req->url() << "\n(repository:" << p->baseUrl() << ")"); isUpdating = false; status = err; @@ -134,7 +134,7 @@ namespace { // anonmouse } else if (responseCode() == 404) { _repo->propFindFailed(this, SVNRepository::SVN_ERROR_NOT_FOUND); } else { - SG_LOG(SG_IO, SG_WARN, "request for:" << url() << + SG_LOG(SG_TERRASYNC, SG_WARN, "request for:" << url() << " return code " << responseCode()); _repo->propFindFailed(this, SVNRepository::SVN_ERROR_SOCKET); _repo = NULL; @@ -231,7 +231,7 @@ protected: _repo->updateFailed(this, SVNRepository::SVN_ERROR_NOT_FOUND); _failed = true; } else { - SG_LOG(SG_IO, SG_WARN, "SVN: request for:" << url() << + SG_LOG(SG_TERRASYNC, SG_WARN, "SVN: request for:" << url() << " got HTTP status " << responseCode()); _repo->updateFailed(this, SVNRepository::SVN_ERROR_HTTP); _failed = true; @@ -331,7 +331,7 @@ void SVNRepository::update() } if (_d->targetRevision == rootDir()->cachedRevision()) { - SG_LOG(SG_IO, SG_DEBUG, baseUrl() << " in sync at version " << _d->targetRevision); + SG_LOG(SG_TERRASYNC, SG_DEBUG, baseUrl() << " in sync at version " << _d->targetRevision); _d->isUpdating = false; return; } @@ -375,7 +375,7 @@ void SVNRepoPrivate::propFindComplete(HTTP::Request* req, DAVCollection* c) void SVNRepoPrivate::propFindFailed(HTTP::Request *req, SVNRepository::ResultCode err) { if (err != SVNRepository::SVN_ERROR_NOT_FOUND) { - SG_LOG(SG_IO, SG_WARN, "PropFind failed for:" << req->url()); + SG_LOG(SG_TERRASYNC, SG_WARN, "PropFind failed for:" << req->url()); } isUpdating = false; diff --git a/simgear/scene/tsync/terrasync.cxx b/simgear/scene/tsync/terrasync.cxx index db306efc..2ae77e45 100644 --- a/simgear/scene/tsync/terrasync.cxx +++ b/simgear/scene/tsync/terrasync.cxx @@ -228,7 +228,7 @@ protected: virtual void onFail() { - SG_LOG(SG_TERRAIN, SG_ALERT, "Failed to query TerraSync SVN server"); + SG_LOG(SG_TERRASYNC, SG_ALERT, "Failed to query TerraSync SVN server"); HTTP::Request::onFail(); } @@ -369,7 +369,7 @@ bool SGTerraSync::SvnThread::start() if (_local_dir=="") { - SG_LOG(SG_TERRAIN,SG_ALERT, + SG_LOG(SG_TERRASYNC,SG_ALERT, "Cannot start scenery download. Local cache directory is undefined."); _fail_count++; _stalled = true; @@ -379,7 +379,7 @@ bool SGTerraSync::SvnThread::start() SGPath path(_local_dir); if (!path.exists()) { - SG_LOG(SG_TERRAIN,SG_ALERT, + SG_LOG(SG_TERRASYNC,SG_ALERT, "Cannot start scenery download. Directory '" << _local_dir << "' does not exist. Set correct directory path or create directory folder."); _fail_count++; @@ -390,7 +390,7 @@ bool SGTerraSync::SvnThread::start() path.append("version"); if (path.exists()) { - SG_LOG(SG_TERRAIN,SG_ALERT, + SG_LOG(SG_TERRASYNC,SG_ALERT, "Cannot start scenery download. Directory '" << _local_dir << "' contains the base package. Use a separate directory."); _fail_count++; @@ -403,7 +403,7 @@ bool SGTerraSync::SvnThread::start() if ((!_use_svn)&&(_rsync_server=="")) { - SG_LOG(SG_TERRAIN,SG_ALERT, + SG_LOG(SG_TERRASYNC,SG_ALERT, "Cannot start scenery download. Rsync scenery server is undefined."); _fail_count++; _stalled = true; @@ -435,7 +435,7 @@ bool SGTerraSync::SvnThread::start() // not really an alert - but we want to (always) see this message, so user is // aware we're downloading scenery (and using bandwidth). - SG_LOG(SG_TERRAIN,SG_ALERT, + SG_LOG(SG_TERRASYNC,SG_ALERT, "Starting automatic scenery download/synchronization. " << status << "Directory: '" << _local_dir << "'."); @@ -475,7 +475,7 @@ bool SGTerraSync::SvnThread::runExternalSyncCommand(const char* dir) #else command = buf.str(); #endif - SG_LOG(SG_TERRAIN,SG_DEBUG, "sync command '" << command << "'"); + SG_LOG(SG_TERRASYNC,SG_DEBUG, "sync command '" << command << "'"); #ifdef SG_WINDOWS // tbd: does Windows support "popen"? @@ -490,7 +490,7 @@ bool SGTerraSync::SvnThread::runExternalSyncCommand(const char* dir) if (rc) { - SG_LOG(SG_TERRAIN,SG_ALERT, + SG_LOG(SG_TERRASYNC,SG_ALERT, "Failed to synchronize directory '" << dir << "', " << "error code= " << rc); return false; @@ -505,7 +505,7 @@ void SGTerraSync::SvnThread::run() { if (_svn_server.empty()) { - SG_LOG(SG_TERRAIN,SG_INFO, "Querying closest TerraSync server"); + SG_LOG(SG_TERRASYNC,SG_INFO, "Querying closest TerraSync server"); ServerSelectQuery* ssq = new ServerSelectQuery; HTTP::Request_ptr req = ssq; _http.makeRequest(req); @@ -515,12 +515,12 @@ void SGTerraSync::SvnThread::run() if (req->readyState() == HTTP::Request::DONE) { _svn_server = ssq->svnUrl(); - SG_LOG(SG_TERRAIN,SG_INFO, "Closest TerraSync server:" << _svn_server); + SG_LOG(SG_TERRASYNC,SG_INFO, "Closest TerraSync server:" << _svn_server); } else { - SG_LOG(SG_TERRAIN,SG_WARN, "Failed to query closest TerraSync server"); + SG_LOG(SG_TERRASYNC,SG_WARN, "Failed to query closest TerraSync server"); } } else { - SG_LOG(SG_TERRAIN,SG_INFO, "Explicit: TerraSync server:" << _svn_server); + SG_LOG(SG_TERRASYNC,SG_INFO, "Explicit: TerraSync server:" << _svn_server); } if (_svn_server.empty()) { @@ -551,7 +551,7 @@ void SGTerraSync::SvnThread::runExternal() SyncItem::Status cacheStatus = isPathCached(next); if (cacheStatus != SyncItem::Invalid) { _cache_hits++; - SG_LOG(SG_TERRAIN, SG_DEBUG, + SG_LOG(SG_TERRASYNC, SG_DEBUG, "Cache hit for: '" << next._dir << "'"); next._status = cacheStatus; _freshTiles.push_back(next); @@ -581,7 +581,7 @@ void SGTerraSync::SvnThread::syncPathExternal(const SyncItem& next) if (isNewDirectory) { int rc = path.create_dir( 0755 ); if (rc) { - SG_LOG(SG_TERRAIN,SG_ALERT, + SG_LOG(SG_TERRASYNC,SG_ALERT, "Cannot create directory '" << path << "', return code = " << rc ); throw sg_exception("Cannot create directory for terrasync", path.str()); } @@ -606,8 +606,8 @@ void SGTerraSync::SvnThread::updateSyncSlot(SyncSlot &slot) if (slot.repository->isDoingSync()) { #if 1 if (slot.stamp.elapsedMSec() > (int)slot.nextWarnTimeout) { - SG_LOG(SG_TERRAIN, SG_INFO, "sync taking a long time:" << slot.currentItem._dir << " taken " << slot.stamp.elapsedMSec()); - SG_LOG(SG_TERRAIN, SG_INFO, "HTTP request count:" << _http.hasActiveRequests()); + SG_LOG(SG_TERRASYNC, SG_INFO, "sync taking a long time:" << slot.currentItem._dir << " taken " << slot.stamp.elapsedMSec()); + SG_LOG(SG_TERRASYNC, SG_INFO, "HTTP request count:" << _http.hasActiveRequests()); slot.nextWarnTimeout += 10000; } #endif @@ -622,7 +622,7 @@ void SGTerraSync::SvnThread::updateSyncSlot(SyncSlot &slot) fail(slot.currentItem); } else { updated(slot.currentItem, slot.isNewDirectory); - SG_LOG(SG_TERRAIN, SG_DEBUG, "sync of " << slot.repository->baseUrl() << " finished (" + SG_LOG(SG_TERRASYNC, SG_DEBUG, "sync of " << slot.repository->baseUrl() << " finished (" << slot.stamp.elapsedMSec() << " msec"); } @@ -642,7 +642,7 @@ void SGTerraSync::SvnThread::updateSyncSlot(SyncSlot &slot) if (slot.isNewDirectory) { int rc = path.create_dir( 0755 ); if (rc) { - SG_LOG(SG_TERRAIN,SG_ALERT, + SG_LOG(SG_TERRASYNC,SG_ALERT, "Cannot create directory '" << path << "', return code = " << rc ); fail(slot.currentItem); return; @@ -661,7 +661,7 @@ void SGTerraSync::SvnThread::updateSyncSlot(SyncSlot &slot) slot.nextWarnTimeout = 20000; slot.stamp.stamp(); slot.busy = true; - SG_LOG(SG_TERRAIN, SG_INFO, "sync of " << slot.repository->baseUrl() << " started, queue size is " << slot.queue.size()); + SG_LOG(SG_TERRASYNC, SG_INFO, "sync of " << slot.repository->baseUrl() << " started, queue size is " << slot.queue.size()); } } @@ -682,7 +682,7 @@ void SGTerraSync::SvnThread::runInternal() SyncItem::Status cacheStatus = isPathCached(next); if (cacheStatus != SyncItem::Invalid) { _cache_hits++; - SG_LOG(SG_TERRAIN, SG_DEBUG, "\nTerraSync Cache hit for: '" << next._dir << "'"); + SG_LOG(SG_TERRASYNC, SG_DEBUG, "\nTerraSync Cache hit for: '" << next._dir << "'"); next._status = cacheStatus; _freshTiles.push_back(next); _is_dirty = true; @@ -739,7 +739,7 @@ void SGTerraSync::SvnThread::fail(SyncItem failedItem) _fail_count++; failedItem._status = SyncItem::Failed; _freshTiles.push_back(failedItem); - SG_LOG(SG_TERRAIN,SG_INFO, + SG_LOG(SG_TERRASYNC,SG_INFO, "Faield to sync'" << failedItem._dir << "'"); _completedTiles[ failedItem._dir ] = now + UpdateInterval::FailedAttempt; _is_dirty = true; @@ -765,7 +765,7 @@ void SGTerraSync::SvnThread::updated(SyncItem item, bool isNewDirectory) time_t now = time(0); _consecutive_errors = 0; _success_count++; - SG_LOG(SG_TERRAIN,SG_INFO, + SG_LOG(SG_TERRASYNC,SG_INFO, "Successfully synchronized directory '" << item._dir << "'"); item._status = SyncItem::Updated; @@ -791,7 +791,7 @@ void SGTerraSync::SvnThread::initCompletedTilesPersistentCache() try { readProperties(_persistentCachePath.str(), cacheRoot); } catch (sg_exception& e) { - SG_LOG(SG_TERRAIN, SG_INFO, "corrupted persistent cache, discarding"); + SG_LOG(SG_TERRASYNC, SG_INFO, "corrupted persistent cache, discarding"); return; } @@ -852,7 +852,7 @@ SGTerraSync::SGTerraSync() : _inited(false) { _svnThread = new SvnThread(); - _log = new BufferedLogCallback(SG_TERRAIN, SG_INFO); + _log = new BufferedLogCallback(SG_TERRASYNC, SG_INFO); _log->truncateAt(255); sglog().addCallback(_log); @@ -977,13 +977,13 @@ void SGTerraSync::update(double) { if (_svnThread->_stalled) { - SG_LOG(SG_TERRAIN,SG_ALERT, + SG_LOG(SG_TERRASYNC,SG_ALERT, "Automatic scenery download/synchronization stalled. Too many errors."); } else { // not really an alert - just always show this message - SG_LOG(SG_TERRAIN,SG_ALERT, + SG_LOG(SG_TERRASYNC,SG_ALERT, "Automatic scenery download/synchronization has stopped."); } _stalledNode->setBoolValue(_svnThread->_stalled); -- 2.39.5