     [ 1 - log# ] 2keep log# ?move-file ;
 
 : rotate-log ( service -- )
-    dup close-log
-    log-path
-    dup delete-oldest
-    keep-logs 1 [a,b] [ advance-log ] with each ;
+    [ close-log ]
+    [
+        log-path
+        [ delete-oldest ]
+        [ keep-logs 1 [a,b] [ advance-log ] with each ] bi
+    ] bi ;
 
 : (rotate-logs) ( -- )
     (close-logs)


: (close-logs) ( -- )
    log-files get
    dup values [ try-dispose ] each
    clear-assoc ;

CONSTANT: keep-logs 10



: open-log-stream ( service -- stream )
    log-path
    [ make-directories ]
    [ 1 log# utf8 <file-appender> ] bi ;

: log-stream ( service -- stream )
    log-files get [ open-log-stream ] cache ;
