Module: OLogger
- Defined in:
- lib/ologger.rb,
lib/ologger/buffer.rb,
lib/ologger/parser.rb,
lib/ologger/middleware.rb,
lib/ologger/object_methods.rb
Defined Under Namespace
Modules: ObjectMethods, Parser
Classes: Buffer, Middleware
Constant Summary
collapse
- LOG_URL =
'/game_logs/'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.on_raise ⇒ Object
Returns the value of attribute on_raise.
18
19
20
|
# File 'lib/ologger.rb', line 18
def on_raise
@on_raise
end
|
.path ⇒ Object
Returns the value of attribute path.
18
19
20
|
# File 'lib/ologger.rb', line 18
def path
@path
end
|
Class Method Details
.buffer ⇒ Object
83
84
85
|
# File 'lib/ologger.rb', line 83
def buffer
@buffer ||= Buffer.new
end
|
.create_module(log_module) ⇒ Object
72
73
74
75
76
77
|
# File 'lib/ologger.rb', line 72
def create_module(log_module)
path = OLogger.path + log_module
unless path.exist?
path.mkpath
end
end
|
.enable(&block) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/ologger.rb', line 87
def enable(&block)
buffer.flush
Thread.current[:ologger_raiser] = true
begin
yield
rescue StandardError => e
e.obj.ologger "Exception:", :objs => [e, e.backtrace]
on_raise.call(e) if on_raise && on_raise.is_a?(Proc)
ensure
Thread.current[:ologger_raiser] = false
buffer.write
end
end
|
.filter(controller, &block) ⇒ Object
101
102
103
|
# File 'lib/ologger.rb', line 101
def filter(controller, &block)
enable(&block)
end
|
.gc ⇒ Object
22
23
24
|
# File 'lib/ologger.rb', line 22
def gc
gc_dir
end
|
.gc_dir(dir_path = OLogger.path) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/ologger.rb', line 26
def gc_dir(dir_path = OLogger.path)
if dir_path.directory?
dir_path.each_entry do |path|
if not_self_and_parent path
gc_dir(dir_path + path)
end
end
else
if needed_to_remove?(dir_path)
dir_path.delete
end
end
end
|
.get_log(log_id) ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/ologger.rb', line 48
def get_log(log_id)
name = parse_log_id(log_id)
path = OLogger.path + name[:module] + name[:file]
if File.exist?(path)
OLogger::Parser.parse(File.read(path))
else
nil
end
end
|
.get_logs(log_module) ⇒ Object
62
63
64
65
|
# File 'lib/ologger.rb', line 62
def get_logs(log_module)
path = OLogger.path + log_module
path.entries.select { |v| not_self_and_parent v }.map{ |v| v.to_s.gsub /\.log$/, '' }
end
|
.included(receiver) ⇒ Object
106
107
108
109
|
# File 'lib/ologger.rb', line 106
def self.included(receiver)
receiver.send :include, ObjectMethods
receiver.extend ObjectMethods
end
|
.list_of_modules ⇒ Object
58
59
60
|
# File 'lib/ologger.rb', line 58
def list_of_modules
OLogger.path.entries.select { |v| not_self_and_parent v }
end
|
.logger(logger_module, logger) ⇒ Object
79
80
81
|
# File 'lib/ologger.rb', line 79
def logger(logger_module, logger)
Logger.new('logfile.log')
end
|
.needed_to_remove?(path) ⇒ Boolean
44
45
46
|
# File 'lib/ologger.rb', line 44
def needed_to_remove?(path)
path.mtime < 1.day.ago || path.size > 300.kilobytes
end
|
.not_self_and_parent(path) ⇒ Object
40
41
42
|
# File 'lib/ologger.rb', line 40
def not_self_and_parent(path)
path.to_s != '.' && path.to_s != '..'
end
|
.parse_log_id(log_id) ⇒ Object
67
68
69
70
|
# File 'lib/ologger.rb', line 67
def parse_log_id(log_id)
p = log_id.match(/(.+)\.(.+)/i)
{:module => p[1], :file => p[2] + '.log'}
end
|