Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 98 lines (74 sloc) 3.133 kb
780ffad @sigma project rename, due to name conflict
authored
1 ;;; logito.el --- logging library for Emacs
605c611 @sigma first version
authored
2
3 ;; Copyright (C) 2012 Yann Hodique
4
5 ;; Author: Yann Hodique <yann.hodique@gmail.com>
6 ;; Keywords: lisp, tool
7 ;; Version: 0.1
8 ;; Package-Requires: ((eieio "1.3"))
9
10 ;; This file is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This file is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; This module provides logging facility for Emacs
28
29 ;;; Code:
30
31 (eval-when-compile
32 (require 'cl))
33
34 (require 'eieio)
35
780ffad @sigma project rename, due to name conflict
authored
36 (defclass logito-object ()
bb41434 @sigma don't log anything by default
authored
37 ((level :initarg :level :initform nil)))
516fc10 @sigma introduce buffer-based and message-based logger implementations
authored
38
780ffad @sigma project rename, due to name conflict
authored
39 (defmethod logito-insert-log ((log logito-object) format &rest objects)
516fc10 @sigma introduce buffer-based and message-based logger implementations
authored
40 "Base implementation, do nothing")
41
780ffad @sigma project rename, due to name conflict
authored
42 (defmethod logito-should-log ((log logito-object) level)
bb41434 @sigma don't log anything by default
authored
43 (let ((l (oref log :level)))
44 (and (integerp l)
45 (<= level l))))
605c611 @sigma first version
authored
46
780ffad @sigma project rename, due to name conflict
authored
47 (defmethod logito-log ((log logito-object) level tag string &rest objects)
48 (when (logito-should-log log level)
49 (apply 'logito-insert-log log (format "[%s] %s" tag string) objects)))
605c611 @sigma first version
authored
50
780ffad @sigma project rename, due to name conflict
authored
51 (defmethod logito-log (log level tag string &rest objects)
e3e4a68 @sigma make doc more explicit
authored
52 "Fallback implementation, do nothing. This allows in particular
7cab261 @sigma fix result for dummy implementation
authored
53 to pass nil as the log object."
54 nil)
516fc10 @sigma introduce buffer-based and message-based logger implementations
authored
55
780ffad @sigma project rename, due to name conflict
authored
56 (defclass logito-message-object (logito-object)
516fc10 @sigma introduce buffer-based and message-based logger implementations
authored
57 ())
58
780ffad @sigma project rename, due to name conflict
authored
59 (defmethod logito-insert-log ((log logito-message-object) format &rest objects)
c655ea4 @sigma better argument naming
authored
60 (apply 'message format objects))
516fc10 @sigma introduce buffer-based and message-based logger implementations
authored
61
780ffad @sigma project rename, due to name conflict
authored
62 (defclass logito-buffer-object (logito-object)
516fc10 @sigma introduce buffer-based and message-based logger implementations
authored
63 ((buffer :initarg :buffer :initform nil)))
64
780ffad @sigma project rename, due to name conflict
authored
65 (defmethod logito-should-log ((log logito-buffer-object) level)
516fc10 @sigma introduce buffer-based and message-based logger implementations
authored
66 (and (oref log :buffer)
67 (call-next-method)))
68
780ffad @sigma project rename, due to name conflict
authored
69 (defmethod logito-insert-log ((log logito-buffer-object) format &rest objects)
516fc10 @sigma introduce buffer-based and message-based logger implementations
authored
70 (let ((buffer (get-buffer-create (oref log :buffer))))
71 (with-current-buffer buffer
72 (goto-char (point-max))
c655ea4 @sigma better argument naming
authored
73 (insert (apply 'format format objects) "\n\n"))))
605c611 @sigma first version
authored
74
824acb8 @sigma new approach to default levels, more compatible with byte-compilation
authored
75 (defmacro logito-def-level (sym val &optional pkg)
780ffad @sigma project rename, due to name conflict
authored
76 "Define a constant logito-<SYM>-level and a macro logito:<SYM>
e6597df @sigma doc for function logger-def-level
authored
77 associated with this level."
824acb8 @sigma new approach to default levels, more compatible with byte-compilation
authored
78 (let* ((pkg (or pkg 'logito))
79 (const (intern (format "%s:%s-level"
80 (symbol-name pkg) (symbol-name sym))))
81 (mac (intern (format "%s:%s"
82 (symbol-name pkg) (symbol-name sym)))))
605c611 @sigma first version
authored
83 `(progn
84 (defconst ,const ,val)
85 (defmacro ,mac (log string &rest objects)
516fc10 @sigma introduce buffer-based and message-based logger implementations
authored
86 (append
780ffad @sigma project rename, due to name conflict
authored
87 (list 'logito-log log ,const '',sym string)
516fc10 @sigma introduce buffer-based and message-based logger implementations
authored
88 objects)))))
605c611 @sigma first version
authored
89
1382abd @sigma allow to define logging helpers in remote packages
authored
90 ;; built-in log levels
824acb8 @sigma new approach to default levels, more compatible with byte-compilation
authored
91 (logito-def-level error 0)
92 (logito-def-level info 5)
93 (logito-def-level verbose 10)
94 (logito-def-level debug 15)
780ffad @sigma project rename, due to name conflict
authored
95
96 (provide 'logito)
97 ;;; logito.el ends here
Something went wrong with that request. Please try again.