alsa-backup 0.0.8 → 0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ Copyright © 2009, 2010 Alban Peignier, Florent Peyraud
2
+
3
+ This program is free software: you can redistribute it and/or modify
4
+ it under the terms of the GNU General public License as published by
5
+ the Free Software Foundation, either version 3 of the License, or
6
+ (at your option) any later version.
7
+
8
+ This program is distributed in the hope that it will be useful,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ GNU General public License for more details.
12
+
13
+ You should have received a copy of the GNU General public License
14
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -1,4 +1,6 @@
1
1
  .autotest
2
+ COPYING
3
+ COPYRIGHT
2
4
  History.txt
3
5
  Manifest.txt
4
6
  PostInstall.txt
@@ -8,7 +10,6 @@ TODO
8
10
  alsa-backup.gemspec
9
11
  bin/alsa-backup
10
12
  config.sample
11
- lib/alsa.rb
12
13
  lib/alsa_backup.rb
13
14
  lib/alsa_backup/cli.rb
14
15
  lib/alsa_backup/core_ext.rb
@@ -16,15 +17,16 @@ lib/alsa_backup/length_controller.rb
16
17
  lib/alsa_backup/recorder.rb
17
18
  lib/alsa_backup/writer.rb
18
19
  lib/sndfile.rb
20
+ lib/syslog_logger.rb
19
21
  script/console
20
22
  script/destroy
21
23
  script/generate
22
- spec/alsa/pcm_spec.rb
24
+ setup.rb
23
25
  spec/alsa_backup/cli_spec.rb
24
26
  spec/alsa_backup/core_ext_spec.rb
27
+ spec/alsa_backup/length_recorder_spec.rb
25
28
  spec/alsa_backup/recorder_spec.rb
26
29
  spec/alsa_backup/writer_spec.rb
27
- spec/alsa_backup_spec.rb
28
30
  spec/fixtures/config_test.rb
29
31
  spec/sndfile/info_spec.rb
30
32
  spec/spec.opts
@@ -1,6 +1,6 @@
1
1
  = AlsaBackup
2
2
 
3
- * http://github.com/alban.peignier/alsa-backup
3
+ * http://projects.tryphon.eu/alsa-backup
4
4
 
5
5
  == DESCRIPTION:
6
6
 
@@ -78,29 +78,19 @@ See config.sample.
78
78
  == INSTALL:
79
79
 
80
80
  sudo apt-get install libasound2 libsndfile1
81
- sudo gem install --source http://gems.github.com albanpeignier-alsa-backup
81
+ sudo gem install --source http://gemcutter.org alsa-backup
82
82
 
83
83
  == LICENSE:
84
84
 
85
- (The MIT License)
85
+ This program is free software: you can redistribute it and/or modify
86
+ it under the terms of the GNU General public License as published by
87
+ the Free Software Foundation, either version 3 of the License, or
88
+ (at your option) any later version.
86
89
 
87
- Copyright (c) 2009 Alban Peignier
90
+ This program is distributed in the hope that it will be useful,
91
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
92
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93
+ GNU General public License for more details.
88
94
 
