0

I am working with Python and I am using RotatingFileHandler to log to some file. I have a very simple question

I am logging like this -

zooklogger.info("steps:: Actual Steps :: Workflow Path :: Host Path %s %s %s" % (steps, wf_path, status_path))

And this is how it is getting logged -

steps:: Actual Steps :: Workflow Path :: Host Path [u'step3', u'step2', u'step1'] /re/wf/ius/v1 /re/colo/phx/h1/wf/ius/v1

Is there any way that it can be logged as -

steps:: Actual Steps :: [u'step3', u'step2', u'step1'], Workflow Path :: /re/wf/ius/v1, Host Path :: /re/colo/phx/h1/wf/ius/v1

I know its a pretty silly question to ask but not able to figure out.

1 Answer 1

1

Sure, just move the %s placeholders:

zooklogger.info("steps:: Actual Steps :: %s, Workflow Path :: %s, Host Path :: %s" % (steps, wf_path, status_path))

The three strings are interpolated into the string at those locations.

Note that you can leave the interpolation step to the logging module; it'll postpone interpolating the values to the last moment; that way it doesn't do that work if the log entry never reaches a handler, for example:

zooklogger.info("steps:: Actual Steps :: %s, Workflow Path :: %s, Host Path :: %s",
                steps, wf_path, status_path)

Here the three arguments are passed in separately to the logger.info() call.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.