filterfish-logging 0.9.8

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.
Files changed (55) hide show
  1. data/History.txt +176 -0
  2. data/Manifest.txt +54 -0
  3. data/README.txt +93 -0
  4. data/Rakefile +28 -0
  5. data/data/logging.yaml +63 -0
  6. data/lib/logging.rb +288 -0
  7. data/lib/logging/appender.rb +257 -0
  8. data/lib/logging/appenders/console.rb +43 -0
  9. data/lib/logging/appenders/email.rb +131 -0
  10. data/lib/logging/appenders/file.rb +55 -0
  11. data/lib/logging/appenders/growl.rb +182 -0
  12. data/lib/logging/appenders/io.rb +81 -0
  13. data/lib/logging/appenders/rolling_file.rb +293 -0
  14. data/lib/logging/appenders/syslog.rb +202 -0
  15. data/lib/logging/config/yaml_configurator.rb +197 -0
  16. data/lib/logging/layout.rb +103 -0
  17. data/lib/logging/layouts/basic.rb +35 -0
  18. data/lib/logging/layouts/pattern.rb +292 -0
  19. data/lib/logging/log_event.rb +50 -0
  20. data/lib/logging/logger.rb +388 -0
  21. data/lib/logging/repository.rb +151 -0
  22. data/lib/logging/root_logger.rb +60 -0
  23. data/lib/logging/utils.rb +44 -0
  24. data/tasks/ann.rake +78 -0
  25. data/tasks/bones.rake +21 -0
  26. data/tasks/gem.rake +106 -0
  27. data/tasks/manifest.rake +49 -0
  28. data/tasks/notes.rake +22 -0
  29. data/tasks/post_load.rake +37 -0
  30. data/tasks/rdoc.rake +49 -0
  31. data/tasks/rubyforge.rake +57 -0
  32. data/tasks/setup.rb +253 -0
  33. data/tasks/svn.rake +45 -0
  34. data/tasks/test.rake +38 -0
  35. data/test/appenders/test_console.rb +40 -0
  36. data/test/appenders/test_email.rb +167 -0
  37. data/test/appenders/test_file.rb +94 -0
  38. data/test/appenders/test_growl.rb +115 -0
  39. data/test/appenders/test_io.rb +113 -0
  40. data/test/appenders/test_rolling_file.rb +187 -0
  41. data/test/appenders/test_syslog.rb +192 -0
  42. data/test/benchmark.rb +88 -0
  43. data/test/config/test_yaml_configurator.rb +41 -0
  44. data/test/layouts/test_basic.rb +44 -0
  45. data/test/layouts/test_pattern.rb +173 -0
  46. data/test/setup.rb +66 -0
  47. data/test/test_appender.rb +162 -0
  48. data/test/test_layout.rb +85 -0
  49. data/test/test_log_event.rb +81 -0
  50. data/test/test_logger.rb +589 -0
  51. data/test/test_logging.rb +250 -0
  52. data/test/test_repository.rb +123 -0
  53. data/test/test_root_logger.rb +82 -0
  54. data/test/test_utils.rb +48 -0
  55. metadata +126 -0
