Dave Sill wrote (on Apr 12, 1999):
> [EMAIL PROTECTED] wrote:
>
> >What are the advantages/disadvantages of cyclog over syslog?
[...]
> Disadvantages: only logs messages sent to stdout, only logs messages
> from local system, doesn't chunk logs by day/week/etc--only by size,
> dates/times aren't human-readable without "tailocal",
This last disadvantage can be perhaps better served, for those of
emacs persuasion, by the hack below.
--
Arnaldo Mandel
Computer Science Dept.
Universidade de S\~{a}o Paulo, Brazil
[EMAIL PROTECTED]
;;; tailocal.el - handles TAI time-stamps
;; Time-stamp: <1999/04/13 19:15:54 benavuya.ime.usp.br [benavuya.ime.usp.br] am>
;;; Copyright (C) 1999 Arnaldo Mandel
;;
;; Author: Arnaldo Mandel ([EMAIL PROTECTED])
;; Version: 0.1
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; This substitutes TAI time-stamps by readable timestamps.
;; Mostly usable for reading djb-style logfiles.
;;
;; If those are useful for you, you would probabley bind
;; the interactive functions to keys. Suggestion:
;; (eval-after-load "dired"
;; '(define-key dired-mode-map "\C-t" 'dired-decode-tai-filename))
;; (define-key text-mode-map "\C-xt" 'tailocal)
(defvar time-stamp-format "[%Y/%m/%d %T]")
(defconst tai-stamp "\\(^\\| \\)\\(\\([0-9]+\\)\\.[0-9]+\\) ")
(defun tai-to-local (num)
(format-time-string time-stamp-format
(cons (+ 12288 (ash num -16)) (mod num 65536))))
(defun match-tai ()
(if (re-search-forward tai-stamp (point-max) t)
(let ((num (string-to-number (match-string 3))))
(replace-match
(tai-to-local num) t t nil 2)
(backward-char)
t)))
(defun dired-decode-tai-filename ()
"Decodes the current filename as cyclog's @TAI."
(interactive)
(dired-move-to-filename)
(momentary-string-display
(tai-to-local
(string-to-number (buffer-substring (1+ (point)) (+ 15 (point))))) (point)))
; Alternative implementation. Maybe there should be a var deciding among these two
;(defun dired-decode-tai-filename ()
; "Decodes the current filename as cyclog's @TAI."
; (interactive)
; (message (tai-to-local (string-to-number (substring (dired-get-filename) -12)))))
(defun tailocal (from to)
"Converts tai time-stamps on REGION to human-readable ones."
(interactive "r")
(let ((vezes 0)
(matches 0)
(q 0)
(m (copy-marker to))
(bm (buffer-modified-p)))
(save-excursion
(message "Tailocalizing:")
;; Estimate number of tai-stamps, for feedback
(goto-char to)
(forward-line -1)
(setq q (point))
(forward-line -10)
(save-match-data
(while (re-search-forward tai-stamp q t)
(setq matches (1+ matches))))
(setq matches (/ (* matches (count-lines from to)) 10)
q (1+ (/ matches 100)))
;; Now do the work
(goto-char from)
(while (and (< (point) m)
(match-tai))
(setq vezes (1+ vezes))
(if (= (% vezes q) 0)
(message "Tailocalizing: %d%% done." (/ (* 100 vezes) matches)))))
(message "")
(set-buffer-modified-p bm)))