• R/O
  • SSH

p36-log: Commit

P36-Log is a simple logging library for Common Lisp. Logging and
Debug Logging are conceptually separate in this library.


Commit MetaInfo

Revision7436eb3fc9d714726906eb4ec4636b18a4b169f6 (tree)
Zeit2019-12-17 17:02:36
AutorAlexa Jones-Gonzales <alexa@part...>
CommiterAlexa Jones-Gonzales

Log Message

Version bump - Added MULTI-LOGGER

Ändern Zusammenfassung

Diff

diff -r bd6646f72bac -r 7436eb3fc9d7 p36-log.asd
--- a/p36-log.asd Sun Oct 06 01:59:13 2019 -0600
+++ b/p36-log.asd Tue Dec 17 01:02:36 2019 -0700
@@ -26,7 +26,7 @@
2626 :long-name "P36-Log"
2727 :description "A logging library for Common Lisp"
2828
29- :version "0.3"
29+ :version "0.4"
3030 :license "GPLv3 (see LICENSE for details)"
3131
3232 :maintainer "Alexa Jones-Gonzales"
@@ -43,7 +43,8 @@
4343 (:file "globals")
4444 (:file "simple-logging")
4545 (:file "logger")
46- (:file "utils"))))
46+ (:file "utils")
47+ (:file "multi-logger"))))
4748
4849 :source-control "https://hg.osdn.net/view/p36-log/p36-log/")
4950
diff -r bd6646f72bac -r 7436eb3fc9d7 src/multi-logger.lisp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/multi-logger.lisp Tue Dec 17 01:02:36 2019 -0700
@@ -0,0 +1,105 @@
1+;;;; This file is part of P36-Log
2+;;;; Copyright (C) 2019 Alexa Jones-Gonzales <alexa@partition36.com>
3+;;;;
4+;;;; This program is free software: you can redistribute it and/or modify
5+;;;; it under the terms of the GNU General Public License as published by
6+;;;; the Free Software Foundation, either version 3 of the License, or
7+;;;; (at your option) any later version.
8+;;;;
9+;;;; This program is distributed in the hope that it will be useful,
10+;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+;;;; GNU General Public License for more details.
13+;;;;
14+;;;; You should have received a copy of the GNU General Public License
15+;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
16+(in-package :com.p36.p36-log)
17+
18+;;;;
19+;;;; Multi Logger Class
20+;;;;
21+
22+(defclass multi-logger (logger)
23+ ((other-loggers
24+ :initform (make-hash-table :test 'equal)
25+ :reader logger-other-loggers))
26+
27+ (:documentation "The MULTI-LOGGER class behaves just like a normal
28+ LOGGER by default. However, you can add additional LOGGERs via a
29+ hash table accessible with the LOGGER-OTHER-LOGGERS method. Whene
30+ calling any logging function with a multi-logger, all of the LOGGERs
31+ in this hash table will be logged to as well.
32+
33+ The keys in this hash table can be whatever you want, but the values
34+ should always be a LOGGER or some subclass of LOGGER."))
35+
36+(defun make-basic-multi-logger ()
37+ "Creates a new MULTI-LOGGER with the headers setup to output basic,
38+uncolored text. This does not affect colored text output on any other
39+LOGGERs attached to this MULTI-LOGGER."
40+ (make-instance 'multi-logger))
41+
42+(defun make-colored-multi-logger (&key (default-color :bright-white) (debug-color :green) (warn-color :yellow)
43+ (error-color :bright-red))
44+ "Creates a new MULTI-LOGGER with the headers setup to output colored
45+text. This does not affect colored text output on any other LOGGERs
46+attached to this MULTI-LOGGER."
47+ (make-instance 'multi-logger :headers (make-instance 'header-definition
48+ :error-color error-color
49+ :warn-color warn-color
50+ :default-color default-color
51+ :debug-color debug-color)))
52+
53+(defmethod log :after ((msg string) &rest fmt-args)
54+ (when (typep *logger* 'multi-logger)
55+ (loop for l being the hash-values in (logger-other-loggers *logger*) do
56+ (log* l msg fmt-args))))
57+
58+(defmethod log* :after ((logger multi-logger) (msg string) &rest fmt-args)
59+ (loop for l being the hash-values in (logger-other-loggers logger) do
60+ (log* l msg fmt-args)))
61+
62+(defmethod vlog :after (min-level msg &rest fmt-args)
63+ (when (typep *logger* 'multi-logger)
64+ (loop for l being the hash-values in (logger-other-loggers *logger*) do
65+ (vlog* l min-level msg fmt-args))))
66+
67+(defmethod vlog* :after ((logger multi-logger) (min-level integer) (msg string) &rest fmt-args)
68+ (loop for l being the hash-values in (logger-other-loggers logger) do
69+ (vlog* l min-level msg fmt-args)))
70+
71+(defmethod dlog :after ((min-level integer) (msg string) &rest fmt-args)
72+ (when (typep *logger* 'multi-logger)
73+ (loop for l being the hash-values in (logger-other-loggers *logger*) do
74+ (dlog* l min-level msg fmt-args))))
75+
76+(defmethod dlog* :after ((logger multi-logger) (min-level integer) (msg string) &rest fmt-args)
77+ (loop for l being the hash-values in (logger-other-loggers logger) do
78+ (dlog* l min-level msg fmt-args)))
79+
80+(defmethod dlog! :after ((msg string) &rest fmt-args)
81+ (when (typep *logger* 'multi-logger)
82+ (loop for l being the hash-values in (logger-other-loggers *logger*) do
83+ (dlog*! l msg fmt-args))))
84+
85+(defmethod dlog*! :after ((logger multi-logger) (msg string) &rest fmt-args)
86+ (loop for l being the hash-values in (logger-other-loggers logger) do
87+ (dlog*! l msg fmt-args)))
88+
89+(defmethod warn-log :after ((msg string) &rest fmt-args)
90+ (when (typep *logger* 'multi-logger)
91+ (loop for l being the hash-values in (logger-other-loggers *logger*) do
92+ (warn-log* l msg fmt-args))))
93+
94+(defmethod warn-log* :after ((logger multi-logger) (msg string) &rest fmt-args)
95+ (loop for l being the hash-values in (logger-other-loggers logger) do
96+ (warn-log* l msg fmt-args)))
97+
98+(defmethod error-log :after ((msg string) &rest fmt-args)
99+ (when (typep *logger* 'multi-logger)
100+ (loop for l being the hash-values in (logger-other-loggers *logger*) do
101+ (error-log* l msg fmt-args))))
102+
103+(defmethod error-log* :after ((logger multi-logger) (msg string) &rest fmt-args)
104+ (loop for l being the hash-values in (logger-other-loggers logger) do
105+ (error-log* l msg fmt-args)))
diff -r bd6646f72bac -r 7436eb3fc9d7 src/package.lisp
--- a/src/package.lisp Sun Oct 06 01:59:13 2019 -0600
+++ b/src/package.lisp Tue Dec 17 01:02:36 2019 -0700
@@ -68,7 +68,12 @@
6868
6969 #:make-basic-logger
7070 #:make-colored-logger
71- #:with-logger))
71+ #:with-logger
72+
73+ #:multi-logger
74+ #:logger-other-loggers
75+ #:make-basic-multi-logger
76+ #:make-colored-multi-logger))
7277
7378 (defpackage :com.p36.p36-log-simple
7479 (:use :common-lisp)
Show on old repository browser