factor/library/io/logging.factor

32 lines
831 B
Factor
Raw Normal View History

! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
2004-07-16 02:26:21 -04:00
IN: logging
USING: kernel namespaces stdio streams strings ;
2004-07-16 02:26:21 -04:00
! A simple logging framework.
2004-07-16 02:26:21 -04:00
: log ( msg -- )
#! Log a message to the log stream, either stdio or a file.
"log" get dup [
tuck stream-print stream-flush
] [
2drop
] ifte ;
2004-07-16 02:26:21 -04:00
: with-logging ( quot -- )
#! Calls to log inside quot will output to stdio.
2004-11-29 23:14:12 -05:00
[ stdio get "log" set call ] with-scope ;
: with-log-file ( file quot -- )
#! Calls to log inside quot will output to a file.
[ swap <file-reader> "log" set call ] with-scope ;
! Helpful words.
: log-error ( error -- ) "Error: " swap cat2 log ;
: log-client ( client-stream -- )
client-stream-host [
"Accepted connection from " swap cat2 log
] when* ;