moontalk/server/eventloop-server-experiment/logger.4th

29 lines
507 B
Plaintext
Raw Normal View History

2024-02-17 13:26:14 -05:00
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 ;