Skip to content

Commit

Permalink
Switch from lsst::pex::logging to lsst::log
Browse files Browse the repository at this point in the history
Replace logs at pex::logging::TTrace<5> (-5) using lsst::log DEBUG level
Replace logs at pex::logging DEBUG level (-10) using lsst::log TRACE level

In daf.persistence.PropertySetFormatter,
replace pex::logging Trace at level -20 using lsst::log TRACE level
  • Loading branch information
Hsin-Fang Chiang committed Aug 6, 2016
1 parent 711c365 commit ad8672d
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 43 deletions.
1 change: 0 additions & 1 deletion include/lsst/daf/persistence/PropertySetFormatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <lsst/daf/base/PropertySet.h>
#include "lsst/daf/base/DateTime.h"
#include <lsst/pex/exceptions.h>
#include <lsst/pex/logging/Trace.h>


using boost::serialization::make_nvp;
Expand Down
16 changes: 8 additions & 8 deletions python/lsst/daf/persistence/butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import yaml

import lsst.pex.logging as pexLog
from lsst.log import Log
import lsst.pex.policy as pexPolicy
from . import StorageList, LogicalLocation, ReadProxy, ButlerSubset, ButlerDataRef, Persistence, Repository, \
Access, Storage, Policy, NoResults, MultipleResults, Repository, DataId, RepositoryCfg, \
Expand Down Expand Up @@ -249,7 +249,8 @@ def __init__(self, root=None, mapper=None, inputs=None, outputs=None, **mapperAr
# Always use an empty Persistence policy until we can get rid of it
persistencePolicy = pexPolicy.Policy()
self.persistence = Persistence.getPersistence(persistencePolicy)
self.log = pexLog.Log(pexLog.Log.getDefaultLog(), "daf.persistence.butler")
self.log = Log.getLogger("daf.persistence.butler")
self.log.setLevel(Log.INFO)

inputs = listify(inputs)
outputs = listify(outputs)
Expand Down Expand Up @@ -563,9 +564,8 @@ def datasetExists(self, datasetType, dataId={}, **rest):
if not os.path.exists(logLoc):
return False
return True
self.log.log(pexLog.Log.WARN,
"datasetExists() for non-file storage %s, dataset type=%s, keys=%s" %
(storageName, datasetType, str(dataId)))
self.log.warn("datasetExists() for non-file storage %s, dataset type=%s, keys=%s",
storageName, datasetType, str(dataId))
return True


Expand All @@ -591,7 +591,7 @@ def get(self, datasetType, dataId=None, immediate=False, **rest):
if location is None:
raise NoResults("No locations for get:", datasetType, dataId)

self.log.log(pexLog.Log.DEBUG, "Get type=%s keys=%s from %s" % (datasetType, dataId, str(location)))
self.log.trace("Get type=%s keys=%s from %s", datasetType, dataId, str(location))

if hasattr(location.mapper, "bypass_" + datasetType):
# this type loader block should get moved into a helper someplace, and duplciations removed.
Expand Down Expand Up @@ -695,12 +695,12 @@ def dataRef(self, datasetType, level=None, dataId={}, **rest):


def _read(self, location):
trace = pexLog.BlockTimingLog(self.log, "read", pexLog.BlockTimingLog.INSTRUM+1)
self.log.debug("Starting reading from %s", location)
results = location.repository.read(location)
if len(results) == 1:
results = results[0]
return results
trace.done()
self.log.debug("Ending reading")

def __reduce__(self):
ret = (_unreduce, (self._initArgs, self.datasetTypeAliasDict))
Expand Down
2 changes: 0 additions & 2 deletions python/lsst/daf/persistence/persistenceLib.i
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ Access to the lsst::daf::persistence classes
#include "lsst/daf/persistence/DbStorage.h"
#include "lsst/daf/persistence/DbTsvStorage.h"
#include "lsst/daf/base.h"
#include "lsst/pex/logging.h"
#include "lsst/pex/policy.h"
%}

Expand All @@ -55,7 +54,6 @@ Access to the lsst::daf::persistence classes

%import "lsst/pex/exceptions/exceptionsLib.i"
%import "lsst/daf/base/baseLib.i"
%import "lsst/pex/logging/loggingLib.i"
%import "lsst/pex/policy/policyLib.i"

