all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to successively log stuff to a file?
@ 2014-02-03 23:41 Michael Heerdegen
  2014-02-04 12:36 ` Stephen Berman
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2014-02-03 23:41 UTC (permalink / raw
  To: emacs-devel

Hello,

I have written a little library for logging stuff, i.e. hit keys and
executed commands, messages, and file loads [1].

I want that you can define a dribble file where all my logged output
would be written to.  That would be a good help to reconstruct what you
did before a crash, or for writing bug reports (Yes, I know about
`open-dribble-file', but it's in C).

What is the smartest way to do that (in LISP, of course)?

I could save the buffer content to a file regularly.  To have a complete
log after crashes, I would have to save the buffer after each
keystroke.  This seems very dumb.

There is also `write-region'.  But that prints a message in the echo
area after each call, i.e. in my case, after each hit key.

Is there a smarter/cleverer/more low level way to do what I want?


Thanks,

Michael.


[1]  https://github.com/michael-heerdegen/interaction-log.el




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to successively log stuff to a file?
  2014-02-03 23:41 How to successively log stuff to a file? Michael Heerdegen
@ 2014-02-04 12:36 ` Stephen Berman
  2014-02-06  3:37   ` Michael Heerdegen
  2014-02-06  3:54   ` persistent file locks (was: How to successively log stuff to a file?) Michael Heerdegen
  0 siblings, 2 replies; 8+ messages in thread