89
- Permission is hereby granted, free of charge, to any person obtaining
90
- a copy of this software and associated documentation files (the
91
- 'Software'), to deal in the Software without restriction, including
92
- without limitation the rights to use, copy, modify, merge, publish,
93
- distribute, sublicense, and/or sell copies of the Software, and to
94
- permit persons to whom the Software is furnished to do so, subject to
95
- the following conditions:
96
-
97
- The above copyright notice and this permission notice shall be
98
- included in all copies or substantial portions of the Software.
99
-
100
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
101
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
102
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
103
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
104
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
105
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
106
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
95
+ You should have received a copy of the GNU General public License
96
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
data/Rakefile CHANGED
@@ -1,65 +1,65 @@
1
- require 'rubygems' unless ENV['NO_RUBYGEMS']
2
- %w[rake rake/clean fileutils newgem hoe rubigen].each { |f| require f }
3
- require File.dirname(__FILE__) + '/lib/alsa_backup'
4
-
5
- # Generate all the Rake tasks
6
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
7
- $hoe = Hoe.spec('alsa-backup') do |p|
8
- p.version = AlsaBackup::VERSION
9
- p.readme_file = 'README.rdoc'
10
- p.developer('Alban Peignier', 'alban@tryphon.eu')
11
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
12
- p.rubyforge_name = p.name # TODO this is default value
13
- p.extra_deps = [
14
- ['ffi','>= 0.3.5'], [ 'newgem', ">= #{::Newgem::VERSION}" ], [ 'daemons', '>= 1.0.10' ]
15
- ]
16
- p.extra_dev_deps = [
17
- ['newgem', ">= #{::Newgem::VERSION}"]
18
- ]
19
- p.url = 'http://projects.tryphon.eu/alsa-backup'
20
-
21
- p.clean_globs |= %w[**/.DS_Store tmp *.log]
22
- path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
23
- p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
24
- p.rsync_args = '-av --delete --ignore-errors'
25
- end
26
-
27
- desc 'Recreate Manifest.txt to include ALL files'
28
- task :manifest do
29
- `rake check_manifest | patch -p0 > Manifest.txt`
30
- end
31
-
32
- desc "Generate a #{$hoe.name}.gemspec file"
33
- task :gemspec do
34
- File.open("#{$hoe.name}.gemspec", "w") do |file|
35
- file.puts $hoe.spec.to_ruby
36
- end
37
- end
38
-
39
- require 'newgem/tasks' # load /tasks/*.rake
40
- Dir['tasks/**/*.rake'].each { |t| load t }
41
-
42
- task :default => :spec
43
-
44
- namespace :gems do
45
- task :install do
46
- gems = %w{active_support ffi rspec daemons}
47
- sh "sudo gem install #{gems.join(' ')}"
48
- end
49
- end
50
-
51
- require 'debian/build'
52
-
53
- include Debian::Build
54
- require 'debian/build/config'
55
-
56
- namespace "package" do
57
- Package.new(:"alsa-backup") do |t|
58
- t.version = '0.0.8'
59
- t.debian_increment = 1
60
-
61
- t.source_provider = GitExportProvider.new
62
- end
63
- end
64
-
65
- require 'debian/build/tasks'
1
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
2
+ %w[rake rake/clean fileutils newgem hoe rubigen].each { |f| require f }
3
+ require File.dirname(__FILE__) + '/lib/alsa_backup'
4
+
5
+ # Generate all the Rake tasks
6
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
7
+ $hoe = Hoe.spec('alsa-backup') do |p|
8
+ p.version = AlsaBackup::VERSION
9
+ p.readme_file = 'README.rdoc'
10
+ p.developer('Alban Peignier', 'alban@tryphon.eu')
11
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
12
+ p.rubyforge_name = p.name # TODO this is default value
13
+ p.extra_deps = [
14
+ ['ffi','>= 0.3.5'], [ 'newgem', ">= #{::Newgem::VERSION}" ], [ 'daemons', '>= 1.0.10' ]
15
+ ]
16
+ p.extra_dev_deps = [
17
+ ['newgem', ">= #{::Newgem::VERSION}"]
18
+ ]
19
+ p.url = 'http://projects.tryphon.eu/alsa-backup'
20
+
21
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
22
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
23
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
24
+ p.rsync_args = '-av --delete --ignore-errors'
25
+ end
26
+
27
+ desc 'Recreate Manifest.txt to include ALL files'
28
+ task :manifest do
29
+ `rake check_manifest | patch -p0 > Manifest.txt`
30
+ end
31
+
32
+ desc "Generate a #{$hoe.name}.gemspec file"
33
+ task :gemspec do
34
+ File.open("#{$hoe.name}.gemspec", "w") do |file|
35
+ file.puts $hoe.spec.to_ruby
36
+ end
37
+ end
38
+
39
+ require 'newgem/tasks' # load /tasks/*.rake
40
+ Dir['tasks/**/*.rake'].each { |t| load t }
41
+
42
+ task :default => :spec
43
+
44
+ namespace :gems do
45
+ task :install do
46
+ gems = %w{active_support ffi rspec daemons}
47
+ sh "sudo gem install #{gems.join(' ')}"
48
+ end
49
+ end
50
+
51
+ require 'debian/build'
52
+
53
+ include Debian::Build
54
+ require 'debian/build/config'
55
+
56
+ namespace "package" do
57
+ Package.new(:"alsa-backup") do |t|
58
+ t.version = '0.10'
59
+ t.debian_increment = 1
60
+
61
+ t.source_provider = GitExportProvider.new
62
+ end
63
+ end
64
+
65
+ require 'debian/build/tasks'
@@ -2,46 +2,46 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{alsa-backup}
5
- s.version = "0.0.8"
5
+ s.version = "0.10"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Alban Peignier"]
9
- s.date = %q{2010-01-23}
9
+ s.date = %q{2010-10-14}
10
10
  s.default_executable = %q{alsa-backup}
