fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fab-user] print vs. logging


From: Bruno Clermont
Subject: [Fab-user] print vs. logging
Date: Thu, 15 Oct 2009 15:11:01 -0400

Hi,

Thanks for Fabric! With it, I wrote many deployment scripts. Once I
considered it stable enough, I wrote a django web interface to let my
users easily invoke those fabric scripts. I just import fabric
directly from my views, setĀ fabric.state.env.host_string and
fabric.state.env.key_filename before running the equivalent of a
fabfile.py.

It work perfectly.

The only thing that don't fit is the way fabric print output of
operations. It print straight into stdout.

Is it feasible to use python logging module instead of print?

Instead of something like (from fabric.operations._run_command):

    if output.debug:
        print("[%s] run: %s" % (env.host_string, wrapped_command))
    elif output.running:
        print("[%s] run: %s" % (env.host_string, given_command))

having a:

    env.log.debug("[%s] run: %s" % (env.host_string, wrapped_command))
    env.log.info("[%s] run: %s" % (env.host_string, given_command))

and give the user the ability to alter the behavior of env.log (such
as send to a file, syslog and stdout).
by default just send to the local console at logging.INFO level.

Maybe It's a bad idea... I don't know, I always used python scripts
for my own needs... in my case, I've used env.__dict__['log'] =
logging.getLogger('fabric') to have a global log handler for all my
classes. Using python logging give so much flexibility to the user,
while keeping the code clean.

I quickly hacked a clone git for fun and migrate all print to logging
and it seem to work fine.

What do you think of this?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]