colorlog 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/colorlog +92 -49
- metadata +6 -6
data/bin/colorlog
CHANGED
@@ -4,16 +4,51 @@ require 'optparse'
|
|
4
4
|
require 'rainbow'
|
5
5
|
require 'yaml'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
COLORS = [
|
8
|
+
:black,
|
9
|
+
:red,
|
10
|
+
:green,
|
11
|
+
:yellow,
|
12
|
+
:blue,
|
13
|
+
:magenta,
|
14
|
+
:cyan,
|
15
|
+
:white,
|
16
|
+
:default
|
17
|
+
]
|
15
18
|
|
19
|
+
options = {
|
20
|
+
colors: {
|
21
|
+
default: {
|
22
|
+
color: :default,
|
23
|
+
regex: //
|
24
|
+
},
|
25
|
+
success: {
|
26
|
+
color: :green,
|
27
|
+
regex: /success/i
|
28
|
+
},
|
29
|
+
warning: {
|
30
|
+
color: :yellow,
|
31
|
+
regex: /warning/i
|
32
|
+
},
|
33
|
+
error: {
|
34
|
+
color: :red,
|
35
|
+
regex: /^(?:(?!\bTests\b).)*(?:failure|error).*$/i
|
36
|
+
},
|
37
|
+
custom1: {
|
38
|
+
color: :blue,
|
39
|
+
regex: /custom1/
|
40
|
+
},
|
41
|
+
custom2: {
|
42
|
+
color: :magenta,
|
43
|
+
regex: /custom2/
|
44
|
+
},
|
45
|
+
custom3: {
|
46
|
+
color: :cyan,
|
47
|
+
regex: /custom3/
|
48
|
+
}
|
49
|
+
}
|
16
50
|
}
|
51
|
+
|
17
52
|
CONFIG_FILE = File.join(ENV['HOME'], '.colorlog.rc.yaml')
|
18
53
|
if File.exists? CONFIG_FILE
|
19
54
|
config_options = YAML.load_file(CONFIG_FILE)
|
@@ -29,47 +64,61 @@ option_parser = OptionParser.new do |opts|
|
|
29
64
|
"different color depending on the content of the line matching different Regexp.
|
30
65
|
|
31
66
|
Usage: #{executable_name} [options] filename
|
67
|
+
possible colors are: " + COLORS.map { |color| color.id2name }.to_s+"
|
68
|
+
You can change the default values by editing "+CONFIG_FILE+"
|
69
|
+
|
70
|
+
"
|
71
|
+
|
72
|
+
opts.on('--default-color COLOR', COLORS, 'color to use when no match is found (' + options[:colors][:default][:color].id2name + ')') do |default_color|
|
73
|
+
options[:colors][:default][:color] = default_color
|
74
|
+
end
|
75
|
+
|
76
|
+
opts.on('-s', '--success REGEXP', Regexp, 'RegExp that matched will turn the line in --success-color (' + options[:colors][:success][:regex].inspect + ')') do |success|
|
77
|
+
options[:colors][:success][:regex] = success
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.on('--success-color COLOR', COLORS, 'color to use when line matches success (' + options[:colors][:success][:color].id2name + ')') do |success_color|
|
81
|
+
options[:colors][:success][:color] = success_color
|
82
|
+
end
|
32
83
|
|
33
|
-
|
84
|
+
opts.on('-w', '--warning REGEXP', Regexp, 'RegExp that matched will turn the line in --warning-color (' + options[:colors][:warning][:regex].inspect + ')') do |warning|
|
85
|
+
options[:colors][:warning][:regex] = warning
|
86
|
+
end
|
34
87
|
|
35
|
-
COLORS
|
36
|
-
|
37
|
-
|
38
|
-
:green,
|
39
|
-
:yellow,
|
40
|
-
:blue,
|
41
|
-
:magenta,
|
42
|
-
:cyan,
|
43
|
-
:white,
|
44
|
-
:default
|
45
|
-
]
|
88
|
+
opts.on('--warning-color COLOR', COLORS, 'color to use when line matches warning (' + options[:colors][:warning][:color].id2name + ')') do |warning_color|
|
89
|
+
options[:colors][:warning][:color] = warning_color
|
90
|
+
end
|
46
91
|
|
47
|
-
opts.on('
|
48
|
-
options[:
|
92
|
+
opts.on('-e', '--error REGEXP', Regexp, 'RegExp that matched will turn the line in --error-color (' + options[:colors][:error][:regex].inspect + ')') do |error|
|
93
|
+
options[:colors][:error][:regex] = error
|
49
94
|
end
|
50
95
|
|
51
|
-
opts.on('--
|
52
|
-
options[:
|
96
|
+
opts.on('--error-color COLOR', COLORS, 'color to use when line matches error (' + options[:colors][:error][:color].id2name + ')') do |error_color|
|
97
|
+
options[:colors][:error][:color] = error_color
|
53
98
|
end
|
54
99
|
|
55
|
-
opts.on('--
|
56
|
-
options[:
|
100
|
+
opts.on('--custom1 REGEXP', Regexp, 'RegExp that matched will turn the line in --custom-color1 (' + options[:colors][:custom1][:regex].inspect + ')') do |custom|
|
101
|
+
options[:colors][:custom1][:regex] = custom
|
57
102
|
end
|
58
103
|
|
59
|
-
opts.on('--
|
60
|
-
options[:
|
104
|
+
opts.on('--custom1-color COLOR', COLORS, 'color to use when line matches custom1 (' + options[:colors][:custom1][:color].id2name + ')') do |custom_color|
|
105
|
+
options[:colors][:custom1][:color] = custom_color
|
61
106
|
end
|
62
107
|
|
63
|
-
opts.on('
|
64
|
-
options[:
|
108
|
+
opts.on('--custom2 REGEXP', Regexp, 'RegExp that matched will turn the line in --custom-color2 (' + options[:colors][:custom2][:regex].inspect + ')') do |custom|
|
109
|
+
options[:colors][:custom2][:regex] = custom
|
65
110
|
end
|
66
111
|
|
67
|
-
opts.on('-
|
68
|
-
options[:
|
112
|
+
opts.on('--custom2-color COLOR', COLORS, 'color to use when line matches custom2 (' + options[:colors][:custom2][:color].id2name + ')') do |custom_color|
|
113
|
+
options[:colors][:custom2][:color] = custom_color
|
69
114
|
end
|
70
115
|
|
71
|
-
opts.on('
|
72
|
-
options[:
|
116
|
+
opts.on('--custom3 REGEXP', Regexp, 'RegExp that matched will turn the line in --custom-color3 (' + options[:colors][:custom3][:regex].inspect + ')') do |custom|
|
117
|
+
options[:colors][:custom3][:regex] = custom
|
118
|
+
end
|
119
|
+
|
120
|
+
opts.on('--custom3-color COLOR', COLORS, 'color to use when line matches custom3 (' + options[:colors][:custom3][:color].id2name + ')') do |custom_color|
|
121
|
+
options[:colors][:custom3][:color] = custom_color
|
73
122
|
end
|
74
123
|
|
75
124
|
end
|
@@ -77,23 +126,17 @@ end
|
|
77
126
|
option_parser.parse!
|
78
127
|
|
79
128
|
def color_print(line, options)
|
129
|
+
actual_color = options[:colors][:default][:color]
|
80
130
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
if line =~ success_check
|
88
|
-
color = options[:success_color]
|
89
|
-
end
|
90
|
-
if line =~ warning_check
|
91
|
-
color = options[:warning_color]
|
92
|
-
end
|
93
|
-
if line =~ error_check
|
94
|
-
color = options[:error_color]
|
131
|
+
options[:colors].each do |key, value|
|
132
|
+
regexp = Regexp.new(value[:regex])
|
133
|
+
color = value[:color]
|
134
|
+
if line =~ regexp
|
135
|
+
actual_color = color
|
136
|
+
end
|
95
137
|
end
|
96
|
-
|
138
|
+
|
139
|
+
printf("%s".foreground(actual_color), line)
|
97
140
|
|
98
141
|
end
|
99
142
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorlog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rainbow
|
@@ -59,8 +59,8 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.12'
|
62
|
-
description: colorlog allow you to read a file with some lines colored
|
63
|
-
|
62
|
+
description: colorlog allow you to read a file with some lines colored based on regexp
|
63
|
+
three different regexp
|
64
64
|
email:
|
65
65
|
executables:
|
66
66
|
- colorlog
|
@@ -82,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
segments:
|
84
84
|
- 0
|
85
|
-
hash:
|
85
|
+
hash: 3221968240800879847
|
86
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
87
|
none: false
|
88
88
|
requirements:
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
segments:
|
93
93
|
- 0
|
94
|
-
hash:
|
94
|
+
hash: 3221968240800879847
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
97
|
rubygems_version: 1.8.24
|