11
11
  s.description = %q{ALSA client to perform continuous recording}
12
12
  s.email = ["alban@tryphon.eu"]
13
13
  s.executables = ["alsa-backup"]
14
14
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt"]
15
- s.files = [".autotest", "History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "TODO", "alsa-backup.gemspec", "bin/alsa-backup", "config.sample", "lib/alsa.rb", "lib/alsa_backup.rb", "lib/alsa_backup/cli.rb", "lib/alsa_backup/core_ext.rb", "lib/alsa_backup/length_controller.rb", "lib/alsa_backup/recorder.rb", "lib/alsa_backup/writer.rb", "lib/sndfile.rb", "script/console", "script/destroy", "script/generate", "spec/alsa/pcm_spec.rb", "spec/alsa_backup/cli_spec.rb", "spec/alsa_backup/core_ext_spec.rb", "spec/alsa_backup/recorder_spec.rb", "spec/alsa_backup/writer_spec.rb", "spec/alsa_backup_spec.rb", "spec/fixtures/config_test.rb", "spec/sndfile/info_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
15
+ s.files = [".autotest", "COPYING", "COPYRIGHT", "History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "TODO", "alsa-backup.gemspec", "bin/alsa-backup", "config.sample", "lib/alsa_backup.rb", "lib/alsa_backup/cli.rb", "lib/alsa_backup/core_ext.rb", "lib/alsa_backup/length_controller.rb", "lib/alsa_backup/recorder.rb", "lib/alsa_backup/writer.rb", "lib/sndfile.rb", "lib/syslog_logger.rb", "script/console", "script/destroy", "script/generate", "setup.rb", "spec/alsa_backup/cli_spec.rb", "spec/alsa_backup/core_ext_spec.rb", "spec/alsa_backup/length_recorder_spec.rb", "spec/alsa_backup/recorder_spec.rb", "spec/alsa_backup/writer_spec.rb", "spec/fixtures/config_test.rb", "spec/sndfile/info_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
16
16
  s.homepage = %q{http://projects.tryphon.eu/alsa-backup}
17
17
  s.rdoc_options = ["--main", "README.rdoc"]
18
18
  s.require_paths = ["lib"]
19
19
  s.rubyforge_project = %q{alsa-backup}
20
- s.rubygems_version = %q{1.3.5}
20
+ s.rubygems_version = %q{1.3.7}
21
21
  s.summary = %q{ALSA client to perform continuous recording}
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
25
  s.specification_version = 3
26
26
 
27
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
28
  s.add_runtime_dependency(%q<ffi>, [">= 0.3.5"])
29
- s.add_runtime_dependency(%q<newgem>, [">= 1.5.2"])
29
+ s.add_runtime_dependency(%q<newgem>, [">= 1.5.3"])
30
30
  s.add_runtime_dependency(%q<daemons>, [">= 1.0.10"])
31
- s.add_development_dependency(%q<newgem>, [">= 1.5.2"])
32
- s.add_development_dependency(%q<hoe>, [">= 2.5.0"])
31
+ s.add_development_dependency(%q<newgem>, [">= 1.5.3"])
32
+ s.add_development_dependency(%q<hoe>, [">= 2.6.2"])
33
33
  else
34
34
  s.add_dependency(%q<ffi>, [">= 0.3.5"])
35
- s.add_dependency(%q<newgem>, [">= 1.5.2"])
35
+ s.add_dependency(%q<newgem>, [">= 1.5.3"])
36
36
  s.add_dependency(%q<daemons>, [">= 1.0.10"])
37
- s.add_dependency(%q<newgem>, [">= 1.5.2"])
38
- s.add_dependency(%q<hoe>, [">= 2.5.0"])
37
+ s.add_dependency(%q<newgem>, [">= 1.5.3"])
38
+ s.add_dependency(%q<hoe>, [">= 2.6.2"])
39
39
  end
40
40
  else
41
41
  s.add_dependency(%q<ffi>, [">= 0.3.5"])
42
- s.add_dependency(%q<newgem>, [">= 1.5.2"])
42
+ s.add_dependency(%q<newgem>, [">= 1.5.3"])
43
43
  s.add_dependency(%q<daemons>, [">= 1.0.10"])
44
- s.add_dependency(%q<newgem>, [">= 1.5.2"])
45
- s.add_dependency(%q<hoe>, [">= 2.5.0"])
44
+ s.add_dependency(%q<newgem>, [">= 1.5.3"])
45
+ s.add_dependency(%q<hoe>, [">= 2.6.2"])
46
46
  end
47
47
  end
@@ -5,7 +5,7 @@ require 'active_support'
5
5
  require 'logger'
6
6
 
7
7
  module AlsaBackup
8
- VERSION = '0.0.8'
8
+ VERSION = '0.10'
9
9
 
10
10
  def self.recorder
11
11
  @recorder ||= AlsaBackup::Recorder.new
@@ -5,6 +5,20 @@ class Time
5
5
  self.change(attribute => actual - actual%modulo)
6
6
  end
7
7
 
8
+ # FIXME cloned by waiting correct require 'active_support/..' for active_support > 3
9
+ def change(options)
10
+ ::Time.send(
11
+ self.utc? ? :utc : :local,
12
+ options[:year] || self.year,
13
+ options[:month] || self.month,
14
+ options[:mday] || self.mday,
15
+ options[:hour] || self.hour,
16
+ options[:min] || (options[:hour] ? 0 : self.min),
17
+ options[:sec] || ((options[:hour] || options[:min]) ? 0 : self.sec),
18
+ options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : self.usec)
19
+ )
20
+ end
21
+
8
22
  end
9
23
 
10
24
  class File
@@ -15,7 +15,7 @@ module AlsaBackup
15
15
  end
16
16
 
17
17
  attr_accessor :file, :directory, :error_handler
18
- attr_accessor :device, :sample_rate, :channels
18
+ attr_accessor :device, :sample_rate, :channels, :buffer_time, :period_time
19
19
 
20
20
  def start(seconds_to_record = nil)
21
21
  length_controller = self.length_controller(seconds_to_record)
@@ -39,7 +39,14 @@ module AlsaBackup
39
39
  end
40
40
 
41
41
  def open_capture(&block)
42
- ALSA::PCM::Capture.open(device, format(:sample_format => :s16_le), &block)
42
+ ALSA::PCM::Capture.open(device, alsa_options, &block)
43
+ end
44
+
45
+ def alsa_options
46
+ format(:sample_format => :s16_le).tap do |alsa_options|
47
+ alsa_options[:buffer_time] = buffer_time if buffer_time
48
+ alsa_options[:period_time] = period_time if period_time
49
+ end
43
50
  end
44
51
 
45
52
  def handle_error(e, try_to_continue = true)
@@ -19,9 +19,7 @@ module AlsaBackup
19
19
  @file = options[:file]
20
20
  @format = options[:format]
21
21
 
22
- @on_close_callbacks = [ Proc.new do |file|
23
- Writer.delete_empty_file(file)
24
- end ]
22
+ @on_close_callbacks = []
25
23
  @on_close_callbacks << options[:on_close] if options[:on_close]
26
24
  end
27
25
 
@@ -59,6 +57,9 @@ module AlsaBackup
59
57
 
60
58
  def on_close(file)
61
59
  AlsaBackup.logger.info('close current file')
60
+ return if Writer.delete_empty_file(file)
61
+
62
+ AlsaBackup.logger.debug("invoke #{@on_close_callbacks.size} callback(s)")
62
63
  @on_close_callbacks.each do |callback|
63
64
  begin
64
65
  callback.call(file)
@@ -0,0 +1,190 @@
1
+ require 'syslog'
2
+ require 'logger'
3
+
4
+ ##
5
+ # SyslogLogger is a Logger work-alike that logs via syslog instead of to a
6
+ # file. You can add SyslogLogger to your Rails production environment to
7
+ # aggregate logs between multiple machines.
8
+ #
9
+ # By default, SyslogLogger uses the program name 'rails', but this can be
10
+ # changed via the first argument to SyslogLogger.new.
11
+ #
12
+ # NOTE! You can only set the SyslogLogger program name when you initialize
13
+ # SyslogLogger for the first time. This is a limitation of the way
14
+ # SyslogLogger uses syslog (and in some ways, a limitation of the way
15
+ # syslog(3) works). Attempts to change SyslogLogger's program name after the
16
+ # first initialization will be ignored.
17
+ #
18
+ # = Sample usage with Rails
19
+ #
20
+ # == config/environment/production.rb
21
+ #
22
+ # Add the following lines:
23
+ #
24
+ # require 'syslog_logger'
25
+ # RAILS_DEFAULT_LOGGER = SyslogLogger.new
26
+ #
27
+ # == config/environment.rb
28
+ #
29
+ # In 0.10.0, change this line:
30
+ #
31
+ # RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
32
+ #
33
+ # to:
34
+ #
35
+ # RAILS_DEFAULT_LOGGER ||= Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
36
+ #
37
+ # Other versions of Rails should have a similar change.
38
+ #
39
+ # == BSD syslog setup
40
+ #
41
+ # === /etc/syslog.conf
42
+ #
43
+ # Add the following lines:
44
+ #
45
+ # !rails
46
+ # *.* /var/log/production.log
47
+ #
48
+ # Then touch /var/log/production.log and signal syslogd with a HUP
49
+ # (killall -HUP syslogd, on FreeBSD).
50
+ #
51
+ # === /etc/newsyslog.conf
52
+ #
53
+ # Add the following line:
54
+ #
55
+ # /var/log/production.log 640 7 * @T00 Z
56
+ #
57
+ # This creates a log file that is rotated every day at midnight, gzip'd, then
58
+ # kept for 7 days. Consult newsyslog.conf(5) for more details.
59
+ #
60
+ # == syslog-ng setup
61
+ #
62
+ # === syslog-ng.conf
63
+ #
64
+ # destination rails_log { file("/var/log/production.log"); };
65
+ # filter f_rails { program("rails.*"); };
66
+ # log { source(src); filter(f_rails); destination(rails_log); };
67
+ #
68
+ # == Starting
69
+ #
70
+ # Now restart your Rails app. Your production logs should now be showing up
71
+ # in /var/log/production.log. If you have mulitple machines, you can log them
72
+ # all to a central machine with remote syslog logging for analysis. Consult
73
+ # your syslogd(8) manpage for further details.
74
+
75
+ class SyslogLogger
76
+
77
+ ##
78
+ # The version of SyslogLogger you are using.
79
+
80
+ VERSION = '1.4.0'
81
+
82
+ ##
83
+ # Maps Logger warning types to syslog(3) warning types.
84
+
85
+ LOGGER_MAP = {
86
+ :unknown => :alert,
87
+ :fatal => :err,
88
+ :error => :warning,
89
+ :warn => :notice,
90
+ :info => :info,
91
+ :debug => :debug,
92
+ }
93
+
94
+ ##
95
+ # Maps Logger log levels to their values so we can silence.
96
+
97
+ LOGGER_LEVEL_MAP = {}
98
+
99
+ LOGGER_MAP.each_key do |key|
100
+ LOGGER_LEVEL_MAP[key] = Logger.const_get key.to_s.upcase
101
+ end
102
+
103
+ ##
104
+ # Maps Logger log level values to syslog log levels.
105
+
106
+ LEVEL_LOGGER_MAP = {}
107
+
108
+ LOGGER_LEVEL_MAP.invert.each do |level, severity|
109
+ LEVEL_LOGGER_MAP[level] = LOGGER_MAP[severity]
110
+ end
111
+
112
+ ##
113
+ # Builds a methods for level +meth+.
114
+
115
+ def self.make_methods(meth)
116
+ eval <<-EOM, nil, __FILE__, __LINE__ + 1
117
+ def #{meth}(message = nil)
118
+ return true if #{LOGGER_LEVEL_MAP[meth]} < @level
119
+ SYSLOG.#{LOGGER_MAP[meth]} clean(message || yield)
120
+ return true
121
+ end
122
+
123
+ def #{meth}?
124
+ @level <= Logger::#{meth.to_s.upcase}
125
+ end
126
+ EOM
127
+ end
128
+
129
+ LOGGER_MAP.each_key do |level|
130
+ make_methods level
131
+ end
132
+
133
+ ##
134
+ # Log level for Logger compatibility.
135
+
136
+ attr_accessor :level
137
+
138
+ ##
139
+ # Fills in variables for Logger compatibility. If this is the first
140
+ # instance of SyslogLogger, +program_name+ may be set to change the logged
141
+ # program name.
142
+ #
143
+ # Due to the way syslog works, only one program name may be chosen.
144
+
145
+ def initialize(program_name = 'rails')
146
+ @level = Logger::DEBUG
147
+
148
+ return if defined? SYSLOG
149
+ self.class.const_set :SYSLOG, Syslog.open(program_name)
150
+ end
151
+
152
+ ##
153
+ # Almost duplicates Logger#add. +progname+ is ignored.
154
+
155
+ def add(severity, message = nil, progname = nil, &block)
156
+ severity ||= Logger::UNKNOWN
157
+ return true if severity < @level
158
+ message = clean(message || block.call)
159
+ SYSLOG.send LEVEL_LOGGER_MAP[severity], clean(message)
160
+ return true
161
+ end
162
+
163
+ ##
164
+ # Allows messages of a particular log level to be ignored temporarily.
165
+ #
166
+ # Can you say "Broken Windows"?
167
+
168
+ def silence(temporary_level = Logger::ERROR)
169
+ old_logger_level = @level
170
+ @level = temporary_level
171
+ yield
172
+ ensure
173
+ @level = old_logger_level
174
+ end
175
+
176
+ private
177
+
178
+ ##
179
+ # Clean up messages so they're nice and pretty.
180
+
181
+ def clean(message)
182
+ message = message.to_s.dup
183
+ message.strip!
184
+ message.gsub!(/%/, '%%') # syslog(3) freaks on % (printf)
185
+ message.gsub!(/\e\[[^m]*m/, '') # remove useless ansi color codes
186
+ return message
187
+ end
188
+
189
+ end
190
+