%newobject lsst::daf::persistence::Persistence::getPersistence;
Expand Down
7 changes: 4 additions & 3 deletions python/lsst/daf/persistence/posixStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import yaml

from . import LogicalLocation, Persistence, Policy, StorageList, Registry, Storage, RepositoryCfg, safeFileIo
import lsst.pex.logging as pexLog
from lsst.log import Log
import lsst.pex.policy as pexPolicy
from .safeFileIo import SafeFilename

Expand All @@ -43,7 +43,8 @@ def __init__(self, uri):
:return:
"""
self.log = pexLog.Log(pexLog.Log.getDefaultLog(), "daf.persistence.butler")
self.log = Log.getLogger("daf.persistence.butler")
self.log.setLevel(Log.INFO)
self.root = parseRes = urlparse.urlparse(uri).path
if self.root and not os.path.exists(self.root):
os.makedirs(self.root)
Expand Down Expand Up @@ -163,7 +164,7 @@ def write(self, butlerLocation, obj):
:param obj: the object to be written.
:return: None
"""
self.log.log(pexLog.Log.DEBUG, "Put location=%s obj=%s" % (butlerLocation, obj))
self.log.trace("Put location=%s obj=%s", butlerLocation, obj)

additionalData = butlerLocation.getAdditionalData()
storageName = butlerLocation.getStorageName()
Expand Down
9 changes: 6 additions & 3 deletions src/DbStorageImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,20 @@ static char const* SVNid __attribute__((unused)) = "$Id$";
#include <mysql/mysql.h>

#include "lsst/pex/exceptions.h"
#include "lsst/pex/logging/Trace.h"
#include "lsst/daf/persistence/DbStorageLocation.h"
#include "lsst/daf/persistence/LogicalLocation.h"
#include "lsst/daf/base/DateTime.h"
#include "lsst/log/Log.h"

namespace dafPer = lsst::daf::persistence;
namespace dafBase = lsst::daf::base;
namespace pexExcept = lsst::pex::exceptions;
namespace pexPolicy = lsst::pex::policy;

namespace {
LOG_LOGGER _log = LOG_GET("daf.persistence.DbStorage");
}

