[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] print vs. logging
From: |
Christian Vest Hansen |
Subject: |
Re: [Fab-user] print vs. logging |
Date: |
Fri, 16 Oct 2009 09:41:16 +0200 |
On Thu, Oct 15, 2009 at 9:11 PM, Bruno Clermont
<address@hidden> wrote:
> 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.
Don't you risk being bitten by the globally shared mutable state that
is `env`? I mean, what if two people simultaneously start two
different scripts?
>
> 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?
>
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/fab-user
>
--
Venlig hilsen / Kind regards,
Christian Vest Hansen.