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

Convert ctrl_pool code to lsst.log #8

Merged
merged 1 commit into from
Dec 16, 2016
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
2 changes: 1 addition & 1 deletion config/log4cxx.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ log4j.appender.A1.Target=System.err
log4j.appender.A1.layout=PatternLayout
log4j.appender.A1.layout.ConversionPattern=%X{PID} %-5p %c: %m%n
log4j.appender.F1=org.apache.log4j.FileAppender
log4j.appender.F1.File=jobs.log
log4j.appender.F1.File=job_${JOBNAME}.log
log4j.appender.F1.layout=PatternLayout
log4j.appender.F1.layout.ConversionPattern=%X{PID} %-5p %d{yyyy-MM-ddThh:mm:ss.sss} %c (%X{LABEL})(%F:%L)- %m%n
19 changes: 4 additions & 15 deletions python/lsst/ctrl/pool/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,25 @@
import copyreg

import lsst.log as lsstLog
import lsst.pex.logging as pexLog
from lsst.utils import getPackageDir



def pickleLog(log):
"""Pickle a log

Drop the log on the floor; we'll get a new default.
Assumes that we're always just using the default log,
and not modifying it.
Assumes that we're always just using the lsst.log default.
"""
return pexLog.getDefaultLog, tuple()


def pickleLsstLog(log):
"""Pickle a lsst.log.Log"""
return lsstLog.Log, tuple()

copyreg.pickle(pexLog.Log, pickleLog)
copyreg.pickle(pexLog.ScreenLog, pickleLog)
copyreg.pickle(lsstLog.Log, pickleLsstLog)
copyreg.pickle(lsstLog.Log, pickleLog)


def jobLog(job):
"""Add a job-specific log destination"""
if job is None or job == "None":
return
machine = os.uname()[1].split(".")[0]
pexLog.getDefaultLog().addDestination(job + ".%s.%d" % (machine, os.getpid()))
packageDir = getPackageDir("ctrl_pool")
# Set the environment variable which names the output file
os.environ['JOBNAME'] = job
lsstLog.configure(os.path.join(packageDir, "config/log4cxx.properties"))
lsstLog.MDC("PID", os.getpid())
7 changes: 4 additions & 3 deletions python/lsst/ctrl/pool/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import contextlib
from lsst.pipe.base import CmdLineTask, TaskRunner
from .pool import startPool, Pool, NODE, abortOnError, setBatchType
from . import log # register pickle functions for pex_logging
from . import log # register pickle functions for log

__all__ = ["Batch", "PbsBatch", "SlurmBatch", "SmpBatch", "BATCH_TYPES", "BatchArgumentParser",
"BatchCmdLineTask", "BatchPoolTask", ]
Expand Down Expand Up @@ -63,8 +63,9 @@ def processStats():

def printProcessStats():
"""Print the process statistics to the log"""
from lsst.pex.logging import getDefaultLog
getDefaultLog().info("Process stats for %s: %s" % (NODE, processStats()))
from lsst.log import Log
log = Log.getDefaultLogger()
log.info("Process stats for %s: %s" % (NODE, processStats()))


class Batch(object):
Expand Down
1 change: 0 additions & 1 deletion ups/ctrl_pool.table
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
setupRequired(python_future)
setupRequired(daf_persistence)
setupRequired(pipe_base)
setupRequired(pex_logging)
setupRequired(log)
setupRequired(utils)
setupOptional(mpi4py)
Expand Down