From: Stephen Berman @ 2014-02-04 12:36 UTC (permalink / raw
  To: Michael Heerdegen; +Cc: emacs-devel

On Tue, 04 Feb 2014 00:41:00 +0100 Michael Heerdegen <michael_heerdegen@web.de> wrote:

> Hello,
>
> I have written a little library for logging stuff, i.e. hit keys and
> executed commands, messages, and file loads [1].
>
> I want that you can define a dribble file where all my logged output
> would be written to.  That would be a good help to reconstruct what you
> did before a crash, or for writing bug reports (Yes, I know about
> `open-dribble-file', but it's in C).
>
> What is the smartest way to do that (in LISP, of course)?
>
> I could save the buffer content to a file regularly.  To have a complete
> log after crashes, I would have to save the buffer after each
> keystroke.  This seems very dumb.
>
> There is also `write-region'.  But that prints a message in the echo
> area after each call, i.e. in my case, after each hit key.

You can suppress the message:

   write-region is an interactive built-in function in `C source code'.
   
   (write-region START END FILENAME &optional APPEND VISIT LOCKNAME MUSTBENEW)
   
   Write current region into specified file.
   [...]
   If VISIT is neither t nor nil nor a string,
     that means do not display the "Wrote file" message.

Steve Berman



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: How to successively log stuff to a file?
  2014-02-04 12:36 ` Stephen Berman
@ 2014-02-06  3:37   ` Michael Heerdegen
  2014-02-06  3:54   ` persistent file locks (was: How to successively log stuff to a file?) Michael Heerdegen
  1 sibling, 0 replies; 8+ messages in thread
From: Michael Heerdegen @ 2014-02-06  3:37 UTC (permalink / raw
  To: emacs-devel

Stephen Berman <stephen.berman@gmx.net> writes:

> > There is also `write-region'.  But that prints a message in the echo
> > area after each call, i.e. in my case, after each hit key.
>
> You can suppress the message:

Indeed, that works ok.  Thanks!

Michael.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* persistent file locks (was: How to successively log stuff to a file?)
  2014-02-04 12:36 ` Stephen Berman
  2014-02-06  3:37   ` Michael Heerdegen
@ 2014-02-06  3:54   ` Michael Heerdegen
  2014-02-06  6:21     ` Eli Zaretskii
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2014-02-06  3:54 UTC (permalink / raw
  To: emacs-devel

Stephen Berman <stephen.berman@gmx.net> writes:

> > I want that you can define a dribble file where all my logged output
> > would be written to. [...]
> > What is the smartest way to do that (in LISP, of course)?

I want now to use `write-region' for that.

When the user runs multiple Emacs processes, my lib should not cause
both processes to append to one and the same file.  I want to use Emacs
file locks for preventing that.  After reading
(info "(elisp) File Locks"), it seems that locks are handled only
implicitly, and are removed when the associated buffer is not modified
any more.  I need a persistent lock.  Is there a way to achieve this?
Or what would you recommend to do instead?

Thanks a lot,

Michael.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: persistent file locks (was: How to successively log stuff to a file?)
  2014-02-06  3:54   ` persistent file locks (was: How to successively log stuff to a file?) Michael Heerdegen
@ 2014-02-06  6:21     ` Eli Zaretskii
  2014-02-06  6:57       ` persistent file locks Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2014-02-06  6:21 UTC (permalink / raw
  To: Michael Heerdegen; +Cc: emacs-devel

> From: Michael Heerdegen <michael_heerdegen@web.de>
> Date: Thu, 06 Feb 2014 04:54:13 +0100
> 
> When the user runs multiple Emacs processes, my lib should not cause
> both processes to append to one and the same file.  I want to use Emacs
> file locks for preventing that.  After reading
> (info "(elisp) File Locks"), it seems that locks are handled only
> implicitly, and are removed when the associated buffer is not modified
> any more.  I need a persistent lock.  Is there a way to achieve this?
> Or what would you recommend to do instead?

Name the file with the Emacs PID in the file name?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: persistent file locks
  2014-02-06  6:21     ` Eli Zaretskii
@ 2014-02-06  6:57       ` Michael Heerdegen
  2014-02-06  8:34         ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2014-02-06  6:57 UTC (permalink / raw
  To: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> > When the user runs multiple Emacs processes, my lib should not cause
> > both processes to append to one and the same file.  I want to use Emacs
> > file locks for preventing that.  After reading
> > (info "(elisp) File Locks"), it seems that locks are handled only
> > implicitly, and are removed when the associated buffer is not modified
> > any more.  I need a persistent lock.  Is there a way to achieve this?
> > Or what would you recommend to do instead?
>
> Name the file with the Emacs PID in the file name?

Thanks.  That would work, but it would mean that I would either
pollute some user's directory with lots of differently named log files,
or I would have to implement some merging/removing mechanism for those.

I would prefer a solution with a constant log file name (additional
Emacs processes would just avoid logging if the file is locked, or
alternatively log into a different file named emacs-log~2 or so).

Eli, does your answer imply that there are only workaround solutions,
i.e., that there is no clean way to avoid automatic lock removal by
Emacs?

Thanks,

Michael.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: persistent file locks
  2014-02-06  6:57       ` persistent file locks Michael Heerdegen
@ 2014-02-06  8:34         ` Eli Zaretskii
  2014-02-07 12:27           ` Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2014-02-06  8:34 UTC (permalink / raw
  To: Michael Heerdegen; +Cc: emacs-devel

> From: Michael Heerdegen <michael_heerdegen@web.de>
> Date: Thu, 06 Feb 2014 07:57:52 +0100
> 
> Thanks.  That would work, but it would mean that I would either
> pollute some user's directory with lots of differently named log files,
> or I would have to implement some merging/removing mechanism for those.

I don't see why would you need all that complexity.  But then I don't
really understand what are your requirements for this feature.  Would
you care to state them?

> I would prefer a solution with a constant log file name (additional
> Emacs processes would just avoid logging if the file is locked, or
> alternatively log into a different file named emacs-log~2 or so).
> 
> Eli, does your answer imply that there are only workaround solutions,
> i.e., that there is no clean way to avoid automatic lock removal by
> Emacs?

I don't understand why would you need to lock the file in the first
place.  For starters, Emacs is quite capable of using the same file
from more than one session: it closes the file as soon as write-region
does its job.  If you want to distinguish between log entries from
different sessions, you can have the Emacs PID be part of the entry.

Lock files are a nuisance, because they need to be removed at the
right moment, and cause annoying user prompts if they aren't (e.g., if
Emacs crashed).  If I were you, I'd like to avoid that if possible.

As for using the user-lock feature: it is not intended to be used for
anything but what it is used now, and for that, it removes the lock as
soon as the file is saved or made unmodified in any other way.  It
will also do nothing if you try locking a file that is already locked
by the same Emacs session, which is probably not what you want.  And
it cannot be customized, i.e. the name of the lock file and its
contents cannot be controlled by a Lisp program.  So I don't think it
fits your bill.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: persistent file locks
  2014-02-06  8:34         ` Eli Zaretskii
@ 2014-02-07 12:27           ` Michael Heerdegen
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Heerdegen @ 2014-02-07 12:27 UTC (permalink / raw
  To: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> I don't understand why would you need to lock the file in the first
> place.  For starters, Emacs is quite capable of using the same file
> from more than one session: it closes the file as soon as write-region
> does its job.  If you want to distinguish between log entries from
> different sessions, you can have the Emacs PID be part of the entry.
>
> [...]

Ok, thanks for the background.  You've convinced me that I'd better not
use locks.  I think I'll follow your advice and just prepend each log
line with the pid.


Thanks again,

Michael.




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-02-07 12:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-03 23:41 How to successively log stuff to a file? Michael Heerdegen
2014-02-04 12:36 ` Stephen Berman
2014-02-06  3:37   ` Michael Heerdegen
2014-02-06  3:54   ` persistent file locks (was: How to successively log stuff to a file?) Michael Heerdegen
2014-02-06  6:21     ` Eli Zaretskii
2014-02-06  6:57       ` persistent file locks Michael Heerdegen
2014-02-06  8:34         ` Eli Zaretskii
2014-02-07 12:27           ` Michael Heerdegen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.