openvz 1.1 → 1.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/openvz/log.rb +15 -26
- data/lib/openvz.rb +1 -1
- data/openvz.gemspec +1 -1
- metadata +3 -3
data/lib/openvz/log.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
module OpenVZ
|
2
|
+
#
|
2
3
|
# A simple class that allows logging at various levels.
|
4
|
+
#
|
3
5
|
class Log
|
4
|
-
class << self
|
5
|
-
@logger = nil
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
@logger.class
|
10
|
-
end
|
7
|
+
@known_levels = [:fatal, :error, :warn, :info, :debug]
|
8
|
+
@active_level = :warn
|
11
9
|
|
10
|
+
class << self
|
12
11
|
# Logs at info level
|
13
12
|
def info(msg)
|
14
13
|
log(:info, msg)
|
@@ -34,34 +33,24 @@ module OpenVZ
|
|
34
33
|
log(:error, msg)
|
35
34
|
end
|
36
35
|
|
37
|
-
#
|
38
|
-
def instance
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
# increments the active log level
|
43
|
-
def cycle_level
|
44
|
-
@logger.cycle_level if @configured
|
45
|
-
end
|
46
|
-
|
47
|
-
# logs a message at a certain level
|
36
|
+
# logs message at level
|
48
37
|
def log(level, msg)
|
49
|
-
|
50
|
-
|
38
|
+
puts "#{@known_levels.index(level)} <= #{@known_levels.index(@active_level)}"
|
39
|
+
if @known_levels.index(level) <= @known_levels.index(@active_level)
|
40
|
+
t = Time.new.strftime("%H:%M:%S")
|
41
|
+
STDERR.puts "#{t}: #{level}: #{from}: #{msg}"
|
42
|
+
end
|
51
43
|
end
|
52
44
|
|
53
|
-
#
|
54
|
-
def
|
55
|
-
@
|
45
|
+
# Set the log level.
|
46
|
+
def set_level(level)
|
47
|
+
@active_level = level
|
56
48
|
end
|
57
49
|
|
58
|
-
|
59
|
-
# figures out the filename that called us
|
50
|
+
# filename that called us
|
60
51
|
def from
|
61
52
|
from = File.basename(caller[2])
|
62
53
|
end
|
63
54
|
end
|
64
55
|
end
|
65
56
|
end
|
66
|
-
|
67
|
-
# vi:tabstop=4:expandtab:ai:filetype=ruby
|
data/lib/openvz.rb
CHANGED
data/openvz.gemspec
CHANGED
metadata
CHANGED