File tree 3 files changed +21
-15
lines changed
3 files changed +21
-15
lines changed Original file line number Diff line number Diff line change 1
1
0.1.7
2
2
3
+ * Only colorize output when logging to a TTY
3
4
* Fix crashing --list-templates flag
4
5
5
6
0.1.6
Original file line number Diff line number Diff line change @@ -5,32 +5,44 @@ module Overcommit
5
5
class Logger
6
6
include Singleton
7
7
8
+ attr_accessor :output
9
+
8
10
def partial ( *args )
9
- print *args
11
+ out . print *args
10
12
end
11
13
12
14
def log ( *args )
13
- puts *args
15
+ out . puts *args
14
16
end
15
17
16
18
def bold ( str )
17
- log " \033 [1;37m #{ str } \033 [0m"
19
+ color ( '1;37' , str )
18
20
end
19
21
20
22
def error ( str )
21
- log " \033 [31m #{ str } \033 [0m"
23
+ color ( 31 , str )
22
24
end
23
25
24
26
def success ( str )
25
- log " \033 [32m #{ str } \033 [0m"
27
+ color ( 32 , str )
26
28
end
27
29
28
30
def warning ( str )
29
- log " \033 [33m #{ str } \033 [0m"
31
+ color ( 33 , str )
30
32
end
31
33
32
34
def notice ( str )
33
- log "\033 [1;33m#{ str } \033 [0m"
35
+ color ( '1;33' , str )
36
+ end
37
+
38
+ def out
39
+ self . output ||= $stdout
40
+ end
41
+
42
+ private
43
+
44
+ def color ( code , str )
45
+ log ( out . isatty ? "\033 [#{ code } m#{ str } \033 [0m" : str )
34
46
end
35
47
end
36
48
end
Original file line number Diff line number Diff line change 8
8
9
9
def exit ( *args ) ; end
10
10
11
- # Silence output to STDOUT
12
- class Overcommit ::Logger
13
- def log ( *args )
14
- end
15
-
16
- def partial ( *args )
17
- end
18
- end
11
+ Overcommit ::Logger . instance . output = StringIO . new
You can’t perform that action at this time.
0 commit comments