logit 1.0.1 → 1.0.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/README.rdoc +30 -3
- data/Rakefile +1 -1
- data/lib/logit.rb +19 -5
- data/logit.gemspec +1 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -43,9 +43,27 @@ this will add something like 'Publisher 1234' to log entries.
|
|
43
43
|
|
44
44
|
this will rotate logs up to a total of 5 files with max size of 102400
|
45
45
|
bytes.
|
46
|
+
|
47
|
+
==== Flushing each message to the log file immediately
|
48
|
+
|
49
|
+
logs_to :publisher, :flush_mode => :immediate
|
50
|
+
|
51
|
+
The default behavior is to use the default file buffering. Turning this
|
52
|
+
on will cause each message to be written to the log file immediately.
|
53
|
+
Alternatively, you can control this programmatically like so:
|
54
|
+
|
55
|
+
logger.info("my message")
|
56
|
+
logger.flush()
|
57
|
+
|
58
|
+
==== Also print to stdout
|
46
59
|
|
60
|
+
logs_to :publisher, :stdout => true
|
61
|
+
|
62
|
+
This will print log messages to stdout in addition to writing them to the
|
63
|
+
log file.
|
47
64
|
|
48
|
-
|
65
|
+
|
66
|
+
= Rails
|
49
67
|
|
50
68
|
LogIt automatically detects if you're running in a Rails environment. If
|
51
69
|
so, it will write to the Rails log directory and appends the
|
@@ -53,6 +71,7 @@ environment to the log file name. For example:
|
|
53
71
|
|
54
72
|
RAILS_ROOT/log/publisher_development.log
|
55
73
|
|
74
|
+
|
56
75
|
= Example log
|
57
76
|
|
58
77
|
09-12-2010 10:27:10 INFO [publisher 4607]: Publishing files to endpoint.
|
@@ -62,23 +81,31 @@ environment to the log file name. For example:
|
|
62
81
|
09-12-2010 10:28:32 INFO [publisher 4634]: Publishing files to endpoint.
|
63
82
|
09-12-2010 10:28:32 WARN [publisher 4634]: No files available to publish.
|
64
83
|
|
65
|
-
= Installation
|
66
84
|
|
85
|
+
= Installation
|
67
86
|
== As a Gem
|
68
87
|
|
69
88
|
$ gem install logit
|
70
89
|
|
90
|
+
|
71
91
|
== As a Rails plugin
|
72
92
|
|
73
93
|
$ script/plugin install git://github.com/ssayles/logit.git
|
74
94
|
|
75
95
|
|
96
|
+
|
97
|
+
= Release Notes
|
98
|
+
|
99
|
+
[1.0.2]
|
100
|
+
* Added :flush_mode option. Set this to <tt>:immediate</tt> if you want each message flushed to the log file immediately.
|
101
|
+
* Added :stdout option. Set this to <tt>true</tt> if you want logs printed to stdout as well.
|
102
|
+
|
103
|
+
|
76
104
|
= TODO
|
77
105
|
|
78
106
|
* Allow users to pass in a proc or a name of a method to call to handle formatting of log entries.
|
79
107
|
* Add some tests?
|
80
108
|
|
81
|
-
|
82
109
|
= Credits
|
83
110
|
|
84
111
|
LogIt is written and maintained by {Scott Sayles}[mailto:ssayles@users.sourceforge.net].
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('logit', '1.0.
|
5
|
+
Echoe.new('logit', '1.0.2') do |p|
|
6
6
|
p.description = 'Easily add custom logging abilities to your Ruby or Rails application.'
|
7
7
|
p.url = 'http://github.com/codemariner/logit'
|
8
8
|
p.author = 'Scott Sayles'
|
data/lib/logit.rb
CHANGED
@@ -4,7 +4,7 @@ module Logit
|
|
4
4
|
end
|
5
5
|
|
6
6
|
module ClassMethods
|
7
|
-
DEFAULT_OPTS = {:write_mode => 'a'}
|
7
|
+
DEFAULT_OPTS = {:write_mode => 'a', :flush_mode => :default, :stdout => false}
|
8
8
|
|
9
9
|
begin
|
10
10
|
Module.const_get(:Logger)
|
@@ -17,6 +17,8 @@ module Logit
|
|
17
17
|
# * +:shift_age+ - Number of old logs to keep or frequency of rotation.
|
18
18
|
# * +:shift_size+ - Maximum logfile size that only applies when <tt>:shift_age</tt> is a number.
|
19
19
|
# * +:progname+ - Logging program name. The <tt>:progname</tt> value is used in the default logging format if defined.
|
20
|
+
# * +:flush_mode+ - One of <tt>:immediate</tt> or <tt>:default</tt>. <tt>:immediate</tt> will cause a write to the log file for each message logged. The default behavior is to use default file buffering.
|
21
|
+
# * +:stdout+ - If set to <tt>true</tt>, this will cause logs to be printed to stdout <b>in addition to</b> the log file.
|
20
22
|
#
|
21
23
|
# === Examples
|
22
24
|
#
|
@@ -114,8 +116,11 @@ module Logit
|
|
114
116
|
#
|
115
117
|
class Logger < Logger
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
+
DEFAULT_OPTS = {:write_mode => 'a', :flush_mode => :default}
|
120
|
+
|
121
|
+
def initialize(log_path, opts = DEFAULT_OPTS)
|
122
|
+
@opts = DEFAULT_OPTS.merge(opts)
|
123
|
+
@f = File.open(log_path, @opts[:write_mode])
|
119
124
|
super @f
|
120
125
|
end
|
121
126
|
|
@@ -123,12 +128,21 @@ module Logit
|
|
123
128
|
|
124
129
|
name = (progname) ? " [#{progname}]" : ""
|
125
130
|
|
126
|
-
"#{timestamp.strftime('%d-%m-%Y %H:%M:%S')} #{severity.ljust(6)}#{name}: #{msg}\n"
|
131
|
+
message = "#{timestamp.strftime('%d-%m-%Y %H:%M:%S')} #{severity.ljust(6)}#{name}: #{msg}\n"
|
132
|
+
puts message if @opts[:stdout]
|
133
|
+
message
|
127
134
|
end
|
128
|
-
|
135
|
+
|
136
|
+
def add(severity, message = nil, progname = nil, &block)
|
137
|
+
super(severity, message, progname, &block)
|
138
|
+
flush() if @opts[:flush_mode] == :immediate
|
139
|
+
end
|
140
|
+
|
141
|
+
# Causes any pending writes to be flushed to disk
|
129
142
|
def flush()
|
130
143
|
@f.flush()
|
131
144
|
end
|
145
|
+
|
132
146
|
end
|
133
147
|
|
134
148
|
end
|
data/logit.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Scott Sayles
|