hoodie 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hoodie/logging.rb +114 -7
- data/lib/hoodie/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62365f7e782e882ae3769a0f11495a15662baffd
|
4
|
+
data.tar.gz: 5c174acce11e7d7e22ebbe43533b52f2bc91a6c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89700fd2bed82cc9abfd889db31551694ac271b49eb3ae5554c1ab3def161948218cd6062ccde5cbd5202634a569458d96ebb51744a68a321f3b74af404c6393
|
7
|
+
data.tar.gz: b18ae1e33e1f0b9abaaa2cab448e76411a71c8804c2524d0f2aada6319addd65aa0bd749c6ebd17b3a5b4e906757ab426ecf1b28c78694e4d55878a62ba1b8b9
|
data/lib/hoodie/logging.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Author: Tom Santos <santos.tom@gmail.com>
|
4
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
5
|
+
#
|
6
|
+
# Copyright (C) 2012-2014 Tom Santos, Stefano Harding
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
1
20
|
|
2
21
|
require 'logger'
|
3
22
|
require 'time'
|
@@ -5,39 +24,70 @@ require 'time'
|
|
5
24
|
module Hoodie
|
6
25
|
module Logging
|
7
26
|
class << self
|
8
|
-
|
27
|
+
|
28
|
+
# The Zero Log for Class
|
29
|
+
class NoLogger < Logger
|
30
|
+
def initialize(*args); end
|
31
|
+
def add(*args, &block); end
|
32
|
+
end
|
33
|
+
|
34
|
+
def no_logger
|
35
|
+
@log ||= NoLogger.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def log(log_prefix)
|
9
39
|
@log ||= Logger.new($stdout).tap do |log|
|
10
|
-
log.progname =
|
11
|
-
log.level = Logger::INFO
|
40
|
+
log.progname = self.class == Class ? self.to_s : self.class.to_s
|
12
41
|
log.formatter = Hoodie::Formatter.new
|
42
|
+
log.formatter.datetime_format = '%F %T'
|
43
|
+
log.level = Logger::DEBUG
|
13
44
|
end
|
14
45
|
end
|
15
46
|
|
16
47
|
def log=(log)
|
17
48
|
@log = log
|
18
49
|
end
|
50
|
+
|
51
|
+
def log_prefix
|
52
|
+
self.class == Class ? self.to_s : self.class.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def level
|
56
|
+
"Logger::#{@level.to_s.upcase}"
|
57
|
+
end
|
19
58
|
end
|
20
59
|
|
21
60
|
def self.included(base)
|
22
61
|
class << base
|
23
62
|
def log
|
24
|
-
|
63
|
+
log_prefix = self.class == Class ? self.to_s : self.class.to_s
|
64
|
+
Hoodie::Logging.log log_prefix
|
25
65
|
end
|
26
66
|
end
|
27
67
|
end
|
28
68
|
|
29
69
|
def log
|
30
|
-
|
70
|
+
log_prefix = self.class == Class ? self.to_s : self.class.to_s
|
71
|
+
Hoodie::Logging.log log_prefix
|
31
72
|
end
|
32
73
|
end
|
33
74
|
|
34
|
-
class Formatter <
|
75
|
+
class Formatter < Logger::Formatter
|
76
|
+
attr_accessor :datetime_format
|
77
|
+
|
35
78
|
def initialize
|
79
|
+
@datetime_format = nil
|
36
80
|
super
|
37
81
|
end
|
38
82
|
|
39
83
|
def call(severity, time, progname, msg)
|
40
|
-
format % [
|
84
|
+
format % [
|
85
|
+
format_datetime(time).BLUE,
|
86
|
+
progname.CYAN,
|
87
|
+
$$,
|
88
|
+
severity.GREEN,
|
89
|
+
msg2str(msg).strip.ORANGE
|
90
|
+
]
|
41
91
|
end
|
42
92
|
|
43
93
|
private # P R O P R I E T À P R I V A T A Vietato L'accesso
|
@@ -45,5 +95,62 @@ module Hoodie
|
|
45
95
|
def format
|
46
96
|
"%s [%s#%d] %5s: %s\n"
|
47
97
|
end
|
98
|
+
|
99
|
+
def format_datetime(time)
|
100
|
+
if @datetime_format.nil?
|
101
|
+
time.strftime("%Y-%m-%dT%H:%M:%S.") << "%06d " % time.usec
|
102
|
+
else
|
103
|
+
time.strftime(@datetime_format)
|
104
|
+
end
|
105
|
+
end
|
48
106
|
end
|
49
107
|
end
|
108
|
+
|
109
|
+
class String
|
110
|
+
def clear; colorize(self, "\e[0m"); end
|
111
|
+
# Erase the current line of terminal output.
|
112
|
+
def erase_line; colorize(self, "\e[K"); end
|
113
|
+
# Erase the character under the cursor.
|
114
|
+
def erase_char; colorize(self, "\e[P"); end
|
115
|
+
# The start of an ANSI bold sequence.
|
116
|
+
def bold; colorize(self, "\e[1m"); end
|
117
|
+
# The start of an ANSI dark sequence.
|
118
|
+
def dark; colorize(self, "\e[2m"); end
|
119
|
+
# The start of an ANSI underline sequence.
|
120
|
+
def underline; colorize(self, "\e[4m"); end
|
121
|
+
# The start of an ANSI blink sequence.
|
122
|
+
def blink; colorize(self, "\e[5m"); end
|
123
|
+
# The start of an ANSI reverse sequence.
|
124
|
+
def reverse; colorize(self, "\e[7m"); end
|
125
|
+
# The start of an ANSI concealed sequence.
|
126
|
+
def concealed; colorize(self, "\e[8m"); end
|
127
|
+
|
128
|
+
# Set the terminal's foreground ANSI color to
|
129
|
+
def BLACK; colorize(self, "\e[0;30m"); end
|
130
|
+
def GRAY; colorize(self, "\e[1;30m"); end
|
131
|
+
def RED; colorize(self, "\e[0;31m"); end
|
132
|
+
def MAGENTA; colorize(self, "\e[1;31m"); end
|
133
|
+
def GREEN; colorize(self, "\e[0;32m"); end
|
134
|
+
def OLIVE; colorize(self, "\e[1;32m"); end
|
135
|
+
def YELLOW; colorize(self, "\e[0;33m"); end
|
136
|
+
def CREAM; colorize(self, "\e[1;33m"); end
|
137
|
+
def BLUE; colorize(self, "\e[0;34m"); end
|
138
|
+
def PURPLE; colorize(self, "\e[1;34m"); end
|
139
|
+
def ORANGE; colorize(self, "\e[0;35m"); end
|
140
|
+
def MUSTARD; colorize(self, "\e[1;35m"); end
|
141
|
+
def CYAN; colorize(self, "\e[0;36m"); end
|
142
|
+
def CYAN2; colorize(self, "\e[1;36m"); end
|
143
|
+
def WHITE; colorize(self, "\e[0;97m"); end
|
144
|
+
|
145
|
+
# Set the terminal's background ANSI color to
|
146
|
+
def on_black; colorize(self, "\e[40m"); end
|
147
|
+
def on_red; colorize(self, "\e[41m"); end
|
148
|
+
def on_green; colorize(self, "\e[42m"); end
|
149
|
+
def on_yellow; colorize(self, "\e[43m"); end
|
150
|
+
def on_blue; colorize(self, "\e[44m"); end
|
151
|
+
def on_magenta; colorize(self, "\e[45m"); end
|
152
|
+
def on_cyan; colorize(self, "\e[46m"); end
|
153
|
+
def on_white; colorize(self, "\e[47m"); end
|
154
|
+
|
155
|
+
def colorize(text, color_code) "#{color_code}#{text}\e[0m" end
|
156
|
+
end
|
data/lib/hoodie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoodie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Harding
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hitimes
|