Last active
December 26, 2015 04:59
-
-
Save KeenS/7096990 to your computer and use it in GitHub Desktop.
Shibuya.lispのLisp Meet Up #10 で発表したときのデモのソースです
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ql:quickload :bordeaux-threads) | |
(ql:quickload :log4cl) | |
; debugとinfoのログレベルのメッセージを交互に吐き続けるスレッドを作成 | |
(defparameter thrd (bordeaux-threads:make-thread | |
(lambda () (loop | |
(log:debug "this is debug") | |
(log:info "this is ~{~a~}" '(#\i #\n #\f #\o)) | |
(sleep 1))))) | |
;(infoしか出力されない) | |
; debugを有効にする | |
(log:config :debug) | |
;(debugも出力される | |
;再びinfoに引き上げる | |
(log:config :info) | |
;(infoしか出力されない) | |
(bordeaux-threads:destroy-thread thrd) | |
; こっちは良い感じに表示してくれる | |
(let ((a 1) | |
(b 3)) | |
(log:expr a b (+ a b))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ql:quickload :log4cl) | |
(ql:quickload :cl-syslog) | |
;; アペンダを定義 | |
(defclass syslog-appender (log4cl-impl:appender) | |
()) | |
;; アペンダの出力方法を定義 | |
(defmethod log4cl-impl:appender-do-append ((appender syslog-appender) logger level log-func) | |
;; 出力はcl-syslogに丸投げ。 | |
(cl-syslog:log "log4cl" :local7 :info | |
(with-output-to-string (s) | |
(log4cl-impl:layout-to-stream | |
(slot-value appender 'log4cl-impl:layout) s logger level log-func)))) | |
;; ロガーを作成 | |
(defvar syslog-logger (log:category '(syslog))) | |
;; ロガーにアペンダを対応付ける | |
(log4cl-impl:add-appender syslog-logger (make-instance 'syslog-appender)) | |
;; ログ出力 | |
(log:i :logger syslog-logger "from cl") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 手元にダウンロードしてきている前提 | |
(ql:quickload :log4cl-fluentd) | |
;ロガーを作成 | |
(log4cl-fluentd:create-fluentd-logger | |
:forward nil ;forwardはoff、onだとデフォルトで:forward-portは24224、:forward-hostはlocalhostに設定されてある | |
:tail t :tail-name-format "filename.log" :tail-backup-format "%Y-%m-%d" ;tailはonで、ファイル名とバックアップファイルの書式を指定 | |
:http t :http-port 8888) ;httpもonにして:http-portを8888から変更。:http-hostはlocalhostのまま | |
(defvar logger log4cl-fluentd:fluentd-logger) | |
;(log:info :logger logger :format-control "~a" (log4cl-fluentd:json))までがイディオム | |
;(json :key1 arg1 :key2 arg2 ...) or (json plist) | |
(log:info :logger logger :format-control "~a" (log4cl-fluentd:json :message "hello")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment