-
Notifications
You must be signed in to change notification settings - Fork 21
/
README
112 lines (72 loc) · 3.15 KB
/
README
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
= About
AlogR enables a Ruby project to log to the filesystem using non-blocking asynchronous IO with no external dependencies.
= Author
Wayne E. Seguin (wayneeseguin at gmail dot com)
= How it works
A global logging buffer gets added to the running application.
There is a global buffer which is an array of fifo queues.
Worker threads are to pop the first element (which is a string) off of a fifo queue and "process" it.
Processing involves writing the string to disk using non-blocking asynchronous IO
Threads will be event based where the event is something being placed in the queue, or the queue non-empty.
= Config
You can choose the log that the application uses:
AlogR.new( "log/app_log.log" )
:log specifies the default log
AlogR.new( :log => "log/app_log.log" )
You may also specify any combination of logs corresponding to the log levels in addition to the default log:
AlogR.new( :log => "log/app_log.log", :error => "log/error.log", :debug => "log/debug.log")
where log levels are one of: [ emergency, alert, critical, error, warning, notice, info, debug ]
= Application Usage
First be sure to setup the logger:
$alogger = AlogR.new(:log)
To log a string to either the error log or the default log (depending on your configuration):
"Jonnie! You borked it!".log(:error)
Feature Requests:
# Be able to specify conditional filters
= Examples
* Example 1
require "alogr"
$logger = AlogR::Logger.new(:log => "/Users/wayne/projects/ruby/alogr/trunk/log/default.log")
"a test, should go to the logs 10 times\n".log.log.log.log.log.log.log.log.log.log
* Example 2
require "alogr"
$logger = AlogR.new(
:log => "/Users/wayne/projects/ruby/alogr/trunk/log/production.log",
:error => "/Users/wayne/projects/ruby/alogr/trunk/log/error.log"
)
"(1)this should go to the production log\n".log
"(2)this should go to error log\n".log(:error)
"(3)error\n".log :error
"(4)production\n".log :info
"(5)error".log :error
* Example 3
require "lib/alogr"
$logger = AlogR.new(
:log => "/Users/wayne/projects/ruby/alogr/trunk/log/production.log",
:error => "/Users/wayne/projects/ruby/alogr/trunk/log/error.log",
:info => "/Users/wayne/projects/ruby/alogr/trunk/log/info.log",
:warning => "/Users/wayne/projects/ruby/alogr/trunk/log/warning.log"
)
"this should go to info log".log
"this should go to error log".log(:error)
"this should go to production log".log(:warning)
"error".log :error
"warning".log :warning
"info".log :info
"yetanother error".log :error
* Example 4
require "lib/alogr"
$logger = AlogR.new(
:log => "/Users/wayne/projects/ruby/alogr/trunk/log/production.log",
:error => "/Users/wayne/projects/ruby/alogr/trunk/log/error.log",
:info => "/Users/wayne/projects/ruby/alogr/trunk/log/info.log",
/paypal => "/Users/wayne/projects/ruby/alogr/trunk/log/paypal.log"
)
"this should go to info log".log
"this should go to error log".log(:error)
"this should go to production log".log(:warning)
* Example 4:
If line matches a regexp then sent log/paypal.log as well as production.log
AlogR.new(:log => "log/production.log", /paypal/ => "log/paypal.log")
Gets logged to both
{ :something => "value", :something_else => "value" }.log