[IPython-User] Logging in new IPython

Gökhan Sever gokhansever@gmail....
Sat Aug 6 19:21:12 CDT 2011


On Sat, Aug 6, 2011 at 3:59 PM, MinRK <benjaminrk@gmail.com> wrote:
>
>
> On Sat, Aug 6, 2011 at 14:43, Gökhan Sever <gokhansever@gmail.com> wrote:
>>
>> Hi,
>>
>> You already have logging option in IPython. I forgot mentioning of
>> this functionality before. When I look into the sqlite database, I
>> couldn't see timestamps associated with commands. However the
>> classical logging in IPython allows timestamping of commands.
>
> I've never used the IPython logging output, so I didn't know it had a
> timestamp :)
> You are right that there are not timestamps associated with individual
> commands in the sqlite history, they are only associated with sessions as a
> whole.  It would probably be valuable to add timestamps to individual
> commands as well.  I believe I asked for this, but was outvoted, since it
> would add cost to each execution, and people would rarely be interested in
> the extra information.
>
>>
>> So far, the following options seems the best scenario for me for
>> logging the activity in IPython.
>>  %logstart -t -r "ipy_log.txt" global
>>
>> What is the right place to put this magic just before I start typing?
>
> The right place is InteractiveShellApp.exec_lines in a config file:
> c.InteractiveShellApp.exec_lines = ["%logstart -t -r 'ipy_log.txt' "] # or
> append, if you already have other lines

This is the solution that fits my need best. sqlite to text pathway is
not very preferable since it requires extra steps plus the timestamps
are missing.  Added your lines into ipython_config.py and
ipython_qtconsole_config.py. I didnt see them before doing ipython
profile create under ~/.config/ipython/profile_default

In qtconsole_config.py I put a slightly modified version of that line as:

c.IPKernelApp.exec_lines = ["%logstart -t -r 'ipy_log.txt' global"]

These works very well for me.  I have habit of taking notes to myself
within IPython. This configuration will help me to continue this
exercise for a while.

Thanks for your replies.
>
>>
>> Also, can I get the same behavior via the command line interface?
>
> There's approximately nothing you can do in a config file that you can't on
> the command-line.  The easiest way to start IPython with logging immediately
> from the command-line is:
> ipython -i --c="%logstart -t -r 'ipy_log.txt'"
> '-c' is a shortcut for appending a single line to the end of exec_lines.
>  The '-i' prevents IPython from exiting after running the command.
> (you will get the natural '-c cmd' syntax back when PR #74 reinstates
> argparse for parsing)
> -MinRK
>>
>> Thanks.
>>
>> On Wed, Aug 3, 2011 at 10:03 PM, Gökhan Sever <gokhansever@gmail.com>
>> wrote:
>> > Hello,
>> >
>> > Finally, I get the new Ipython running. qtconsole is up too. I
>> > installed v0.11 The very first thing I have noticed is there is not
>> > .ipython folder under my home directory.
>> >
>> > ipython -help and ipython -help-all provides a lot of reading for
>> > tomorrow :)
>> >
>> > I have an alias in .bashrc as:
>> > # fixed after getting a single dash deprecation warning for pylab
>> > alias ii='ipython --pylab'
>> >
>> > Now typing "ii"
>> > WARNING: `-pylab` flag has been deprecated.
>> >    Use `--pylab` instead, or `--pylab=foo` to specify a backend.
>> >
>> > Is this warning temporary?
>> >
>> > Thanks for all your efforts and especially well-documenting the new
>> > changes.
>> >
>> > More testing comes later...
>> >
>> >
>> > On Wed, Aug 3, 2011 at 3:16 PM, Gökhan Sever <gokhansever@gmail.com>
>> > wrote:
>> >> Hi,
>> >> I tend to log my sessions and index them via full-text searching tool
>> >> called
>> >> "recoll" along with many other files (indeed tons of them). Being able
>> >> to
>> >> have IPython history in the form of text would make my life easier
>> >> since
>> >> recoll can easily crawl text files. In addition, recoll has a command
>> >> line
>> >> tool to dump xapian database into a text file with some basic text
>> >> statistics options. This way, I can easily get statistics about my most
>> >> used
>> >> Python commands and such.
>> >> I plan to upgrade my beloved IPython v0.10 to the new release tonight.
>> >> I
>> >> will let you know how my experience goes with the new one. Hopefully, I
>> >> will
>> >> figure out a way to get text outputs from the sqlite saved logs.
>> >> Thanks,
>> >>
>> >> On Wed, Aug 3, 2011 at 9:30 AM, Thomas Kluyver <takowl@gmail.com>
>> >> wrote:
>> >>>
>> >>> On 3 August 2011 16:02, Gökhan Sever <gokhansever@gmail.com> wrote:
>> >>>>
>> >>>> Thanks for the answer Thomas. Is there a way to dump the sqlite
>> >>>> database
>> >>>> to a text file? Since time-stamping automatically added in the
>> >>>> database, I
>> >>>> don't see a particular reason for using another logging mechanism.
>> >>>
>> >>> There's no tool for that at present, but if you feel like writing one,
>> >>> it
>> >>> shouldn't be too complex. The file is
>> >>> .ipython/profile_default/history.sqlite. You can extract timestamps
>> >>> from the
>> >>> session table, and then use the session number to select rows from the
>> >>> history table (and the output_history table if you've turned on output
>> >>> logging as well). In fact, you might be able to import
>> >>> IPython.core.history
>> >>> to handle loading the database.
>> >>>
>> >>> Thanks,
>> >>> Thomas
>> >>
>> >>
>> >>
>> >> --
>> >> Gökhan
>> >>
>> >
>> >
>> >
>> > --
>> > Gökhan
>> >
>>
>>
>>
>> --
>> Gökhan
>> _______________________________________________
>> IPython-User mailing list
>> IPython-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>



-- 
Gökhan


More information about the IPython-User mailing list