micrologger 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a7f36acc51fecb2796f86400c5358e6325ffe487
4
+ data.tar.gz: f775d5803b48e4ca0a0f2beb36d34b8ca4ddda9e
5
+ SHA512:
6
+ metadata.gz: 4fbbc44f38a544ceeb9e886add442c35ec406d89963454c3afc8f341243c0ef2b2051adf3b5ebab2bedf21e3bd07801acd7991d063be672db58809e6e609e727
7
+ data.tar.gz: a69ea0864cfb03173eb6dcbfe489272be3be7aa4fca2c5c4e98757af7194ce1c8f702b88616f3ab29c46e6104efe9c152601c195d64600e6e6b60ad284db2b76
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ script: ruby spec/*
4
+
5
+ rvm:
6
+ - 2.2.1
7
+ - 2.2.0
8
+ - 2.1.5
9
+ - 2.1.4
10
+ - 2.1.3
11
+ - 2.1.2
12
+ - 2.1.1
13
+ - 2.1.0
14
+ - 2.0.0
15
+ - rbx-2
16
+ - jruby-head
17
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ### 0.1.0
2
+
3
+ * Release
4
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ microevent (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ microevent!
data/MIT-LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Jan Lelis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # MicroLogger [![[travis]](https://travis-ci.org/janlelis/micrologger.png)](https://travis-ci.org/janlelis/micrologger)
2
+
3
+ A minimal logger based on [MicroEvent](https://github.com/janlelis/microevent.rb).
4
+
5
+ ## Setup
6
+
7
+ Add to your `Gemfile`
8
+
9
+ ```ruby
10
+ gem 'micrologger'
11
+ ```
12
+
13
+ ## How to Use It
14
+
15
+ A new logger has to be configured what should be done on log events using handler procs. There are two default handlers for logging to STDOUT/STDERR included:
16
+
17
+ ```ruby
18
+ $logger = MicroLogger.new
19
+ $logger.register :info, :stdout
20
+ $logger.register :fatal, :stderr
21
+
22
+ $logger.log "debug" # STDOUT: debug
23
+ $logger.log "error", :fatal # STDERR: error
24
+ ```
25
+
26
+ For any andvanced or customized behaviour, you will need to register your own blocks/procs:
27
+
28
+
29
+ ### Example: Log to File
30
+
31
+ ```ruby
32
+ $logger = MicroLogger.new
33
+ $logger.register :warn, :stderr
34
+ $logger.register :warn do |message, meta|
35
+ File.open("logfile.#{meta[:level]}.txt", "a"){ |f| f.puts "#{meta[:time]} | #{message}" }
36
+ end
37
+
38
+ $logger.log "hey", :warn # Will write to STDERR and logfile.warn.txt
39
+ ```
40
+
41
+ Other ideas you could do: Send data to a remote endpoint, send emails, send to analytics...
42
+
43
+
44
+ ## J-_-L
45
+
46
+ Copyright (c) 2015 [Jan Lelis](http://janlelis.com). See MIT-LICENSE for details.
Binary file
@@ -0,0 +1,50 @@
1
+ require 'microevent'
2
+ require 'paint'
3
+
4
+ class MicroLogger
5
+ include MicroEvent
6
+
7
+ VERSION = "0.1.0".freeze
8
+ DEFAULT_HANDLERS = {
9
+ stdout: lambda{ |message, extra|
10
+ STDOUT.puts formatter(message, extra)
11
+ },
12
+ stderr: lambda{ |message, extra|
13
+ STDERR.puts Paint[formatter(message, extra), :red]
14
+ },
15
+ }
16
+
17
+ def log(message, level = :info, extra = {})
18
+ trigger level, message, {level: level, time: Time.now}.merge(extra)
19
+ end
20
+
21
+ def register(level = :info, handler = nil, &block)
22
+ bind level, &resolve_handler(handler || block)
23
+ end
24
+
25
+ def unregister(level = :info, handler = nil, &block)
26
+ if handler || block
27
+ unbind level, &resolve_handler(handler || block)
28
+ else
29
+ unbind level
30
+ end
31
+ end
32
+
33
+
34
+ private
35
+
36
+ def resolve_handler(handler)
37
+ if handler.is_a?(Proc)
38
+ handler
39
+ elsif default_handler = DEFAULT_HANDLERS[handler]
40
+ default_handler
41
+ else
42
+ raise ArgumentError, "no suitable handler found for #{handler.inspect}"
43
+ end
44
+ end
45
+
46
+ def formatter(message, extra)
47
+ "#{extra[:time].strftime('%Y-%m-%d %H:%M')} | #{extra[:level]} | #{message}"
48
+ end
49
+ end
50
+
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/micrologger', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "micrologger"
7
+ gem.version = MicroLogger::VERSION
8
+ gem.summary = 'A minimal logger.'
9
+ gem.description = 'A minimal logger based on MicroEvent.rb'
10
+ gem.license = "MIT"
11
+ gem.authors = ["Jan Lelis"]
12
+ gem.email = "mail@janlelis.de"
13
+ gem.homepage = "https://github.com/janlelis/micrologger"
14
+
15
+ gem.files = Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'microevent', '~> 1.0'
21
+ gem.add_dependency 'paint', '~> 0.9'
22
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: micrologger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jan Lelis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: microevent
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: paint
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ description: A minimal logger based on MicroEvent.rb
42
+ email: mail@janlelis.de
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - ".travis.yml"
49
+ - CHANGELOG.md
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - MIT-LICENSE.txt
53
+ - README.md
54
+ - lib/.micrologger.rb.swp
55
+ - lib/micrologger.rb
56
+ - micrologger.gemspec
57
+ homepage: https://github.com/janlelis/micrologger
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.5
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: A minimal logger.
81
+ test_files: []
82
+ has_rdoc: