-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlog_queue.rb
91 lines (57 loc) · 1.31 KB
/
log_queue.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require 'thread'
require 'logger'
module LQ
def self.start_up()
@queue ||= Array.new()
@mutex = Mutex.new()
@shutdown = false
@log = Logger.new(STDOUT) # TODO Make this settable
@thread = Thread.new do
get_to_da_choppa
end
end
def self.get_to_da_choppa()
while (!@shutdown)
if (@queue.length > 0)
val = ""
@mutex.synchronize do
val = @queue.shift()
end
@log.add(val[0],val[1])
end
sleep(0.1)
end
end
def self.shutdown()
#Shutting down will disallow anymore additions
#to the queue, let the queue finish, then stop.
@shutdown = true
@thread.join
end
def self.add(severity, msg=nil)
if (@shutdown)
return
end
@mutex.synchronize do
@queue.push([severity, msg])
end
end
def self.debug(msg=nil)
add(Logger::Severity::DEBUG, msg)
end
def self.info(msg=nil)
add(Logger::Severity::INFO, msg)
end
def self.warn(msg=nil)
add(Logger::Severity::WARN, msg)
end
def self.error(msg=nil)
add(Logger::Severity::ERROR, msg)
end
def self.fatal(msg=nil)
add(Logger::Severity::FATAL, msg)
end
def self.unknown(msg=nil)
add(Logger::Severity::UNKNOWN, msg)
end
end