@@ -0,0 +1,49 @@
1
+ # $Id$
2
+
3
+ require 'find'
4
+
5
+ namespace :manifest do
6
+
7
+ desc 'Verify the manifest'
8
+ task :check do
9
+ fn = PROJ.manifest_file + '.tmp'
10
+ files = manifest_files
11
+
12
+ File.open(fn, 'w') {|fp| fp.puts files}
13
+ lines = %x(#{DIFF} -du #{PROJ.manifest_file} #{fn}).split("\n")
14
+ if HAVE_FACETS_ANSICODE and ENV.has_key?('TERM')
15
+ lines.map! do |line|
16
+ case line
17
+ when %r/^(-{3}|\+{3})/; nil
18
+ when %r/^@/; Console::ANSICode.blue line
19
+ when %r/^\+/; Console::ANSICode.green line
20
+ when %r/^\-/; Console::ANSICode.red line
21
+ else line end
22
+ end
23
+ end
24
+ puts lines.compact
25
+ rm fn rescue nil
26
+ end
27
+
28
+ desc 'Create a new manifest'
29
+ task :create do
30
+ files = manifest_files
31
+ unless test(?f, PROJ.manifest_file)
32
+ files << PROJ.manifest_file
33
+ files.sort!
34
+ end
35
+ File.open(PROJ.manifest_file, 'w') {|fp| fp.puts files}
36
+ end
37
+
38
+ task :assert do
39
+ files = manifest_files
40
+ manifest = File.read(PROJ.manifest_file).split($/)
41
+ raise "ERROR: #{PROJ.manifest_file} is out of date" unless files == manifest
42
+ end
43
+
44
+ end # namespace :manifest
45
+
46
+ desc 'Alias to manifest:check'
47
+ task :manifest => 'manifest:check'
48
+
49
+ # EOF
data/tasks/notes.rake ADDED
@@ -0,0 +1,22 @@
1
+ # $Id$
2
+
3
+ if HAVE_BONES
4
+
5
+ desc "Enumerate all annotations"
6
+ task :notes do
7
+ Bones::AnnotationExtractor.enumerate(
8
+ PROJ, PROJ.notes.tags.join('|'), :tag => true)
9
+ end
10
+
11
+ namespace :notes do
12
+ PROJ.notes.tags.each do |tag|
13
+ desc "Enumerate all #{tag} annotations"
14
+ task tag.downcase.to_sym do
15
+ Bones::AnnotationExtractor.enumerate(PROJ, tag)
16
+ end
17
+ end
18
+ end
19
+
20
+ end # if HAVE_BONES
21
+
22
+ # EOF
@@ -0,0 +1,37 @@
1
+ # $Id$
2
+
3
+ # This file does not define any rake tasks. It is used to load some project
4
+ # settings if they are not defined by the user.
5
+
6
+ PROJ.rdoc.exclude << "^#{Regexp.escape(PROJ.manifest_file)}$"
7
+ PROJ.exclude << "^#{Regexp.escape(PROJ.ann.file)}$"
8
+
9
+ flatten_arrays = lambda do |this,os|
10
+ os.instance_variable_get(:@table).each do |key,val|
11
+ next if key == :dependencies
12
+ case val
13
+ when Array; val.flatten!
14
+ when OpenStruct; this.call(this,val)
15
+ end
16
+ end
17
+ end
18
+ flatten_arrays.call(flatten_arrays,PROJ)
19
+
20
+ PROJ.changes ||= paragraphs_of(PROJ.history_file, 0..1).join("\n\n")
21
+
22
+ PROJ.description ||= paragraphs_of(PROJ.readme_file, 'description').join("\n\n")
23
+
24
+ PROJ.summary ||= PROJ.description.split('.').first
25
+
26
+ PROJ.gem.files ||=
27
+ if test(?f, PROJ.manifest_file)
28
+ files = File.readlines(PROJ.manifest_file).map {|fn| fn.chomp.strip}
29
+ files.delete ''
30
+ files
31
+ else [] end
32
+
33
+ PROJ.gem.executables ||= PROJ.gem.files.find_all {|fn| fn =~ %r/^bin/}
34
+
35
+ PROJ.rdoc.main ||= PROJ.readme_file
36
+
37
+ # EOF
data/tasks/rdoc.rake ADDED
@@ -0,0 +1,49 @@
1
+ # $Id$
2
+
3
+ require 'rake/rdoctask'
4
+
5
+ namespace :doc do
6
+
7
+ desc 'Generate RDoc documentation'
8
+ Rake::RDocTask.new do |rd|
9
+ rdoc = PROJ.rdoc
10
+ rd.main = rdoc.main
11
+ rd.rdoc_dir = rdoc.dir
12
+
13
+ incl = Regexp.new(rdoc.include.join('|'))
14
+ excl = Regexp.new(rdoc.exclude.join('|'))
15
+ files = PROJ.gem.files.find_all do |fn|
16
+ case fn
17
+ when excl; false
18
+ when incl; true
19
+ else false end
20
+ end
21
+ rd.rdoc_files.push(*files)
22
+
23
+ title = "#{PROJ.name}-#{PROJ.version} Documentation"
24
+ title = "#{PROJ.rubyforge.name}'s " + title if PROJ.rubyforge.name != title
25
+
26
+ rd.options << "-t #{title}"
27
+ rd.options.concat(rdoc.opts)
28
+ end
29
+
30
+ desc 'Generate ri locally for testing'
31
+ task :ri => :clobber_ri do
32
+ sh "#{RDOC} --ri -o ri ."
33
+ end
34
+
35
+ task :clobber_ri do
36
+ rm_r 'ri' rescue nil
37
+ end
38
+
39
+ end # namespace :doc
40
+
41
+ desc 'Alias to doc:rdoc'
42
+ task :doc => 'doc:rdoc'
43
+
44
+ desc 'Remove all build products'
45
+ task :clobber => %w(doc:clobber_rdoc doc:clobber_ri)
46
+
47
+ remove_desc_for_task %w(doc:clobber_rdoc)
48
+
49
+ # EOF
@@ -0,0 +1,57 @@
1
+ # $Id$
2
+
3
+ if PROJ.rubyforge.name && HAVE_RUBYFORGE
4
+
5
+ require 'rubyforge'
6
+ require 'rake/contrib/sshpublisher'
7
+
8
+ namespace :gem do
9
+ desc 'Package and upload to RubyForge'
10
+ task :release => [:clobber, :package] do |t|
11
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
12
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
13
+ pkg = "pkg/#{PROJ.gem.spec.full_name}"
14
+
15
+ if $DEBUG then
16
+ puts "release_id = rf.add_release #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
17
+ puts "rf.add_file #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
18
+ end
19
+
20
+ rf = RubyForge.new
21
+ puts 'Logging in'
22
+ rf.login
23
+
24
+ c = rf.userconfig
25
+ c['release_notes'] = PROJ.description if PROJ.description
26
+ c['release_changes'] = PROJ.changes if PROJ.changes
27
+ c['preformatted'] = true
28
+
29
+ files = [(PROJ.gem.need_tar ? "#{pkg}.tgz" : nil),
30
+ (PROJ.gem.need_zip ? "#{pkg}.zip" : nil),
31
+ "#{pkg}.gem"].compact
32
+
33
+ puts "Releasing #{PROJ.name} v. #{PROJ.version}"
34
+ rf.add_release PROJ.rubyforge.name, PROJ.name, PROJ.version, *files
35
+ end
36
+ end # namespace :gem
37
+
38
+
39
+ namespace :doc do
40
+ desc "Publish RDoc to RubyForge"
41
+ task :release => %w(doc:clobber_rdoc doc:rdoc) do
42
+ config = YAML.load(
43
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
44
+ )
45
+
46
+ host = "#{config['username']}@rubyforge.org"
47
+ remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge.name}/"
48
+ remote_dir << PROJ.rdoc.remote_dir if PROJ.rdoc.remote_dir
49
+ local_dir = PROJ.rdoc.dir
50
+
51
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
52
+ end
53
+ end # namespace :doc
54
+
55
+ end # if HAVE_RUBYFORGE
56
+
57
+ # EOF
data/tasks/setup.rb ADDED
@@ -0,0 +1,253 @@
1
+ # $Id$
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/clean'
6
+ require 'fileutils'
7
+ require 'ostruct'
8
+
9
+ class OpenStruct; undef :gem; end
10
+
11
+ PROJ = OpenStruct.new(
12
+ # Project Defaults
13
+ :name => nil,
14
+ :summary => nil,
15
+ :description => nil,
16
+ :changes => nil,
17
+ :authors => nil,
18
+ :email => nil,
19
+ :url => nil,
20
+ :version => ENV['VERSION'] || '0.0.0',
21
+ :exclude => %w(tmp$ bak$ ~$ CVS .svn/ ^pkg/ ^doc/),
22
+ :release_name => ENV['RELEASE'],
23
+
24
+ # System Defaults
25
+ :ruby_opts => %w(-w),
26
+ :libs => [],
27
+ :history_file => 'History.txt',
28
+ :manifest_file => 'Manifest.txt',
29
+ :readme_file => 'README.txt',
30
+
31
+ # Announce
32
+ :ann => OpenStruct.new(
33
+ :file => 'announcement.txt',
34
+ :text => nil,
35
+ :paragraphs => [],
36
+ :email => {
37
+ :from => nil,
38
+ :to => %w(ruby-talk@ruby-lang.org),
39
+ :server => 'localhost',
40
+ :port => 25,
41
+ :domain => ENV['HOSTNAME'],
42
+ :acct => nil,
43
+ :passwd => nil,
44
+ :authtype => :plain
45
+ }
46
+ ),
47
+
48
+ # Gem Packaging
49
+ :gem => OpenStruct.new(
50
+ :dependencies => [],
51
+ :executables => nil,
52
+ :extensions => FileList['ext/**/extconf.rb'],
53
+ :files => nil,
54
+ :need_tar => true,
55
+ :need_zip => false,
56
+ :post_install_message => nil
57
+ ),
58
+
59
+ # File Annotations
60
+ :notes => OpenStruct.new(
61
+ :exclude => %w(^tasks/setup.rb$),
62
+ :extensions => %w(.txt .rb .erb) << '',
63
+ :tags => %w(FIXME OPTIMIZE TODO)
64
+ ),
65
+
66
+ # Rcov
67
+ :rcov => OpenStruct.new(
68
+ :dir => 'coverage',
69
+ :opts => %w[--sort coverage -T],
70
+ :threshold => 90.0,
71
+ :threshold_exact => false
72
+ ),
73
+
74
+ # Rdoc
75
+ :rdoc => OpenStruct.new(
76
+ :opts => [],
77
+ :include => %w(^lib/ ^bin/ ^ext/ .txt$),
78
+ :exclude => %w(extconf.rb$),
79
+ :main => nil,
80
+ :dir => 'doc',
81
+ :remote_dir => nil
82
+ ),
83
+
84
+ # Rubyforge
85
+ :rubyforge => OpenStruct.new(
86
+ :name => nil
87
+ ),
88
+
89
+ # Rspec
90
+ :spec => OpenStruct.new(
91
+ :files => FileList['spec/**/*_spec.rb'],
92
+ :opts => []
93
+ ),
94
+
95
+ # Subversion Repository
96
+ :svn => OpenStruct.new(
97
+ :root => nil,
98
+ :path => nil,
99
+ :trunk => 'trunk',
100
+ :tags => 'tags',
101
+ :branches => 'branches'
102
+ ),
103
+
104
+ # Test::Unit
105
+ :test => OpenStruct.new(
106
+ :files => FileList['test/**/test_*.rb'],
107
+ :file => 'test/all.rb',
108
+ :opts => []
109
+ )
110
+ )
111
+
112
+ # Load the other rake files in the tasks folder
113
+ rakefiles = Dir.glob('tasks/*.rake').sort
114
+ rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
115
+ import(*rakefiles)
116
+
117
+ # Setup the project libraries
118
+ %w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
119
+
120
+ # Setup some constants
121
+ WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
122
+
123
+ DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
124
+
125
+ def quiet( &block )
126
+ io = [STDOUT.dup, STDERR.dup]
127
+ STDOUT.reopen DEV_NULL
128
+ STDERR.reopen DEV_NULL
129
+ block.call
130
+ ensure
131
+ STDOUT.reopen io.first
132
+ STDERR.reopen io.last
133
+ end
134
+
135
+ DIFF = if WIN32 then 'diff.exe'
136
+ else
137
+ if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
138
+ else 'diff' end
139
+ end unless defined? DIFF
140
+
141
+ SUDO = if WIN32 then ''
142
+ else
143
+ if quiet {system 'which sudo'} then 'sudo'
144
+ else '' end
145
+ end
146
+
147
+ RCOV = WIN32 ? 'rcov.bat' : 'rcov'
148
+ RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
149
+ GEM = WIN32 ? 'gem.bat' : 'gem'
150
+
151
+ %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
152
+ begin
153
+ require lib
154
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
155
+ rescue LoadError
156
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
157
+ end
158
+ end
159
+
160
+ # Reads a file at +path+ and spits out an array of the +paragraphs+
161
+ # specified.
162
+ #
163
+ # changes = paragraphs_of('History.txt', 0..1).join("\n\n")
164
+ # summary, *description = paragraphs_of('README.txt', 3, 3..8)
165
+ #
166
+ def paragraphs_of( path, *paragraphs )
167
+ title = String === paragraphs.first ? paragraphs.shift : nil
168
+ ary = File.read(path).delete("\r").split(/\n\n+/)
169
+
170
+ result = if title
171
+ tmp, matching = [], false
172
+ rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
173
+ paragraphs << (0..-1) if paragraphs.empty?
174
+
175
+ ary.each do |val|
176
+ if val =~ rgxp
177
+ break if matching
178
+ matching = true
179
+ rgxp = %r/^=+/i
180
+ elsif matching
181
+ tmp << val
182
+ end
183
+ end
184
+ tmp
185
+ else ary end
186
+
187
+ result.values_at(*paragraphs)
188
+ end
189
+
190
+ # Adds the given gem _name_ to the current project's dependency list. An
191
+ # optional gem _version_ can be given. If omitted, the newest gem version
192
+ # will be used.
193
+ #
194
+ def depend_on( name, version = nil )
195
+ spec = Gem.source_index.find_name(name).last
196
+ version = spec.version.to_s if version.nil? and !spec.nil?
197
+
198
+ PROJ.gem.dependencies << case version
199
+ when nil; [name]
200
+ when %r/^\d/; [name, ">= #{version}"]
201
+ else [name, version] end
202
+ end
203
+
204
+ # Adds the given arguments to the include path if they are not already there
205
+ #
206
+ def ensure_in_path( *args )
207
+ args.each do |path|
208
+ path = File.expand_path(path)
209
+ $:.unshift(path) if test(?d, path) and not $:.include?(path)
210
+ end
211
+ end
212
+
213
+ # Find a rake task using the task name and remove any description text. This
214
+ # will prevent the task from being displayed in the list of available tasks.
215
+ #
216
+ def remove_desc_for_task( names )
217
+ Array(names).each do |task_name|
218
+ task = Rake.application.tasks.find {|t| t.name == task_name}
219
+ next if task.nil?
220
+ task.instance_variable_set :@comment, nil
221
+ end
222
+ end
223
+
224
+ # Change working directories to _dir_, call the _block_ of code, and then
225
+ # change back to the original working directory (the current directory when
226
+ # this method was called).
227
+ #
228
+ def in_directory( dir, &block )
229
+ curdir = pwd
230
+ begin
231
+ cd dir
232
+ return block.call
233
+ ensure
234
+ cd curdir
235
+ end
236
+ end
237
+
238
+ # Scans the current working directory and creates a list of files that are
239
+ # candidates to be in the manifest.
240
+ #
241
+ def manifest_files
242
+ files = []
243
+ exclude = Regexp.new(PROJ.exclude.join('|'))
244
+ Find.find '.' do |path|
245
+ path.sub! %r/^(\.\/|\/)/o, ''
246
+ next unless test ?f, path
247
+ next if path =~ exclude
248
+ files << path
249
+ end
250
+ files.sort!
251
+ end
252
+
253
+ # EOF