[Python-ideas] natively logging sys.path modifications

Chris Angelico rosuav at gmail.com
Wed Jun 24 17:47:25 CEST 2015


On Wed, Jun 24, 2015 at 11:07 PM, anatoly techtonik <techtonik at gmail.com> wrote:
> sys.path is kind of important thing for troubleshooting. It may worth
> to ship it with a logging mechanism that allows to quickly dump
> who added what and (optionally) why.
>
> I see the log as a circular memory buffer of limited size, to say
> 256 entries, that contains tuples in the following format:
>
> path, who, where, why
>
>    path   -- actual path added to sys.path
>    who    -- the context - package.module:function or
>                          - package.module:class.method or
>                          - package.module:__toplevel__
>    where  -- full filename and line number to the instruction
>    why    -- advanced API may allow to set this field
>

It should be possible for you to replace sys.path with an object of
your own invention, a subclass of list that records the above
information whenever it's modified. Install that early, then let all
the other changes get logged. Or have you tried this and found that it
breaks something?

ChrisA


More information about the Python-ideas mailing list