factor/basis/logging/insomniac/insomniac.factor

38 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
2008-09-10 23:11:40 -04:00
io.files io.streams.string namespaces make alarms assocs
io.encodings.utf8 accessors calendar sequences qualified ;
2008-03-07 18:20:15 -05:00
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 )
[ analyze-log-file ] with-string-writer ;
2008-02-07 18:07:43 -05:00
: 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 -- )
2008-09-06 20:13:59 -04:00
dupd ?analyze-log [ drop ] [
<email>
swap >>body
insomniac-recipients get >>to
insomniac-sender get >>from
swap email-subject >>subject
send-email
2008-09-06 20:13:59 -04:00
] if-empty ;
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 ;