31 lines
1.1 KiB
Common Lisp
31 lines
1.1 KiB
Common Lisp
;;;; cl-scopes/logging - mostly configuration for log4cl
|
|
|
|
(defpackage :scopes/logging
|
|
(:use :common-lisp)
|
|
(:local-nicknames (:config :scopes/config)
|
|
(:util :scopes/util))
|
|
(:export #:config #:setup))
|
|
|
|
(in-package :scopes/logging)
|
|
|
|
(defclass config (config:base)
|
|
((config:setup :initform #'setup)
|
|
(loglevel :reader loglevel :initarg :loglevel :initform :warn)
|
|
(logfile :reader logfile :initarg :logfile :initform "scopes.log")
|
|
(console :reader console :initarg :console :initform t)))
|
|
|
|
(defun setup(cfg)
|
|
(let ((loglevel (loglevel cfg))
|
|
(logfile (logfile cfg))
|
|
(pat "%&%<%I%;<;;>;-5p [%D{%H:%M:%S}] %g{}{}{:downcase}:%2.2N%c{1}{}{:downcase} - %:_%m%>%n")
|
|
params)
|
|
(if (stringp loglevel)
|
|
(setf loglevel (util:to-keyword loglevel)))
|
|
(if (stringp logfile)
|
|
(setf logfile (util:path-from-string logfile)))
|
|
(util:ensure-dir logfile)
|
|
;(format t "~&loglevel: ~s, logfile: ~s~%" loglevel logfile)
|
|
(setf params (list :sane loglevel :daily logfile :pattern pat))
|
|
(if (console cfg)
|
|
(setf params (cons :console params)))
|
|
(apply #'log:config params)))
|