factor/extra/logging/insomniac/insomniac.factor

42 lines
1.2 KiB
Factor
Raw Normal View History

2008-02-07 18:07:43 -05:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2008-03-07 18:20:15 -05:00
USING: logging.analysis logging.server logging smtp kernel
io.files io.streams.string namespaces alarms assocs
io.encodings.utf8 accessors calendar qualified ;
QUALIFIED: io.sockets
2008-02-07 18:07:43 -05:00
IN: logging.insomniac
SYMBOL: insomniac-sender
SYMBOL: insomniac-recipients
2008-02-07 20:51:37 -05:00
: ?analyze-log ( service word-names -- string/f )
2008-02-07 18:07:43 -05:00
>r log-path 1 log# dup exists? [
utf8 file-lines r> [ analyze-log ] with-string-writer
2008-02-07 18:07:43 -05:00
] [
r> 2drop f
] if ;
: email-subject ( service -- string )
2008-03-07 18:20:15 -05:00
[
"[INSOMNIAC] " % % " on " % io.sockets:host-name %
] "" make ;
2008-02-07 18:07:43 -05:00
: (email-log-report) ( service word-names -- )
dupd ?analyze-log dup [
<email>
swap >>body
insomniac-recipients get >>to
insomniac-sender get >>from
swap email-subject >>subject
send-email
] [ 2drop ] if ;
2008-02-07 18:07:43 -05:00
2008-02-07 20:51:37 -05:00
\ (email-log-report) NOTICE add-error-logging
2008-02-07 18:07:43 -05:00
2008-02-07 20:51:37 -05:00
: email-log-report ( service word-names -- )
"logging.insomniac" [ (email-log-report) ] with-logging ;
2008-02-07 18:07:43 -05:00
2008-02-10 02:39:37 -05:00
: schedule-insomniac ( service word-names -- )
[ [ email-log-report ] assoc-each rotate-logs ] 2curry
1 days every drop ;