wololo_formatter 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/wololo_formatter/logger.rb +47 -21
- data/lib/wololo_formatter/version.rb +1 -1
- metadata +1 -1
@@ -1,27 +1,53 @@
|
|
1
1
|
class Logger
|
2
2
|
class Formatter
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
def call(severity, time, progname, msg)
|
4
|
+
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S.") << time.usec.to_s[0..2].rjust(3)
|
5
|
+
"#{severity_color severity} \033[0;37m#{formatted_time}\033[0m #{String === msg ? msg : msg.inspect} (pid:#{$$})\n"
|
6
|
+
end
|
7
7
|
|
8
|
-
|
8
|
+
private
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
def severity_color(severity)
|
11
|
+
case severity
|
12
|
+
when "DEBUG"
|
13
|
+
"\033[1;34;40m[DEBUG]\033[0m" # blue
|
14
|
+
when "INFO"
|
15
|
+
"\033[0;32;40m[INFO]\033[0m" # bold white
|
16
|
+
when "WARN"
|
17
|
+
"\033[0;33;40m[WARNING]\033[0m" # bold yellow
|
18
|
+
when "ERROR"
|
19
|
+
"\033[1;31;40m[ERROR]\033[0m" # bold red
|
20
|
+
when "FATAL"
|
21
|
+
"\033[7;31;40m[FATAL]\033[0m" # bold black, red bg
|
22
|
+
else
|
23
|
+
"[#{severity}]" # none
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class SimpleFormatter
|
29
|
+
def call(severity, time, progname, msg)
|
30
|
+
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S.") << time.usec.to_s[0..2].rjust(3)
|
31
|
+
"#{severity_color severity} \033[0;37m#{formatted_time}\033[0m #{String === msg ? msg : msg.inspect} (pid:#{$$})\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def severity_color(severity)
|
37
|
+
case severity
|
38
|
+
when "DEBUG"
|
39
|
+
"\033[1;34;40m[DEBUG]\033[0m" # blue
|
40
|
+
when "INFO"
|
41
|
+
"\033[0;32;40m[INFO]\033[0m" # bold white
|
42
|
+
when "WARN"
|
43
|
+
"\033[0;33;40m[WARNING]\033[0m" # bold yellow
|
44
|
+
when "ERROR"
|
45
|
+
"\033[1;31;40m[ERROR]\033[0m" # bold red
|
46
|
+
when "FATAL"
|
47
|
+
"\033[7;31;40m[FATAL]\033[0m" # bold black, red bg
|
48
|
+
else
|
49
|
+
"[#{severity}]" # none
|
50
|
+
end
|
51
|
+
end
|
26
52
|
end
|
27
53
|
end
|