Moontalk server and client (provided by many parties)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

logger.4th 507B

12345678910111213141516171819202122232425262728
  1. require libs/xstring/xstring.4th
  2. require extensions.4th
  3. 0 variable! logfd
  4. : (log-filepath) ( -- str )
  5. CONFIG_LOG_DIR pad xplace
  6. 0 time to-string pad +xplace
  7. s" .log" pad +xplace
  8. pad xcount ;
  9. (log-filepath) sconstant log-filepath
  10. : logger.open ( -- )
  11. log-filepath r/w create-file throw logfd ! ;
  12. : logger.close ( -- )
  13. logfd @ close-file drop ;
  14. : logger.flush ( -- )
  15. logfd @ flush-file drop ;
  16. : logger.log ( str -- )
  17. logfd @ 0<> IF
  18. logfd @ write-file drop
  19. ELSE
  20. 2drop
  21. THEN ;