USING: assocs calendar calendar.format combinators
concurrency.messaging continuations debugger destructors init io
io.directories io.encodings.utf8 io.files io.pathnames kernel
-locals math math.parser math.ranges namespaces sequences
-strings threads ;
+math math.parser ranges namespaces sequences strings threads ;
IN: logging.server
: log-root ( -- string )
finally ; inline
: timestamp-header. ( -- )
- "[" write now write-timestamp "] " write ;
+ "[" write now write-rfc3339 "] " write ;
: multiline-header ( -- str ) 20 CHAR: - <string> ; foldable
CONSTANT: keep-logs 10
-: ?delete-file ( path -- )
- dup exists? [ delete-file ] [ drop ] if ;
-
: delete-oldest ( service -- )
keep-logs log# ?delete-file ;
: ?move-file ( old new -- )
- over exists? [ move-file ] [ 2drop ] if ;
+ over file-exists? [ move-file ] [ 2drop ] if ;
: advance-log ( path n -- )
[ 1 - log# ] 2keep log# ?move-file ;
[
log-path
[ delete-oldest ]
- [ keep-logs 1 [a,b] [ advance-log ] with each ] bi
+ [ keep-logs 1 [a..b] [ advance-log ] with each ] bi
] bi ;
: (rotate-logs) ( -- )
: log-server ( -- )
[
- init-namespaces
+ init-namestack
[ log-server-loop ]
[ error. (close-logs) ]
recover t