lumber 1.0.2 → 1.0.3
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.
- checksums.yaml +4 -4
 - data/CHANGELOG +5 -0
 - data/lib/lumber/json_formatter.rb +4 -2
 - data/lib/lumber/version.rb +1 -1
 - data/spec/json_formatter_spec.rb +35 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 46565c6578428e0fd2b235b3c342958c1bdd2ca2
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: f6d4b6262295e7e8f7eb9ffac68ae180ae9329c0
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 252efef13b42f54c839d9b9b20908df2e6902a9b657c9452283e9dde81600ce63ebb95f9d9f2878b65eead7e2d6da8279761e00bdfb9a63a7ffba5117dec48f8
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3110b279693bea1ad2a1b522aff0c9c9ab6c57090e1a1c6b3f44adda84748af326f44a84f994144d9e296c5d05888bd621d8feed5062f5cc8108e11b4d848629
         
     | 
    
        data/CHANGELOG
    CHANGED
    
    
| 
         @@ -18,12 +18,14 @@ module Lumber 
     | 
|
| 
       18 
18 
     | 
    
         
             
                      @fields[k.to_s] = v
         
     | 
| 
       19 
19 
     | 
    
         
             
                    end
         
     | 
| 
       20 
20 
     | 
    
         
             
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  @date_pattern = hash['date_pattern'] || '%H:%M:%S'
         
     | 
| 
       21 
23 
     | 
    
         
             
                end
         
     | 
| 
       22 
24 
     | 
    
         | 
| 
       23 
25 
     | 
    
         
             
                def format(logevent)
         
     | 
| 
       24 
26 
     | 
    
         
             
                  data = @fields.dup
         
     | 
| 
       25 
