2005-03-18 21:41:13 -05:00
|
|
|
! 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
|
2005-03-18 21:41:13 -05:00
|
|
|
USING: kernel namespaces stdio streams strings ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-03-18 21:41:13 -05:00
|
|
|
! A simple logging framework.
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
: log ( msg -- )
|
2005-03-18 21:41:13 -05:00
|
|
|
#! 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 -- )
|
2005-03-18 21:41:13 -05:00
|
|
|
#! Calls to log inside quot will output to stdio.
|
2004-11-29 23:14:12 -05:00
|
|
|
[ stdio get "log" set call ] with-scope ;
|
2004-08-17 20:44:57 -04:00
|
|
|
|
|
|
|
: with-log-file ( file quot -- )
|
2005-03-18 21:41:13 -05:00
|
|
|
#! Calls to log inside quot will output to a file.
|
2005-01-29 00:07:56 -05:00
|
|
|
[ swap <file-reader> "log" set call ] with-scope ;
|
2005-03-18 21:41:13 -05:00
|
|
|
|
|
|
|
! Helpful words.
|
|
|
|
|
|
|
|
: log-error ( error -- ) "Error: " swap cat2 log ;
|
|
|
|
|
|
|
|
: log-client ( client-stream -- )
|
|
|
|
client-stream-host [
|
|
|
|
"Accepted connection from " swap cat2 log
|
|
|
|
] when* ;
|