mimi-logger 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 69b1d63b51fc0bc2a4b205a10c71dda4c33674ba
4
+ data.tar.gz: d3809569ef0c86aba1368243cbbcefec5b1b8c62
5
+ SHA512:
6
+ metadata.gz: 869c7890e0923162a8fb7d20a7910c6e0d488a5fb7dc6b7b5a38e9c8600146f36f4b6269253ffcfdbd81ecb0c986c218e975b56901c67c8af95e878a28e0e70c
7
+ data.tar.gz: a0703736c7f5764b70073f750426be8793598137495613cdc844feae89835e264b7ef29685ff0547321eb6f0ca6b4e31566a2ecb774b0630c17c29a63be7c733
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at alex@kukushk.in. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'mimi-core', path: '/mimi-core'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alex Kukushkin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # mimi-logger
2
+
3
+ A pre-configured logger for microservice applications.
4
+
5
+ [in development]
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mimi-logger'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mimi-logger
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'mimi/logger'
27
+
28
+ logger = Mimi::Logger.new
29
+
30
+ logger.info 'I am a banana!' # outputs "I, I am a banana!" to STDOUT
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kukushkin/mimi-logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'mimi/logger'
5
+
6
+ require 'pry'
7
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,102 @@
1
+ require 'forwardable'
2
+ require 'logger'
3
+ require 'mimi/core'
4
+
5
+ module Mimi
6
+ #
7
+ # Mimi::Logger is a preconfigured logger which outputs log messages to STDOUT.
8
+ #
9
+ class Logger
10
+ extend Forwardable
11
+ include Mimi::Core::Module
12
+
13
+ attr_reader :logger_instance
14
+ delegate [
15
+ :debug, :info, :warn, :error, :fatal, :unknown,
16
+ :debug?, :info?, :warn?, :error?, :fatal?,
17
+ :<<, :add, :log
18
+ ] => :logger_instance
19
+
20
+ default_options(
21
+ level: 'info'
22
+ )
23
+
24
+ # Creates a new Logger instance
25
+ #
26
+ # @param [IO] io An IO object to output log messages to, defaults to STDOUT
27
+ # @param [Hash] opts
28
+ # @option [String,Symbol,Integer] :level Initial log level, e.g. 'info'
29
+ #
30
+ # @example
31
+ # logger = Mimi::Logger.new
32
+ # logger.info 'I am a banana!' # outputs "I, I am a banana!" to the STDOUT
33
+ #
34
+ # logger = Mimi::Logger.new(level: :debug)
35
+ # logger.debug 'blabla' # => "D, blabla"
36
+ #
37
+ def initialize(*args)
38
+ io = args.shift if args.first.is_a?(IO)
39
+ io ||= STDOUT
40
+ opts = args.shift if args.first.is_a?(Hash)
41
+ opts ||= {}
42
+ raise ArgumentError, '(io, opts) are expected as parameters' unless args.empty?
43
+
44
+ opts = self.class.module_options.deep_merge(opts)
45
+ @logger_instance = ::Logger.new(io)
46
+ @logger_instance.level = self.class.level_from_any(opts[:level])
47
+ io.sync if io.respond_to?(:sync)
48
+ @logger_instance.formatter = self.class.formatter
49
+ end
50
+
51
+ # Returns the current log level
52
+ #
53
+ # @return [Fixnum]
54
+ #
55
+ def level
56
+ logger_instance.level
57
+ end
58
+
59
+ # Sets the log level.
60
+ # Allows setting the log level from a String or a Symbol, in addition to the standard ::Logger::INFO etc.
61
+ #
62
+ # @param [String,Symbol,Fixnum] value
63
+ #
64
+ def level=(value)
65
+ logger_instance.level = self.class.level_from_any(value)
66
+ end
67
+
68
+ # Returns the log level inferred from value
69
+ #
70
+ # @param value [String,Symbol,Fixnum]
71
+ #
72
+ def self.level_from_any(value)
73
+ return value if value.is_a?(Fixnum)
74
+ case value.to_s.downcase.to_sym
75
+ when :debug
76
+ ::Logger::DEBUG
77
+ when :info
78
+ ::Logger::INFO
79
+ when :warn
80
+ ::Logger::WARN
81
+ when :error
82
+ ::Logger::ERROR
83
+ when :fatal
84
+ ::Logger::FATAL
85
+ when :unknown
86
+ ::Logger::UNKNOWN
87
+ else
88
+ raise ArgumentError, "Invalid value for the log level: '#{value}'"
89
+ end
90
+ end
91
+
92
+ def self.formatter
93
+ proc do |severity, _datetime, _progname, message|
94
+ "#{severity.to_s[0]}, #{message}\n"
95
+ end
96
+ end
97
+ end # class Logger
98
+ end # module Mimi
99
+
100
+ require_relative 'logger/version'
101
+ require_relative 'logger/null_logger'
102
+ require_relative 'logger/instance'
@@ -0,0 +1,27 @@
1
+ module Mimi
2
+ class Logger
3
+ #
4
+ # A mixin to include into your classes and modules.
5
+ # Makes methods #logger and .logger available, referring to one global instance:
6
+ #
7
+ # class MyApp
8
+ # include Mimi::Logger::Instance
9
+ #
10
+ # def something
11
+ # logger.info 'Doing something...'
12
+ # end
13
+ # end
14
+ #
15
+ module Instance
16
+ def self.included(base)
17
+ # puts "Module #{self} included into #{base}"
18
+ base.send(:define_method, :logger) { Mimi::Logger::Instance.instance }
19
+ base.send(:define_singleton_method, :logger) { Mimi::Logger::Instance.instance }
20
+ end
21
+
22
+ def self.instance
23
+ @logger ||= Mimi::Logger.new
24
+ end
25
+ end # module Instance
26
+ end # class Logger
27
+ end # module Mimi
@@ -0,0 +1,27 @@
1
+ module Mimi
2
+ class Logger
3
+ class NullLogger
4
+ def initialize(*)
5
+ end
6
+
7
+ def debug(*)
8
+ end
9
+
10
+ def info(*)
11
+ end
12
+
13
+ def warn(*)
14
+ end
15
+
16
+ def error(*)
17
+ end
18
+
19
+ def fatal(*)
20
+ end
21
+
22
+ def level; end
23
+
24
+ def level=(*); end
25
+ end # class NullLogger
26
+ end # class Logger
27
+ end # module Mimi
@@ -0,0 +1,5 @@
1
+ module Mimi
2
+ class Logger
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mimi/logger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mimi-logger'
8
+ spec.version = Mimi::Logger::VERSION
9
+ spec.authors = ['Alex Kukushkin']
10
+ spec.email = ['alex@kukushk.in']
11
+
12
+ spec.summary = 'A pre-configured logger for microservice applications'
13
+ spec.description = 'A pre-configured logger for microservice applications'
14
+ spec.homepage = 'https://github.com/kukushkin/mimi-logger'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'mimi-core'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 1.11'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.0'
35
+ spec.add_development_dependency 'pry', '~> 0.10'
36
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mimi-logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Kukushkin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mimi-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ description: A pre-configured logger for microservice applications
84
+ email:
85
+ - alex@kukushk.in
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/mimi/logger.rb
101
+ - lib/mimi/logger/instance.rb
102
+ - lib/mimi/logger/null_logger.rb
103
+ - lib/mimi/logger/version.rb
104
+ - mimi-logger.gemspec
105
+ homepage: https://github.com/kukushkin/mimi-logger
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ allowed_push_host: https://rubygems.org
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.5.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: A pre-configured logger for microservice applications
130
+ test_files: []