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

Support full logging to file #57

Closed
bitprophet opened this issue Aug 19, 2011 · 31 comments
Closed

Support full logging to file #57

bitprophet opened this issue Aug 19, 2011 · 31 comments
Milestone

Comments

@bitprophet
Copy link
Member

Description

Outside of any further modifications to the stdout/stderr output controls, it would be very handy to log everything to a file; this would give users another alternate channel for debugging their fabfiles without having to wrestle with what they see at runtime.

Main question is whether to output things as if debug were set, by default. Thinking to leave it off at first, and have a simple flag/option to turn it on, perhaps --log-debug.

Where to log to? By default I'd say user's cwd, though that can get annoying (like "pipturds", i.e. pip-log.txt files that pip drops everywhere.) Unfortunately there's no other great standard location, so perhaps turn logging-to-file off by default? Either way, allow override, say via --log-location or similar.

Unsure whether it makes any sense to utilize the logging module's concept of levels; the only place I can see it being useful at all is for the debug stuff, but we currently think of debugging as modifying output instead of adding to it -- which doesn't mesh with how logging works. So possibly best to just stick everything in, say, INFO for now, then tweak later if necessary.


Potential modules:

  • stdlib logging
    • Pros: stdlib, well known/documented
    • Cons: kind of byzantine/complicated to use
  • Logbook
    • Pros: Armin
  • Twiggy
  • Others?

Originally submitted by Jeff Forcier (bitprophet) on 2009-09-06 at 10:57am EDT

Relations

@ghost ghost assigned bitprophet Aug 19, 2011
@bitprophet
Copy link
Member Author

Travis Swicegood (tswicegood) posted:


Carrying over the conversation from #135, the core logging module is what should be used for all output. That gets logging to file for free as a side-effect, but more importantly provides a uniform way to handle formatting output.


on 2010-01-24 at 09:12pm EST

@bitprophet
Copy link
Member Author

Jeff Forcier (bitprophet) posted:


See #333 for a pull request that does some basic work in this area (though ATM it does not pass tests.)

Keep in mind that I want to at least quickly compare the existing logging modules to see if the non-stdlib ones offer enough benefits (cleaner APIs etc) over the stdlib one to be worth using.


on 2011-04-19 at 12:43pm EDT

@bitprophet
Copy link
Member Author

Jeff Forcier (bitprophet) posted:


Some prior art using the stdlib module can be found in this GH commit (came from a pull request)


on 2011-07-07 at 03:09pm EDT

@bitprophet
Copy link
Member Author

Jeff Forcier (bitprophet) posted:


And recent work by tswicegood, also using the stdlib module and wrapping it a bit, is here on Github


on 2011-07-07 at 03:38pm EDT

@bitprophet
Copy link
Member Author

Adding Invoke label since Invoke will need to log stuff too, and Fabric will then ride on that to some degree (while obviously logging a lot of its own stuff too.)

@andresriancho
Copy link

+1

@ijstokes
Copy link

A big +1 from me.

Has this been added to fabric yet? A bit of a chore to remember to pass every fab command through tee.

@agroszer
Copy link

yes please, that's somehow a must

@thedotedge
Copy link

👍

@josegonzalez
Copy link

@bitprophet is there something we can help with to bring this feature to life?

@hodduc
Copy link

hodduc commented Nov 26, 2013

👍

3 similar comments
@budlight
Copy link

+1

@chrisguidry
Copy link

👍

@loris
Copy link

loris commented Dec 20, 2013

+1

@josegonzalez
Copy link

The current hack I have for this is to set stdout and stderr to a fake logger class, which seems to work well enough for me:

https://github.com/josegonzalez/chef-solo-cup/blob/master/chef_solo_cup/commands/runner.py#L141

@josegonzalez
Copy link

Note: it seems like interactive shells - like asking for passwords - might break in my above implementation, so I still think it would be nice to have it in the core of fabric.

@dreampuf
Copy link

+1

I'm using a ad-hot decorator. But this decorator could not support execute function when the task was parallel running ( you can't get the stdout of multiprocess env )

class Buffered:
    def __init__(self, stream):
        self.stream = stream
        self.buf = []
    def write(self, data):
        self.buf.append(data)
        self.stream.write(data)
        self.stream.flush()
    def __getattr__(self, attr):
        return getattr(self.stream, attr)

def auto_comment(func):
    @wraps(func)
    def wraper(*args, **kws):
        _stdout = sys.stdout
        buffered = sys.stdout = Buffered(_stdout)
        ret = func(*args, **kws)
        if buffered.buf:
            # only pick last 500 lines is good enough
            echo_result = "".join(buffered.buf[-500:])
            # filter the colored results
            echo_result = re.sub("\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", "", echo_result)
            # using the result as you want 
        sys.stdout = _stdout
        return ret
    return wraper

@thedotedge
Copy link

Is there any plan to include this in the core any time soon?

@fruch
Copy link
Contributor

fruch commented Jul 28, 2014

+1

1 similar comment
@ghost
Copy link

ghost commented Aug 4, 2014

+1

@ChrisMarinos
Copy link

+1

1 similar comment
@mbra
Copy link

mbra commented Sep 19, 2014

👍

@msabramo
Copy link

I also would love a solution to this.

@hamiltont
Copy link

+1

Also, this may help others trying to build a streamlogger

@yshao
Copy link

yshao commented Dec 29, 2014

This feature would be nice to have!

@satels
Copy link

satels commented Jan 23, 2015

+1

2 similar comments
@zodman
Copy link

zodman commented May 15, 2015

+1

@marthjod
Copy link

+1

@zodman
Copy link

zodman commented Jun 12, 2015

i offer 10bucks for this feature!

@bitprophet
Copy link
Member Author

Rolling this into pyinvoke/invoke#15, updated its desc with a bunch of thoughts too.

@guhuajun
Copy link

guhuajun commented Aug 8, 2017

Sorry for replying a closed issue.
I am using https://github.com/algrebe/python-tee to redirect stdout to a file.
Hope this project can help others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests