Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-26103: make lsst.log config in butler command conditional #365

Merged
merged 3 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/cli/butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def localCmdPkg(self):
"""localCmdPkg identifies the location of the commands that are in this
package. `getLocalCommands` assumes that the commands can be found in
`localCmdPkg.__all__`, if this is not the case then getLocalCommands
should be overrideen.
should be overridden.

Returns
-------
Expand All @@ -62,7 +62,7 @@ def localCmdPkg(self):
def getLocalCommands(self):
"""Get the commands offered by the local package. This assumes that the
commands can be found in `localCmdPkg.__all__`, if this is not the case
then this function should be overrideen.
then this function should be overridden.

Returns
-------
Expand Down
22 changes: 16 additions & 6 deletions python/lsst/daf/butler/cli/cliLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
import os

try:
import lsst.log as lsstLog
Expand All @@ -38,6 +39,12 @@


class CliLog:
"""Interface for managing python logging and lsst.log. Handles
initialization so that lsst.log is a handler for python logging.

Handles log uninitialization, which allows command line interface code that
initializes logging to run unit tests that execute in batches, without
affecting other unit tests. """

defaultLsstLogLevel = lsstLog.FATAL if lsstLog is not None else None

Expand All @@ -63,17 +70,20 @@ def initLog(cls, longlog):
"""
if cls._initialized:
# Unit tests that execute more than one command do end up
# calling this fucntion multiple times in one program execution,
# calling this function multiple times in one program execution,
# so do log a debug but don't log an error or fail, just make the
# re-initalization a no-op.
# re-initialization a no-op.
log = logging.getLogger(__name__.partition(".")[2])
log.debug("Log is already initialized, returning without re-initializing.")
return
cls._initialized = True

if lsstLog is not None:
# global logging config
lsstLog.configure_prop(_LOG_PROP.format(cls.longLogFmt if longlog else cls.normalLogFmt))
# Initialize global logging config. Skip if the env var
# LSST_LOG_CONFIG exists. The file it points to would already
# configure lsst.log.
if not os.path.isfile(os.environ.get("LSST_LOG_CONFIG", "")):
lsstLog.configure_prop(_LOG_PROP.format(cls.longLogFmt if longlog else cls.normalLogFmt))
cls._recordComponentSetting(None)
pythonLogger = logging.getLogger()
pythonLogger.setLevel(logging.INFO)
Expand Down Expand Up @@ -109,9 +119,9 @@ def resetLog(cls):
If the lsst.log handler was added to the python root logger's handlers
in `initLog`, it will be removed here.

For each loger level that was set by this class, sets that logger's
For each logger level that was set by this class, sets that logger's
level to the value it was before this class set it. For lsst.log, if a
component level was uninitialzed, it will be set to
component level was uninitialized, it will be set to
`Log.defaultLsstLogLevel` because there is no log4cxx api to set a
component back to an uninitialized state.
"""
Expand Down