forked from shirok/Gauche
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.scm
82 lines (61 loc) · 1.98 KB
/
logger.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
;;
;; testing gauche.logger
;;
(use gauche.test)
;; NB: logger uses gauche.fcntl. Before 'make link', it can't be
;; loaded by 'use'.
(when (file-exists? "../ext/fcntl/fcntl.scm")
(add-load-path "../ext/fcntl")
(load "../ext/fcntl/fcntl"))
(when (file-exists? "../ext/syslog/syslog.scm")
(add-load-path "../ext/syslog")
(load "../ext/syslog/syslog"))
(test-start "logger")
(use gauche.logger)
(test-module 'gauche.logger)
;;-------------------------------------------------------------------------
(test-section "log-open")
(sys-system "rm -f test.o")
;; these shouldn't go to the log
(log-format "testing...")
(log-format "testing ~a..." 2)
(log-format "testing ~a..." 3)
(log-open "test.o")
(log-format "real testing...")
(log-format "real testing ~a..." 2)
(log-format "output string\ncontaining newline\ncharacters")
(log-open #f)
(log-format "fake testing...")
(log-open "test.o")
(log-format "real testing again...")
(test "log-open"
'("real testing..."
"real testing 2..."
"output string"
"containing newline"
"characters"
"real testing again...")
(lambda ()
(map (lambda (line)
(cond ((#/^... .. ..:..:.. .+\[\d+\]: (.*)$/ line)
=> (^m (m 1)))
(else #f)))
(call-with-input-file "test.o" port->string-list))))
(sys-system "rm -f test.o")
;;-------------------------------------------------------------------------
(test-section "customized formatter")
(sys-system "rm -f test.o")
(log-open "test.o" :prefix "zeepa:")
(log-format "booba bunba bomba")
(test "customized formatter"
'("zeepa:booba bunba bomba")
(lambda ()
(call-with-input-file "test.o" port->string-list)))
(sys-system "rm -f test.o")
(log-open "test.o" :prefix (lambda (drain) "poopa:"))
(log-format "booba bunba bomba")
(test "customized formatter"
'("poopa:booba bunba bomba")
(lambda ()
(call-with-input-file "test.o" port->string-list)))
(test-end)