logging_factory 0.0.1 → 0.0.2
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 +8 -8
 - data/README.md +2 -2
 - data/Rakefile +1 -2
 - data/lib/version.rb +1 -1
 - data/logging_factory.gemspec +2 -2
 - data/spec/log_stdout_spec.rb +30 -12
 - data/spec/spec_helper.rb +29 -12
 - metadata +10 -11
 - data/LICENSE.txt +0 -22
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,15 +1,15 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            !binary "U0hBMQ==":
         
     | 
| 
       3 
3 
     | 
    
         
             
              metadata.gz: !binary |-
         
     | 
| 
       4 
     | 
    
         
            -
                 
     | 
| 
      
 4 
     | 
    
         
            +
                OTVhM2Q5M2M2ZmU0NjI4OTliM2RjNjQxMWM2YzMyZDQyMDFhOGQ2Mg==
         
     | 
| 
       5 
5 
     | 
    
         
             
              data.tar.gz: !binary |-
         
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
      
 6 
     | 
    
         
            +
                ZmE1MjNhZjY3NGE1NWUwMTI1YTQ2ZjQyZGRlYjQzZDFmYWE3MTNkZA==
         
     | 
| 
       7 
7 
     | 
    
         
             
            SHA512:
         
     | 
| 
       8 
8 
     | 
    
         
             
              metadata.gz: !binary |-
         
     | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
      
 9 
     | 
    
         
            +
                OWU0YjI1MDI4ZWY1YzdlNGU0NGQxM2YyNDg2NDZiODVmMTUzZmRkZDFjYmM1
         
     | 
| 
      
 10 
     | 
    
         
            +
                ODVhZmRjNDZhZWMzZGM5NTk0MDU1YjU2NGQ3NjgyNzk4MjM4YmQzOWE5ZWVl
         
     | 
| 
      
 11 
     | 
    
         
            +
                NjJjZGMzOWYwODY1NGJlZTExMGQyNmMyYWM2OThlZjFjNjU3NmM=
         
     | 
| 
       12 
12 
     | 
    
         
             
              data.tar.gz: !binary |-
         
     | 
| 
       13 
     | 
    
         
            -
                 
     | 
| 
       14 
     | 
    
         
            -
                 
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
      
 13 
     | 
    
         
            +
                NTQ0NDMwOTQwNjEyZTY5YjIzOWIwODUwYWNjNjc0OGI1MmM0Y2FmMWQ4ODcy
         
     | 
| 
      
 14 
     | 
    
         
            +
                ODJkNGRhYTA1OTBmNjQwMmVkYjg2ZjJiZDI3NTI4YmNmNGEyNTI0YTg1ZGQ5
         
     | 
| 
      
 15 
     | 
    
         
            +
                Mjc0NWMwMmE2MTJlYTAwMGIzZjc5NmFiNzc3NmU3NzZkYjBkNTA=
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -54,11 +54,11 @@ This will create an factory that will use the `myproject.log` for logging. Other 
     | 
|
| 
       54 
54 
     | 
    
         | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
56 
     | 
    
         
             
            ## Examples
         
     | 
