logging.server: add support for changing the logging root temporarily.
parent
317b0c8d20
commit
a6989e2cc2
|
@ -1,5 +1,6 @@
|
||||||
IN: logging.tests
|
IN: logging.tests
|
||||||
USING: tools.test logging logging.analysis io math ;
|
USING: tools.test logging logging.analysis logging.server io
|
||||||
|
io.files.temp math ;
|
||||||
|
|
||||||
: input-logging-test ( a b -- c ) + ;
|
: input-logging-test ( a b -- c ) + ;
|
||||||
|
|
||||||
|
@ -13,7 +14,8 @@ USING: tools.test logging logging.analysis io math ;
|
||||||
|
|
||||||
\ error-logging-test ERROR add-error-logging
|
\ error-logging-test ERROR add-error-logging
|
||||||
|
|
||||||
"logging-test" [
|
temp-directory [
|
||||||
|
"logging-test" [
|
||||||
[ 4 ] [ 1 3 input-logging-test ] unit-test
|
[ 4 ] [ 1 3 input-logging-test ] unit-test
|
||||||
|
|
||||||
[ 4 ] [ 1 3 output-logging-test ] unit-test
|
[ 4 ] [ 1 3 output-logging-test ] unit-test
|
||||||
|
@ -21,6 +23,7 @@ USING: tools.test logging logging.analysis io math ;
|
||||||
[ 4/3 ] [ 4 3 error-logging-test ] unit-test
|
[ 4/3 ] [ 4 3 error-logging-test ] unit-test
|
||||||
|
|
||||||
[ f ] [ 1 0 error-logging-test ] unit-test
|
[ f ] [ 1 0 error-logging-test ] unit-test
|
||||||
] with-logging
|
] with-logging
|
||||||
|
|
||||||
[ ] [ "logging-test" { "input-logging-test" } analyze-log-file ] unit-test
|
[ ] [ "logging-test" { "input-logging-test" } analyze-log-file ] unit-test
|
||||||
|
] with-log-root
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
USING: assocs calendar calendar.format combinators
|
USING: assocs calendar calendar.format combinators
|
||||||
concurrency.messaging continuations debugger destructors init io
|
concurrency.messaging continuations debugger destructors init io
|
||||||
io.directories io.encodings.utf8 io.files io.pathnames kernel
|
io.directories io.encodings.utf8 io.files io.pathnames kernel
|
||||||
literals math math.parser math.ranges namespaces sequences
|
locals math math.parser math.ranges namespaces sequences
|
||||||
strings threads ;
|
strings threads ;
|
||||||
IN: logging.server
|
IN: logging.server
|
||||||
|
|
||||||
: log-root ( -- string )
|
: log-root ( -- string )
|
||||||
\ log-root get [ "logs" resource-path ] unless* ;
|
\ log-root get-global [ "logs" resource-path ] unless* ;
|
||||||
|
|
||||||
: log-path ( service -- path )
|
: log-path ( service -- path )
|
||||||
log-root prepend-path ;
|
log-root prepend-path ;
|
||||||
|
@ -26,10 +26,19 @@ SYMBOL: log-files
|
||||||
: log-stream ( service -- stream )
|
: log-stream ( service -- stream )
|
||||||
log-files get [ open-log-stream ] cache ;
|
log-files get [ open-log-stream ] cache ;
|
||||||
|
|
||||||
|
: close-log-streams ( -- )
|
||||||
|
log-files get [ values dispose-each ] [ clear-assoc ] bi ;
|
||||||
|
|
||||||
|
:: with-log-root ( path quot -- )
|
||||||
|
[ close-log-streams path \ log-root set-global quot call ]
|
||||||
|
\ log-root get-global
|
||||||
|
[ \ log-root set-global close-log-streams ] curry
|
||||||
|
[ ] cleanup ; inline
|
||||||
|
|
||||||
: timestamp-header. ( -- )
|
: timestamp-header. ( -- )
|
||||||
"[" write now (timestamp>rfc3339) "] " write ;
|
"[" write now (timestamp>rfc3339) "] " write ;
|
||||||
|
|
||||||
CONSTANT: multiline-header $[ 20 CHAR: - <string> ]
|
: multiline-header ( -- str ) 20 CHAR: - <string> ; foldable
|
||||||
|
|
||||||
: multiline-header. ( -- )
|
: multiline-header. ( -- )
|
||||||
"[" write multiline-header write "] " write ;
|
"[" write multiline-header write "] " write ;
|
||||||
|
|
Loading…
Reference in New Issue