Quantcast

Logging in new IPython

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Logging in new IPython

Gökhan SEVER-2
Hello,

I am still using an older IPython (v0.10) I plan to transition to the new version soon. Could anybody tell me if it's possible to fully log an Ipython session with proper timestamps? My current solution is still based on the approach posted here -> http://ipython.scipy.org/moin/Cookbook/Logging

Does the new sql-based history provide this functionality or what's the recommended practice from the dev team for automatic session logging?

Thanks.

--
Gökhan

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

Thomas Kluyver-2
On 2 August 2011 22:49, Gökhan Sever <[hidden email]> wrote:
I am still using an older IPython (v0.10) I plan to transition to the new version soon. Could anybody tell me if it's possible to fully log an Ipython session with proper timestamps? My current solution is still based on the approach posted here -> http://ipython.scipy.org/moin/Cookbook/Logging

Does the new sql-based history provide this functionality or what's the recommended practice from the dev team for automatic session logging?

The new history effectively stores this information - there's a timestamp on the start and end of your session, and every line is recorded in order. But we've not yet written any way to access it except inside IPython itself. You can use a tool like SQLite browser to inspect the database directly - the structure isn't very complex.

The logging functionality is still there as well, although that recipe will need updating a bit to work with 0.11. I think the neatest thing to do is to put the code into a separate file and get the config to load it via exec_lines. (There might be a better way to load the file as an extension - I haven't looked into that bit of code).

Thanks,
Thomas

P.S. Our wiki is moving - see http://wiki.ipython.org/

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

Gökhan SEVER-2


On Tue, Aug 2, 2011 at 4:36 PM, Thomas Kluyver <[hidden email]> wrote:
On 2 August 2011 22:49, Gökhan Sever <[hidden email]> wrote:
I am still using an older IPython (v0.10) I plan to transition to the new version soon. Could anybody tell me if it's possible to fully log an Ipython session with proper timestamps? My current solution is still based on the approach posted here -> http://ipython.scipy.org/moin/Cookbook/Logging

Does the new sql-based history provide this functionality or what's the recommended practice from the dev team for automatic session logging?

The new history effectively stores this information - there's a timestamp on the start and end of your session, and every line is recorded in order. But we've not yet written any way to access it except inside IPython itself. You can use a tool like SQLite browser to inspect the database directly - the structure isn't very complex.

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.
 

The logging functionality is still there as well, although that recipe will need updating a bit to work with 0.11. I think the neatest thing to do is to put the code into a separate file and get the config to load it via exec_lines. (There might be a better way to load the file as an extension - I haven't looked into that bit of code).

Thanks,
Thomas

P.S. Our wiki is moving - see http://wiki.ipython.org/



--
Gökhan

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

Thomas Kluyver-2
On 3 August 2011 16:02, Gökhan Sever <[hidden email]> 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

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

Thomas Kluyver-2
On 3 August 2011 16:30, Thomas Kluyver <[hidden email]> wrote:
In fact, you might be able to import IPython.core.history to handle loading the database.

Looking at it, the code will need a few changes so HistoryManager can be started without having an InteractiveShell object as well. I'll look into this.

Thanks,
Thomas

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

Gökhan SEVER-2
In reply to this post by Thomas Kluyver-2
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 <[hidden email]> wrote:
On 3 August 2011 16:02, Gökhan Sever <[hidden email]> 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

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

Gökhan SEVER-2
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 <[hidden email]> 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 <[hidden email]> wrote:
>>
>> On 3 August 2011 16:02, Gökhan Sever <[hidden email]> 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
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

Thomas Kluyver-2
On 4 August 2011 05:03, Gökhan Sever <[hidden email]> wrote:
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.

It might be in  .config/ipython instead.

I should add that I don't think this situation is ideal - the ipython folder can be in two separate places, and I would have to look at the code to remember precisely when it uses which. For 0.12, I think we should decide on one location and stick with it.

Thomas

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

MinRK


On Aug 4, 2011, at 4:56, Thomas Kluyver <[hidden email]> wrote:

On 4 August 2011 05:03, Gökhan Sever <[hidden email]> wrote:
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.

It might be in  .config/ipython instead.

I should add that I don't think this situation is ideal - the ipython folder can be in two separate places, and I would have to look at the code to remember precisely when it uses which. For 0.12, I think we should decide on one location and stick with it.

IPython 0.11 respects the XDG spec (.config etc.). It will only use ~/.ipython if it already exists (existing users), or on platforms where XDG is not in use (generally OSX and Windows, but also when the XDG config dir doesn't exist).

So we have picked XDG, but that's obviously not something we should pick everywhere.  The only available change I see is to force the move from ~/.ipython to XDG on Linux unless users set IPYTHON_DIR=~/.ipython, but that doesn't sound good to me.



Thomas
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

Thomas Kluyver-2
On 4 August 2011 17:59, Min RK <[hidden email]> wrote:
IPython 0.11 respects the XDG spec (.config etc.). It will only use ~/.ipython if it already exists (existing users), or on platforms where XDG is not in use (generally OSX and Windows, but also when the XDG config dir doesn't exist).

So we have picked XDG, but that's obviously not something we should pick everywhere.  The only available change I see is to force the move from ~/.ipython to XDG on Linux unless users set IPYTHON_DIR=~/.ipython, but that doesn't sound good to me.

Except, technically, we don't adhere to the XDG spec, because we put everything in .config, while data stored from the program should technically be in .local.

My suggestion is just to return to ignoring the XDG spec, and stick with .ipython. That way, it's in the same place for all users. A quick look at my home directory shows we're not exactly bucking the trend - firefox, libreoffice, pip, bzr, etc. have hidden folders that don't follow XDG. I think having two different possibilities is an extra hurdle for users wanting to configure it, and it feels like we've done it for no better reason than that the spec exists.

Thomas

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

MinRK
In reply to this post by Gökhan SEVER-2
On Wed, Aug 3, 2011 at 21:03, Gökhan Sever <[hidden email]> 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?

No. Flags, etc. expect two leading '-', as is traditional for non
single-character command-line flags.  Since there are many documents,
and even books, that have `ipython -pylab`, it will probably be many
years before we actually let that raise an error, rather than warning
and transforming it into the expected form.

>
> Thanks for all your efforts and especially well-documenting the new changes.

We do our best, but there are certainly many holes in the
documentation, particularly with respect to configuration.

>
> More testing comes later...

Let us know how it goes.

>
>
> On Wed, Aug 3, 2011 at 3:16 PM, Gökhan Sever <[hidden email]> 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 <[hidden email]> wrote:
>>>
>>> On 3 August 2011 16:02, Gökhan Sever <[hidden email]> 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
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

MinRK
In reply to this post by Thomas Kluyver-2


On Thu, Aug 4, 2011 at 11:03, Thomas Kluyver <[hidden email]> wrote:
On 4 August 2011 17:59, Min RK <[hidden email]> wrote:
IPython 0.11 respects the XDG spec (.config etc.). It will only use ~/.ipython if it already exists (existing users), or on platforms where XDG is not in use (generally OSX and Windows, but also when the XDG config dir doesn't exist).

So we have picked XDG, but that's obviously not something we should pick everywhere.  The only available change I see is to force the move from ~/.ipython to XDG on Linux unless users set IPYTHON_DIR=~/.ipython, but that doesn't sound good to me.

Except, technically, we don't adhere to the XDG spec, because we put everything in .config, while data stored from the program should technically be in .local.

My suggestion is just to return to ignoring the XDG spec, and stick with .ipython. That way, it's in the same place for all users. A quick look at my home directory shows we're not exactly bucking the trend - firefox, libreoffice, pip, bzr, etc. have hidden folders that don't follow XDG. I think having two different possibilities is an extra hurdle for users wanting to configure it, and it feels like we've done it for no better reason than that the spec exists.

Well, we did it because a significant number of users asked us to, and it just makes sense to follow established standards.  Just because many other apps haven't caught up to standards doesn't mean we shouldn't.  I agree that it's an unfortunate hurdle during the transition, but moving forward ~/.config/ipython will be the standard on Linux, and only users who have been using IPython for a long time or have explicitly chosen the old location will still be using it.  

Perhaps in 0.12 we should print a deprecation message for ~/.ipython, and some time later enforce the move to XDG unless IPYTHON_DIR is set.

Also note that the first step for configuring IPython is always `ipython profile create[ foo]`, which tells you exactly where the files you want to edit were just created.  We can amend this to always print the locations, even when not generating the files anew.

-MinRK
 

Thomas


_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

Gökhan SEVER-2
In reply to this post by Gökhan SEVER-2
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.

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?
Also, can I get the same behavior via the command line interface?

Thanks.

On Wed, Aug 3, 2011 at 10:03 PM, Gökhan Sever <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
>>>
>>> On 3 August 2011 16:02, Gökhan Sever <[hidden email]> 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
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

MinRK


On Sat, Aug 6, 2011 at 14:43, Gökhan Sever <[hidden email]> 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

 
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
>>>
>>> On 3 August 2011 16:02, Gökhan Sever <[hidden email]> 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
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user


_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logging in new IPython

Gökhan SEVER-2
On Sat, Aug 6, 2011 at 3:59 PM, MinRK <[hidden email]> wrote:

>
>
> On Sat, Aug 6, 2011 at 14:43, Gökhan Sever <[hidden email]> 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 <[hidden email]>
>> 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 <[hidden email]>
>> > 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 <[hidden email]>
>> >> wrote:
>> >>>
>> >>> On 3 August 2011 16:02, Gökhan Sever <[hidden email]> 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
>> [hidden email]
>> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>



--
Gökhan
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Loading...