Permalink
Browse files

Debugging bus error

git-svn-id: svn+ssh://rubyforge.org/var/svn/alogr/trunk@7 5d4fd1e0-7adf-40a7-adde-e9af6235188f
  • Loading branch information...
1 parent 2f1b418 commit a83be59700e0047c390abb06646f985f44bd6ef4 wayneeseguin committed Sep 18, 2007
Showing with 25 additions and 22 deletions.
  1. +1 −2 ext/aio_logger/aio_logger.c
  2. +24 −20 lib/alogr.rb
View
3 ext/aio_logger/aio_logger.c
@@ -14,6 +14,7 @@ static struct aiocb control_block;
int aio_log(char * string, int length, char * file_name) {
int file_descriptor;
const struct aiocb *aio_control_block_list;
+ printf("(%d,%s,%s)\n", length,string,file_name);
//printf("string %s, length: %d, file_name: %s\n", string, length, file_name);
@@ -72,8 +73,6 @@ static VALUE rb_cLogger;
// Called when interpreter loads alogr
void Init_aio_logger() {
- printf("\n() Init_alogr_ext\n");
-
VALUE rb_mAlogR = rb_define_module("AlogR");
VALUE rb_cLogger = rb_define_class_under(rb_mAlogR, "Logger", rb_cObject);
View
44 lib/alogr.rb
@@ -1,69 +1,73 @@
require "aio_logger"
module AlogR
+
Levels = { :emergency => 0, :alert => 1, :critical => 2, :error => 3, :warning => 4, :notice => 5, :info => 6, :debug => 7 }
class Logger
class << self
attr_accessor :default_log_level
+ attr_accessor :log_interval
end
def initialize(options = {})
- puts "In Ruby initialize method"
- case options
- when String:
+
+ if options.class == String
options = {:log => options}
- when Hash:
+ elsif options.class == Hash
options[:log] ||= "log/default.log"
else
raise "AlogR: Invalid configuration"
end
- @log_interval = options[:log_interval] || 0.01
-
+ log_interval = options[:log_interval] || 0.01
default_log_level = options[:default_log_level] || :info
AlogR::Levels.keys.each do | key |
file_name = options[key] || options[:log]
- $alogr_log_files[AlogR::Levels[key]] = file_name
+ $alogr_log_files[AlogR::Levels[key]] = file_name.freeze
system("mkdir -p #{File.dirname(file_name)} ; touch #{file_name}")
end
-
+
+ Object.logger = self # Default logger
+
Thread.abort_on_exception = true
Thread.new do
loop do
- sleep( @log_interval )
+ sleep( log_interval )
flush_log_buffer
end
Thread.exit
end
- end
+ self
+ end
+
def log(string, level = default_log_level)
$alogr_buffer << [level, string]
end
-
- def method_missing(meth, *options)
- puts "method: #{meth.inspect}, options: #{options.inspect}"
- if AlogR::Levels.include?( meth )
- log(meth, options.first)
+
+ def method_missing( method, *options )
+ if AlogR::Levels.include?( method )
+ log( method, options.first )
else
- super.method_missing(meth, *options)
+ super.method_missing( method, *options )
end
end
end
end
-require "alogr/version"
-
class Object
+ class << self
+ attr_accessor :logger
+ end
def log(level = :info)
if self.class == String
- if AlogR::Levels.has_key?(level)
- $logger.log(self, AlogR::Levels[level])
+ unless AlogR::Levels[level].nil?
+ Object.logger.log(self, AlogR::Levels[level])
else
raise "Error: No such log level #{level}"
end

0 comments on commit a83be59

Please sign in to comment.