| 
       57 
     | 
    
         
            -
            See ` 
     | 
| 
      
 57 
     | 
    
         
            +
            See `spec/my_log.log` for an example (run tests to generate this file).
         
     | 
| 
       58 
58 
     | 
    
         | 
| 
       59 
59 
     | 
    
         
             
            Standard output:
         
     | 
| 
       60 
60 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
            <img src='https://github. 
     | 
| 
      
 61 
     | 
    
         
            +
            <img src='https://github.com/nayyara-samuel/logging-factory/blob/master/img/stdout.png?raw=true' height='130'>
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
            Log file:
         
     | 
| 
       64 
64 
     | 
    
         | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -1,2 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
       2 
     | 
    
         
            -
            require 'opower/nexus/deploy_task'
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'bundler/gem_tasks'
         
     | 
    
        data/lib/version.rb
    CHANGED
    
    
    
        data/logging_factory.gemspec
    CHANGED
    
    | 
         @@ -16,6 +16,6 @@ Gem::Specification.new do |gem| 
     | 
|
| 
       16 
16 
     | 
    
         
             
              gem.test_files    = gem.files.grep(%r{^(spec|spec|features)/})
         
     | 
| 
       17 
17 
     | 
    
         
             
              gem.require_paths = ["lib"]
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
              gem.add_dependency 'logging'
         
     | 
| 
       20 
     | 
    
         
            -
              gem.add_dependency 'preconditions'
         
     | 
| 
      
 19 
     | 
    
         
            +
              gem.add_dependency 'logging', '~> 1.8.1'
         
     | 
| 
      
 20 
     | 
    
         
            +
              gem.add_dependency 'preconditions', '~> 0.3.0'
         
     | 
| 
       21 
21 
     | 
    
         
             
            end
         
     | 
    
        data/spec/log_stdout_spec.rb
    CHANGED
    
    | 
         @@ -1,20 +1,38 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
       3 
2 
     | 
    
         | 
| 
       4 
3 
     | 
    
         
             
            describe LoggingFactory::Logger do
         
     | 
| 
       5 
4 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
               
     | 
| 
       7 
     | 
    
         
            -
              let(:debug_message) { 'This is a debug message' }
         
     | 
| 
       8 
     | 
    
         
            -
              let(:info_message) { 'This is an info message' }
         
     | 
| 
       9 
     | 
    
         
            -
              let(:warn_message) { 'This is a warn message' }
         
     | 
| 
       10 
     | 
    
         
            -
              let(:error_message) { 'This is an error message' }
         
     | 
| 
       11 
     | 
    
         
            -
              let(:fatal_message) { 'This is a fatal message' }
         
     | 
| 
      
 5 
     | 
    
         
            +
              context 'log to file' do
         
     | 
| 
       12 
6 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                 
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
                let(:file_accessor) { FileAccessor.new(:spec) }
         
     | 
| 
      
 8 
     | 
    
         
            +
                let(:log_file) { 'my_log.log' }
         
     | 
| 
      
 9 
     | 
    
         
            +
                let(:log) { LoggingFactory::DEFAULT_FACTORY.log('LogExample', output: file_accessor['my_log.log']) }
         
     | 
| 
      
 10 
     | 
    
         
            +
                let(:debug_message) { 'This is a debug message' }
         
     | 
| 
      
 11 
     | 
    
         
            +
                let(:info_message) { 'This is an info message' }
         
     | 
| 
      
 12 
     | 
    
         
            +
                let(:warn_message) { 'This is a warn message' }
         
     | 
| 
      
 13 
     | 
    
         
            +
                let(:error_message) { 'This is an error message' }
         
     | 
| 
      
 14 
     | 
    
         
            +
                let(:fatal_message) { 'This is a fatal message' }
         
     | 
| 
      
 15 
     | 
    
         
            +
                let(:time_regex) { /\[\d{4}(\-\d{2}){2} \d{2}(\:\d{2}){2}\]/ }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                before do
         
     | 
| 
      
 18 
     | 
    
         
            +
                  log.debug(debug_message)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  log.info(info_message)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  log.warn(warn_message)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  log.error(error_message)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  log.fatal(fatal_message)
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
       17 
24 
     | 
    
         | 
| 
      
 25 
     | 
    
         
            +
                it 'logs messages correctly with log levels' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                  log_content = file_accessor.read('my_log.log')
         
     | 
| 
      
 27 
     | 
    
         
            +
                  log_lines = log_content.split("\n")
         
     | 
| 
      
 28 
     | 
    
         
            +
                  expect(log_lines[0]).to match(/^#{time_regex} DEBUG \[LogExample\] #{debug_message}$/)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  expect(log_lines[1]).to match(/^#{time_regex} INFO  \[LogExample\] #{info_message}$/)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  expect(log_lines[2]).to match(/^#{time_regex} WARN  \[LogExample\] #{warn_message}$/)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  expect(log_lines[3]).to match(/^#{time_regex} ERROR \[LogExample\] #{error_message}$/)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  expect(log_lines[4]).to match(/^#{time_regex} FATAL \[LogExample\] #{fatal_message}$/)
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
       18 
36 
     | 
    
         
             
            end
         
     | 
| 
       19 
37 
     | 
    
         | 
| 
       20 
38 
     | 
    
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -1,20 +1,37 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'rspec'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rspec/mocks'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative '../lib/logging_factory'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
      
 5 
     | 
    
         
            +
            # A class to allow easy reference of files with a given base path
         
     | 
| 
      
 6 
     | 
    
         
            +
            class FileAccessor
         
     | 
| 
      
 7 
     | 
    
         
            +
              attr_accessor :base_path
         
     | 
| 
       3 
8 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            #  
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
              # Options should have a list of parts which will be appended together to give the base path
         
     | 
| 
      
 10 
     | 
    
         
            +
              def initialize(*options)
         
     | 
| 
      
 11 
     | 
    
         
            +
                @base_path = File.join(options.map {|f| f.to_s})
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              # Access specific file in the base path
         
     | 
| 
      
 15 
     | 
    
         
            +
              def [](file_name)
         
     | 
| 
      
 16 
     | 
    
         
            +
                File.join(@base_path, file_name)
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              # Read the given file
         
     | 
| 
      
 20 
     | 
    
         
            +
              def read(file_name)
         
     | 
| 
      
 21 
     | 
    
         
            +
                File.read(File.join(@base_path, file_name))
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              # Delete all files in the directory
         
     | 
| 
      
 25 
     | 
    
         
            +
              def delete_files(pattern='*.log')
         
     | 
| 
      
 26 
     | 
    
         
            +
                FileUtils.rm_rf Dir.glob(File.join(base_path, pattern))
         
     | 
| 
       15 
27 
     | 
    
         
             
              end
         
     | 
| 
       16 
28 
     | 
    
         
             
            end
         
     | 
| 
       17 
29 
     | 
    
         | 
| 
       18 
30 
     | 
    
         
             
            RSpec.configure do |config|
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              config.before(:suite) do
         
     | 
| 
      
 33 
     | 
    
         
            +
                file_accessor = FileAccessor.new(:spec)
         
     | 
| 
      
 34 
     | 
    
         
            +
                file_accessor.delete_files
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
       20 
37 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,43 +1,43 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: logging_factory
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Nayyara Samuel
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2014-06- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-06-18 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: logging
         
     | 
| 
       15 
15 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
     | 
    
         
            -
                - -  
     | 
| 
      
 17 
     | 
    
         
            +
                - - ~>
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
     | 
    
         
            -
                    version:  
     | 
| 
      
 19 
     | 
    
         
            +
                    version: 1.8.1
         
     | 
| 
       20 
20 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       21 
21 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
22 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
23 
     | 
    
         
             
                requirements:
         
     | 
| 
       24 
     | 
    
         
            -
                - -  
     | 
| 
      
 24 
     | 
    
         
            +
                - - ~>
         
     | 
| 
       25 
25 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
     | 
    
         
            -
                    version:  
     | 
| 
      
 26 
     | 
    
         
            +
                    version: 1.8.1
         
     | 
| 
       27 
27 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       28 
28 
     | 
    
         
             
              name: preconditions
         
     | 
| 
       29 
29 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       30 
30 
     | 
    
         
             
                requirements:
         
     | 
| 
       31 
     | 
    
         
            -
                - -  
     | 
| 
      
 31 
     | 
    
         
            +
                - - ~>
         
     | 
| 
       32 
32 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       33 
     | 
    
         
            -
                    version:  
     | 
| 
      
 33 
     | 
    
         
            +
                    version: 0.3.0
         
     | 
| 
       34 
34 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       35 
35 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       36 
36 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       37 
37 
     | 
    
         
             
                requirements:
         
     | 
| 
       38 
     | 
    
         
            -
                - -  
     | 
| 
      
 38 
     | 
    
         
            +
                - - ~>
         
     | 
| 
       39 
39 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       40 
     | 
    
         
            -
                    version:  
     | 
| 
      
 40 
     | 
    
         
            +
                    version: 0.3.0
         
     | 
| 
       41 
41 
     | 
    
         
             
            description: A wrapper around logging gem
         
     | 
| 
       42 
42 
     | 
    
         
             
            email:
         
     | 
| 
       43 
43 
     | 
    
         
             
            - nayyara.samuel@opower.com
         
     | 
| 
         @@ -47,7 +47,6 @@ extra_rdoc_files: [] 
     | 
|
| 
       47 
47 
     | 
    
         
             
            files:
         
     | 
| 
       48 
48 
     | 
    
         
             
            - .gitignore
         
     | 
| 
       49 
49 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       50 
     | 
    
         
            -
            - LICENSE.txt
         
     | 
| 
       51 
50 
     | 
    
         
             
            - README.md
         
     | 
| 
       52 
51 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       53 
52 
     | 
    
         
             
            - img/stdout.png
         
     | 
    
        data/LICENSE.txt
    DELETED
    
    | 
         @@ -1,22 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            Copyright (c) 2013 Nayyara Samuel
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            MIT License
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
       6 
     | 
    
         
            -
            a copy of this software and associated documentation files (the
         
     | 
| 
       7 
     | 
    
         
            -
            "Software"), to deal in the Software without restriction, including
         
     | 
| 
       8 
     | 
    
         
            -
            without limitation the rights to use, copy, modify, merge, publish,
         
     | 
| 
       9 
     | 
    
         
            -
            distribute, sublicense, and/or sell copies of the Software, and to
         
     | 
| 
       10 
     | 
    
         
            -
            permit persons to whom the Software is furnished to do so, subject to
         
     | 
| 
       11 
     | 
    
         
            -
            the following conditions:
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
            The above copyright notice and this permission notice shall be
         
     | 
| 
       14 
     | 
    
         
            -
            included in all copies or substantial portions of the Software.
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         
     | 
| 
       17 
     | 
    
         
            -
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
       18 
     | 
    
         
            -
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         
     | 
| 
       19 
     | 
    
         
            -
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
       20 
     | 
    
         
            -
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
       21 
     | 
    
         
            -
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
       22 
     | 
    
         
            -
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     |