]> gitweb.factorcode.org Git - factor.git/blob - basis/logging/insomniac/insomniac.factor
786752f01bcf1aa6df64e64129ab6d7fadd9f7e8
[factor.git] / basis / logging / insomniac / insomniac.factor
1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: logging.analysis logging.server logging smtp kernel
4 io.files io.streams.string namespaces make timers assocs
5 io.encodings.utf8 accessors calendar sequences locals ;
6 QUALIFIED: io.sockets
7 IN: logging.insomniac
8
9 SYMBOL: insomniac-sender
10 SYMBOL: insomniac-recipients
11
12 : email-subject ( service -- string )
13     [
14         "Log analysis for " % % " on " % io.sockets:host-name %
15     ] "" make ;
16
17 :: (email-log-report) ( service word-names -- )
18     <email>
19         [ service word-names analyze-log-file ] with-string-writer >>body
20         insomniac-recipients get >>to
21         insomniac-sender get >>from
22         service email-subject >>subject
23     send-email ;
24
25 \ (email-log-report) NOTICE add-error-logging
26
27 : email-log-report ( service word-names -- )
28     "logging.insomniac" [ (email-log-report) ] with-logging ;
29
30 : schedule-insomniac ( service word-names -- )
31     [ email-log-report rotate-logs ] 2curry
32     1 days every drop ;