Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Debugging bus error

git-svn-id: svn+ssh://rubyforge.org/var/svn/alogr/trunk@7 5d4fd1e0-7adf-40a7-adde-e9af6235188f
  • Loading branch information...
commit a83be59700e0047c390abb06646f985f44bd6ef4 1 parent 2f1b418
authored September 18, 2007
3  ext/aio_logger/aio_logger.c
@@ -14,6 +14,7 @@ static struct aiocb control_block;
14 14
 int aio_log(char * string, int length, char * file_name) {
15 15
   int file_descriptor;
16 16
   const struct aiocb *aio_control_block_list;
  17
+  printf("(%d,%s,%s)\n", length,string,file_name);
17 18
 
18 19
 	//printf("string %s, length: %d, file_name: %s\n", string, length, file_name);
19 20
 
@@ -72,8 +73,6 @@ static VALUE rb_cLogger;
72 73
 
73 74
 // Called when interpreter loads alogr
74 75
 void Init_aio_logger() {
75  
-  printf("\n() Init_alogr_ext\n");
76  
-  
77 76
   VALUE rb_mAlogR = rb_define_module("AlogR");
78 77
   VALUE rb_cLogger = rb_define_class_under(rb_mAlogR, "Logger", rb_cObject);
79 78
   
44  lib/alogr.rb
... ...
@@ -1,69 +1,73 @@
1 1
 require "aio_logger"
2 2
 
3 3
 module AlogR
  4
+  
4 5
   Levels = { :emergency => 0, :alert => 1, :critical => 2, :error => 3, :warning => 4, :notice => 5, :info => 6, :debug => 7 }
5 6
   
6 7
   class Logger
7 8
 
8 9
     class << self
9 10
       attr_accessor :default_log_level
  11
+      attr_accessor :log_interval
10 12
     end
11 13
 
12 14
     def initialize(options = {})
13  
-      puts "In Ruby initialize method"
14  
-      case options
15  
-      when String:
  15
+      
  16
+      if options.class ==  String
16 17
         options = {:log => options}
17  
-      when Hash: 
  18
+      elsif options.class == Hash
18 19
         options[:log] ||= "log/default.log"
19 20
       else
20 21
         raise "AlogR: Invalid configuration"
21 22
       end
22 23
 
23  
-      @log_interval = options[:log_interval] || 0.01
24  
-
  24
+      log_interval      = options[:log_interval]      || 0.01
25 25
       default_log_level = options[:default_log_level] || :info
26 26
 
27 27
       AlogR::Levels.keys.each do | key |
28 28
         file_name = options[key] || options[:log]
29  
-        $alogr_log_files[AlogR::Levels[key]] = file_name
  29
+        $alogr_log_files[AlogR::Levels[key]] = file_name.freeze
30 30
         system("mkdir -p #{File.dirname(file_name)} ; touch #{file_name}")
31 31
       end
32  
-
  32
+      
  33
+      Object.logger = self # Default logger
  34
+      
33 35
       Thread.abort_on_exception = true
34 36
       Thread.new do
35 37
         loop do
36  
-          sleep( @log_interval )
  38
+          sleep( log_interval )
37 39
           flush_log_buffer
38 40
         end
39 41
         Thread.exit
40 42
       end
41  
-    end
42 43
 
  44
+      self
  45
+    end
  46
+    
43 47
     def log(string, level = default_log_level)
44 48
       $alogr_buffer << [level, string]
45 49
     end
46  
-
47  
-    def method_missing(meth, *options)
48  
-      puts "method: #{meth.inspect}, options: #{options.inspect}"
49  
-      if AlogR::Levels.include?( meth )
50  
-        log(meth, options.first)
  50
+    
  51
+    def method_missing( method, *options )
  52
+      if AlogR::Levels.include?( method )
  53
+        log( method, options.first )
51 54
       else
52  
-        super.method_missing(meth, *options)
  55
+        super.method_missing( method, *options )
53 56
       end
54 57
     end
55 58
 
56 59
   end
57 60
 end
58 61
 
59  
-require "alogr/version"
60  
-
61 62
 class Object
  63
+  class << self
  64
+    attr_accessor :logger
  65
+  end
62 66
 
63 67
   def log(level = :info)
64 68
     if self.class == String
65  
-      if AlogR::Levels.has_key?(level)
66  
-        $logger.log(self, AlogR::Levels[level])
  69
+      unless AlogR::Levels[level].nil?
  70
+        Object.logger.log(self, AlogR::Levels[level])
67 71
       else
68 72
         raise "Error: No such log level #{level}"
69 73
       end

0 notes on commit a83be59

Please sign in to comment.
Something went wrong with that request. Please try again.