namespace lsst {
namespace daf {
namespace persistence {
Expand Down Expand Up @@ -254,8 +258,7 @@ void dafPer::DbStorageImpl::executeQuery(std::string const& query) {
if (_db == 0) {
error("No DB connection for query: " + query, false);
}
lsst::pex::logging::TTrace<5>("daf.persistence.DbStorage",
"Query: " + query);
LOGLS_DEBUG(_log, "Query: " << query);
if (mysql_query(_db, query.c_str()) != 0) {
error("Unable to execute query: " + query);
}
Expand Down
30 changes: 13 additions & 17 deletions src/LogicalLocation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ static char const* SVNid __attribute__((unused)) = "$Id$";

#include "boost/regex.hpp"
#include "lsst/pex/exceptions.h"
#include "lsst/pex/logging/Trace.h"
#include "lsst/log/Log.h"

namespace dafBase = lsst::daf::base;
namespace dafPersist = lsst::daf::persistence;
namespace pexExcept = lsst::pex::exceptions;
namespace pexLog = lsst::pex::logging;

namespace {
LOG_LOGGER _log = LOG_GET("daf.persistence.LogicalLocation");
}

dafBase::PropertySet::Ptr dafPersist::LogicalLocation::_map;

Expand All @@ -61,21 +64,19 @@ dafPersist::LogicalLocation::LogicalLocation(
boost::regex expr("(%.*?)\\((\\w+?)\\)");
boost::sregex_iterator i = make_regex_iterator(locString, expr);
boost::sregex_iterator last;
pexLog::TTrace<5>("daf.persistence.LogicalLocation",
"Input string: " + locString);
LOGLS_DEBUG(_log, "Input string: " << locString);
while (i != boost::sregex_iterator()) {
last = i;
if ((*i).prefix().matched) {
_locString += (*i).prefix().str();
}
std::string fmt = (*i).str(1);
std::string key = (*i).str(2);
pexLog::TTrace<5>("daf.persistence.LogicalLocation", "Key: " + key);
LOGLS_DEBUG(_log, "Key: " << key);
if (_map && _map->exists(key)) {
if (_map->typeOf(key) == typeid(int)) {
int value = _map->getAsInt(key);
pexLog::TTrace<5>("daf.persistence.LogicalLocation",
"Map Val: %d", value);
LOGLS_DEBUG(_log, "Map Val: " << value);
if (fmt == "%") {
_locString += (boost::format("%1%") % value).str();
}
Expand All @@ -85,16 +86,14 @@ dafPersist::LogicalLocation::LogicalLocation(
}
else {
std::string value = _map->getAsString(key);
pexLog::TTrace<5>("daf.persistence.LogicalLocation",
"Map Val: " + value);
LOGLS_DEBUG(_log, "Map Val: " << value);
_locString += value;
}
}
else if (additionalData && additionalData->exists(key)) {
if (additionalData->typeOf(key) == typeid(int)) {
int value = additionalData->getAsInt(key);
pexLog::TTrace<5>("daf.persistence.LogicalLocation",
"Map Val: %d", value);
LOGLS_DEBUG(_log, "Map Val: " << value);
if (fmt == "%") {
_locString += (boost::format("%1%") % value).str();
}
Expand All @@ -104,8 +103,7 @@ dafPersist::LogicalLocation::LogicalLocation(
}
else {
std::string value = additionalData->getAsString(key);
pexLog::TTrace<5>("daf.persistence.LogicalLocation",
"Map Val: " + value);
LOGLS_DEBUG(_log, "Map Val: " << value);
_locString += value;
}
}
Expand All @@ -117,13 +115,11 @@ dafPersist::LogicalLocation::LogicalLocation(
}
if (last == boost::sregex_iterator()) {
_locString = locString;
pexLog::TTrace<5>("daf.persistence.LogicalLocation",
"Copy to: " + _locString);
LOGLS_DEBUG(_log, "Copy to: " << _locString);
}
else {
_locString += (*last).suffix().str();
pexLog::TTrace<5>("daf.persistence.LogicalLocation",
"Result: " + _locString);
LOGLS_DEBUG(_log, "Result: " << _locString);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/PropertySetFormatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ static char const* SVNid __attribute__((unused)) = "$Id$";
#include "lsst/daf/persistence/DbStorage.h"
#include "lsst/daf/persistence/XmlStorage.h"
#include <lsst/pex/exceptions.h>
#include <lsst/pex/logging/Trace.h>
#include <lsst/log/Log.h>
#include <lsst/pex/policy/Policy.h>

namespace {
auto _log = LOG_GET("daf.persistence.PropertySetFormatter");
}

#define EXEC_TRACE 20
static void execTrace(std::string s, int level = EXEC_TRACE) {
lsst::pex::logging::Trace("daf.persistence.PropertySetFormatter", level, s);
static void execTrace(std::string s) {
LOGLS_TRACE(_log, s);
}

namespace dafBase = lsst::daf::base;
Expand Down
4 changes: 2 additions & 2 deletions tests/LogicalLocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
from lsst.daf.persistence import LogicalLocation
from lsst.daf.base import PropertySet

import lsst.pex.logging
lsst.pex.logging.Trace_setVerbosity("daf.persistence.LogicalLocation", 10)
import lsst.log
lsst.log.setLevel("daf.persistence.LogicalLocation", lsst.log.TRACE)

class LogicalLocationTestCase(unittest.TestCase):
"""A test case for LogicalLocation."""
Expand Down
1 change: 0 additions & 1 deletion tests/PropertySetPersist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include <lsst/daf/base/PropertySet.h>
#include <lsst/daf/base/Citizen.h>
#include <lsst/pex/logging/Trace.h>
#include <lsst/utils/Utils.h>

#include "lsst/pex/policy/Policy.h"
Expand Down
2 changes: 1 addition & 1 deletion ups/daf_persistence.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lsst.sconsUtils

dependencies = {
"required": ["daf_base", "pex_logging", "pex_policy", "mariadbclient",
"required": ["daf_base", "log", "pex_policy", "mariadbclient",
"boost_serialization"],
"buildRequired": ["boost_test", "swig"],
}
Expand Down
2 changes: 1 addition & 1 deletion ups/daf_persistence.table
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
setupRequired(log)
setupRequired(mariadbclient)
setupRequired(pex_logging)
setupRequired(pex_policy)
setupRequired(pyfits)
setupRequired(pyyaml)
Expand Down

0 comments on commit ad8672d

Please sign in to comment.