Skip to content
Browse files

Change (log:expr) to take advantage of conditional newlines when

*PRINT-PRETTY* is in effect, and allow customization of (log:expr)
strings separating expression and value, as well as suffix after each
expression via (naming-option) method
  • Loading branch information...
1 parent b201cd8 commit 50ccb9b907034c2905587e056811c51bee25ecfc Max Mikhanosha committed Mar 7, 2012
Showing with 54 additions and 27 deletions.
  1. +32 −18 src/logging-macros.lisp
  2. +22 −9 src/naming.lisp
View
50 src/logging-macros.lisp
@@ -71,23 +71,32 @@ any appenders.
(defvar +make-logger-symbols+ '(make-logger))
-
(defmacro log-sexp-with-level (level &rest sexps &environment env)
- "Expands into LOG-<LEVEL> log statement that will print each element of SEXPS
-in the form of ELEMENT=VALUE where ELEMENT will be the literal argument
-without evaluating it, and VALUE will be the result of evaluation. For constant
-string elements, it is output literally without printing its value.
+ "Expands into LOG-<LEVEL> log statement that will print each element
+of SEXPS in the form of ELEMENT=VALUE where ELEMENT will be the
+literal argument without evaluating it, and VALUE will be the result
+of evaluation. Constant string elements will be output directly.
+
+A pretty printer (pprint-newline :fill) format will be used as a
+separator between expressions, so that long expressions start
+on a new line, if *PRINT-PRETTY* is non-NIL
Example:
- (let ((a 1) (b '(two three)))
- (log-sexp \"values are\" a b))
+ (let ((a 1) (b '(two three))
+ (c (loop for i from 1 to 15 collect i)))
+ (log:sexp \"values are\" a b c))
will produce log message:
[debug] - values are A=1 B=(TWO THREE)
+ C=(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
- "
+Separator between expression and value, which defaults to equal sign,
+and a suffix after each value, which defaults to \" ~:_\" (a space
+followed by conditional newline) can be customized per package via
+NAMING-OPTION generic function
+"
(multiple-value-bind (logger-form sexps)
(resolve-logger-form *package* env
(cond
@@ -101,19 +110,24 @@ will produce log message:
+make-logger-symbols+))))
`((make-logger) ,@sexps))
(t sexps)))
- (let* (args
+ (let* ((args nil)
(format
(with-output-to-string (*standard-output*)
+ (princ "~@<~;")
(setq args
- (loop with first = t
- for arg in sexps
- do (if first (setf first nil)
- (write-char #\Space))
- if (stringp arg)
- do (write-string arg)
- else
- do (format t "~s=~~s" arg)
- and collect arg)))))
+ (loop
+ for arg in sexps
+ if (stringp arg)
+ do (format t "~a " arg)
+ else
+ do (format t "~A~A~A~A"
+ "~W"
+ (naming-option *package* :expr-value-separator)
+ "~W"
+ (naming-option *package* :expr-value-suffix))
+ and collect `(quote ,arg)
+ and collect arg))
+ (princ "~:>"))))
`(,level ,logger-form ,format ,@args))))
(defmacro deflog-sexp-macros (levels)
View
31 src/naming.lisp
@@ -24,23 +24,34 @@ function"))
(defgeneric naming-option (package option)
(:documentation "Return the automatic logger naming option
-for the specified package. Valid options are:
+for the specified package. Valid options are keywords:
- :CATEGORY-SEPARATOR - String that separates category names, default
- method returns \":\"
+ :CATEGORY-SEPARATOR
+ : String that separates category names, default method returns
+ \":\"
- :CATEGORY-CASE - Determining how logger naming converts symbols to
- in the category name.
+ :CATEGORY-CASE
+ : Determining how logger naming converts symbols to in the
+ category name.
- Valid values are:
+ Valid values are:
- NIL : As printed by PRINC (ie affected by active *READTABLE*)
- :UPCASE : Convert to upper case
- :DOWNCASE : Convert to lower case
- :INVERT : Invert in the same way inverted READTABLE-CASE does it
- :PRESERVE : Do not change
-Note that pattern layout offers similar facility that changes how
-logger category is printed on the output side."))
+ Note that pattern layout offers similar facility that changes how
+ logger category is printed on the output side
+
+ :EXPR-VALUE-SEPARATOR
+ : A string that separates expression and value printed
+ by (LOG-SEXP). Default is equal sign
+
+ :EXPR-VALUE-SUFFIX
+ : A string inserted into the format statement after each
+ expression and value pair printed by (LOG-SEXP). Default is
+ \" ~:_\" (a space followed by conditional newline)"))
(defgeneric package-wrapper (package categories explicit-p)
@@ -185,7 +196,9 @@ SEPARATOR"
:CATEGORY-SEPARATOR \":\""
(declare (ignore package))
(case option
- (:category-separator ":")))
+ (:category-separator ":")
+ (:expr-value-separator "=")
+ (:expr-value-suffix " ~:_")))
(defmethod resolve-logger-form (package env args)
"- When first element of args is NIL or a constant string, calls

0 comments on commit 50ccb9b

Please sign in to comment.
Something went wrong with that request. Please try again.