29 lines
507 B
Forth
29 lines
507 B
Forth
require libs/xstring/xstring.4th
|
|
|
|
require extensions.4th
|
|
|
|
0 variable! logfd
|
|
|
|
: (log-filepath) ( -- str )
|
|
CONFIG_LOG_DIR pad xplace
|
|
0 time to-string pad +xplace
|
|
s" .log" pad +xplace
|
|
pad xcount ;
|
|
|
|
(log-filepath) sconstant log-filepath
|
|
|
|
: logger.open ( -- )
|
|
log-filepath r/w create-file throw logfd ! ;
|
|
: logger.close ( -- )
|
|
logfd @ close-file drop ;
|
|
|
|
: logger.flush ( -- )
|
|
logfd @ flush-file drop ;
|
|
|
|
: logger.log ( str -- )
|
|
logfd @ 0<> IF
|
|
logfd @ write-file drop
|
|
ELSE
|
|
2drop
|
|
THEN ;
|