27 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                  assign_mapped_key(data, :timestamp, Time.now. 
     | 
| 
      
 28 
     | 
    
         
            +
                  assign_mapped_key(data, :timestamp, Time.now.strftime(@date_pattern))
         
     | 
| 
       27 
29 
     | 
    
         
             
                  assign_mapped_key(data, :logger, logevent.fullname)
         
     | 
| 
       28 
30 
     | 
    
         
             
                  assign_mapped_key(data, :level, Log4r::LNAMES[logevent.level].downcase)
         
     | 
| 
       29 
31 
     | 
    
         | 
| 
         @@ -82,7 +84,7 @@ module Lumber 
     | 
|
| 
       82 
84 
     | 
    
         
             
                    assign_mapped_key(data, :mdc, value)
         
     | 
| 
       83 
85 
     | 
    
         
             
                  end
         
     | 
| 
       84 
86 
     | 
    
         | 
| 
       85 
     | 
    
         
            -
                  data.to_json
         
     | 
| 
      
 87 
     | 
    
         
            +
                  "#{data.to_json}\n"
         
     | 
| 
       86 
88 
     | 
    
         
             
                end
         
     | 
| 
       87 
89 
     | 
    
         | 
| 
       88 
90 
     | 
    
         
             
                private
         
     | 
    
        data/lib/lumber/version.rb
    CHANGED
    
    
    
        data/spec/json_formatter_spec.rb
    CHANGED
    
    | 
         @@ -74,7 +74,6 @@ describe Lumber::JsonFormatter do 
     | 
|
| 
       74 
74 
     | 
    
         
             
                  EOF
         
     | 
| 
       75 
75 
     | 
    
         
             
                  yml.should include('#{1+1}')
         
     | 
| 
       76 
76 
     | 
    
         
             
                  cfg = Log4r::YamlConfigurator
         
     | 
| 
       77 
     | 
    
         
            -
                  cfg['hostname'] = 'foo'
         
     | 
| 
       78 
77 
     | 
    
         
             
                  cfg.load_yaml_string(yml)
         
     | 
| 
       79 
78 
     | 
    
         
             
                  outputter = Log4r::Outputter['stdout']
         
     | 
| 
       80 
79 
     | 
    
         
             
                  outputter.formatter.should_not be_nil
         
     | 
| 
         @@ -82,6 +81,30 @@ describe Lumber::JsonFormatter do 
     | 
|
| 
       82 
81 
     | 
    
         
             
                  outputter.formatter.instance_variable_get(:@fields).should eq({'version' => 1, 'dynamic' => '2'})
         
     | 
| 
       83 
82 
     | 
    
         
             
                end
         
     | 
| 
       84 
83 
     | 
    
         | 
| 
      
 84 
     | 
    
         
            +
                it "can receive date_pattern configuration" do
         
     | 
| 
      
 85 
     | 
    
         
            +
                  yml = <<-'EOF'
         
     | 
| 
      
 86 
     | 
    
         
            +
                    log4r_config:
         
     | 
| 
      
 87 
     | 
    
         
            +
                      pre_config:
         
     | 
| 
      
 88 
     | 
    
         
            +
                        root:
         
     | 
| 
      
 89 
     | 
    
         
            +
                          level: 'DEBUG'
         
     | 
| 
      
 90 
     | 
    
         
            +
                      loggers:
         
     | 
| 
      
 91 
     | 
    
         
            +
                        - name: "mylogger"
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                      outputters:
         
     | 
| 
      
 94 
     | 
    
         
            +
                        - type: StdoutOutputter
         
     | 
| 
      
 95 
     | 
    
         
            +
                          name: stdout
         
     | 
| 
      
 96 
     | 
    
         
            +
                          formatter:
         
     | 
| 
      
 97 
     | 
    
         
            +
                            type: JsonFormatter
         
     | 
| 
      
 98 
     | 
    
         
            +
                            date_pattern: "%M"
         
     | 
| 
      
 99 
     | 
    
         
            +
                  EOF
         
     | 
| 
      
 100 
     | 
    
         
            +
                  cfg = Log4r::YamlConfigurator
         
     | 
| 
      
 101 
     | 
    
         
            +
                  cfg.load_yaml_string(yml)
         
     | 
| 
      
 102 
     | 
    
         
            +
                  outputter = Log4r::Outputter['stdout']
         
     | 
| 
      
 103 
     | 
    
         
            +
                  outputter.formatter.should_not be_nil
         
     | 
| 
      
 104 
     | 
    
         
            +
                  outputter.formatter.should be_a_kind_of Lumber::JsonFormatter
         
     | 
| 
      
 105 
     | 
    
         
            +
                  outputter.formatter.instance_variable_get(:@date_pattern).should == "%M"
         
     | 
| 
      
 106 
     | 
    
         
            +
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
       85 
108 
     | 
    
         
             
              end
         
     | 
| 
       86 
109 
     | 
    
         | 
| 
       87 
110 
     | 
    
         
             
              context "#assign_mapped_key" do
         
     | 
| 
         @@ -167,6 +190,17 @@ describe Lumber::JsonFormatter do 
     | 
|
| 
       167 
190 
     | 
    
         
             
                  json['version'].should == 1
         
     | 
| 
       168 
191 
     | 
    
         
             
                end
         
     | 
| 
       169 
192 
     | 
    
         | 
| 
      
 193 
     | 
    
         
            +
                it "logs as json with date format" do
         
     | 
| 
      
 194 
     | 
    
         
            +
                  now = Time.now
         
     | 
| 
      
 195 
     | 
    
         
            +
                  Time.stub(:now).and_return(now)
         
     | 
| 
      
 196 
     | 
    
         
            +
                  @formatter = Lumber::JsonFormatter.new('date_pattern' => "%s")
         
     | 
| 
      
 197 
     | 
    
         
            +
                  @outputter.formatter = @formatter
         
     | 
| 
      
 198 
     | 
    
         
            +
             
     | 
| 
      
 199 
     | 
    
         
            +
                  @logger.info("howdy")
         
     | 
| 
      
 200 
     | 
    
         
            +
                  json = JSON.parse(@sio.string)
         
     | 
| 
      
 201 
     | 
    
         
            +
                  json['timestamp'].should == now.to_i.to_s
         
     | 
| 
      
 202 
     | 
    
         
            +
                end
         
     | 
| 
      
 203 
     | 
    
         
            +
             
     | 
| 
       170 
204 
     | 
    
         
             
                it "logs exception as json" do
         
     | 
| 
       171 
205 
     | 
    
         
             
                  ex = StandardError.new("mybad")
         
     | 
| 
       172 
206 
     | 
    
         
             
                  raise ex rescue nil
         
     |