Skip to content

Commit

Permalink
* put the new logging stuff behind the sauron-log-events variable; ad…
Browse files Browse the repository at this point in the history
…d documentation
  • Loading branch information
djcb committed Apr 1, 2012
1 parent 7c461e6 commit c7aae29
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
10 changes: 9 additions & 1 deletion README.org
Expand Up @@ -206,6 +206,14 @@
#+end_example


*** Seeing /all/ events

Sometimes, you may want to see /all/ events instead of filtering them, for
example for debugging purposes. For this, there is the variable
=sauron-log-events=. If you set it to =t=, /all/ events will be shown in a
buffer names =*Sauron Log*=. This buffer shows up to
=sauron-log-buffer-max-lines= (default: 1000) lines of the last events.

** connecting to alert.el

John Wiegley's [[https://github.com/jwiegley/alert][alert.el]] has a bit of overlap with sauron; however, I've added
Expand Down Expand Up @@ -301,7 +309,7 @@

You also need to enable the web client support in Transmission - it's in the
'Web' tab of the preferences dialog.

Note, if you start transmission before you start your session, see `Using D-Bus
outside your session'.

Expand Down
29 changes: 21 additions & 8 deletions sauron.el
Expand Up @@ -89,6 +89,10 @@ nick. Must be < 65536")
"Maximum length of messages in the log (longer messages will be
truncated. If set to nil, there is no maximum.")

(defvar sauron-log-events nil
"Whether to show write all Sauron events (even the filtered ones)
to the sauron log buffer.")

(defvar sauron-log-buffer-max-lines 1000
"Maximum number of messages to store in the sauron log buffer.
Messages are removed from the buffer when the total number
Expand Down Expand Up @@ -206,9 +210,9 @@ e.g. when using ERC")
"*internal* Name of the sauron buffer.")

(defvar sr-log-buffer nil
"*internal* The sauron log buffer")
"*internal* The sauron log buffer.")

(defconst sr-log-buffer-name " *Sauron Log*"
(defconst sr-log-buffer-name "*Sauron Log*"
"*internal* Name of the sauron log buffer.")

This comment has been minimized.

Copy link
@tkf

tkf Apr 1, 2012

Contributor

Well, the leading space was intended one. I think many packages use it for buffers you want to hide "deeply". For example, anything-filelist+ (a command in anything.el to show buffers and files) does not show the buffer starting with space. But I don't have strong opinion for this; maybe you should not hide this buffer so deeply. I just wanted to differentiate it from the *Sauron* buffer.

This comment has been minimized.

Copy link
@djcb

djcb via email Apr 1, 2012

Author Owner

This comment has been minimized.

Copy link
@tkf

tkf Apr 1, 2012

Contributor

OK. Thanks for the nice package!


(defvar sr-nick-event-hash nil
Expand Down Expand Up @@ -382,6 +386,15 @@ For debugging purposes."
(goto-char (point-max))
(recenter -1))))

(defun sr-add-to-log (line)
"Add LINE to the Sauron log buffer."
(unless (buffer-live-p sr-log-buffer)
(setq sr-log-buffer (sr-create-buffer-maybe sr-log-buffer-name)))
(with-current-buffer sr-log-buffer
(goto-char (point-max))
(insert line)
(sr-clear-log-buffer-maybe)))


;; the main work horse function
(defun sauron-add-event (origin prio msg &optional func props)
Expand Down Expand Up @@ -423,11 +436,10 @@ PROPS an origin-specific property list that will be passed to the hook funcs."
line))
(line (concat (propertize line 'callback func) "\n"))
(inhibit-read-only t))
(with-current-buffer
(setq sr-log-buffer (sr-create-buffer-maybe sr-log-buffer-name))
(goto-char (point-max))
(insert line))
(sr-clear-log-buffer-maybe)

;; when logging is enabled, write the line to the sauron log as well
(when sauron-log-events (sr-add-to-log line))

(when (and (>= prio sauron-min-priority)
(null (sr-ignore-errors-maybe
;; ignore errors unless we're debugging
Expand Down Expand Up @@ -579,11 +591,12 @@ sauron buffer."


(defun sr-clear-log-buffer-maybe ()
"Clear the sauon log "
(when sr-log-buffer
(with-current-buffer sr-log-buffer
(save-excursion
(let ((lines (count-lines (point-min) (point-max)))
(inhibit-read-only t))
(inhibit-read-only t))
(when (> lines sauron-log-buffer-max-lines)
(forward-line (- sauron-log-buffer-max-lines lines))
(delete-region (point-min) (point))))))))
Expand Down

0 comments on commit c7aae29

Please sign in to comment.