moontalk/server/eventloop-server-experiment/logger.4th
2024-02-17 18:26:14 +00:00

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 ;