console_logger 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +11 -0
- data/console_logger.gemspec +22 -0
- data/lib/console_logger.rb +27 -0
- data/test/test_console_logger.rb +48 -0
- data/test/test_helper.rb +4 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3c67f834edbe2abdbdedf7025554a1332e90fdce
|
4
|
+
data.tar.gz: b6812fb4d4e666da4dc8d8eee294fa34dc254d39
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aafb2b7f4aa38709f2da50c1b311f00756e033307c801d48f877619089b592fdd22c35f572cff8aa9ec9bbb10cd6c0991ec4eb27ece10897c4ac811f3919f8f7
|
7
|
+
data.tar.gz: 66405863d6dad1c994a3d507237542f79b43bb50fc47ddb81bd8725d3ee1a4ba653ceadf8e0e5ff128748baea27a5b0fbc1577a7a7cd559014ccbbfb0b1fd90f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Mike Williams
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# ConsoleLogger
|
2
|
+
|
3
|
+
Logging is great. But sometimes, you just want to write to STDOUT/STDERR.
|
4
|
+
|
5
|
+
ConsoleLogger provides a quick way to get a Logger optimised for console output.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Use it like this:
|
10
|
+
|
11
|
+
require 'console_logger'
|
12
|
+
|
13
|
+
logger = ConsoleLogger.new($stderr)
|
14
|
+
logger.info("something is about to happen")
|
15
|
+
# => INFO: something is about to happen
|
16
|
+
logger.warn("something went wrong!")
|
17
|
+
# => WARN: something went wrong!
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
* It's on GitHub; you know the drill.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
|
5
|
+
spec.name = "console_logger"
|
6
|
+
spec.version = "1.0.0"
|
7
|
+
|
8
|
+
spec.summary = %q{A Logger customised for console output.}
|
9
|
+
spec.license = "MIT"
|
10
|
+
|
11
|
+
spec.authors = ["Mike Williams"]
|
12
|
+
spec.email = ["mdub@dogbiscuit.org"]
|
13
|
+
spec.homepage = "https://github.com/mdub/console_logger"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.test_files = spec.files.grep(%r{^test/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "logger"
|
2
|
+
|
3
|
+
# Provides a Logger customised for console output.
|
4
|
+
#
|
5
|
+
module ConsoleLogger
|
6
|
+
|
7
|
+
# Returns a new Logger, customised for console output.
|
8
|
+
#
|
9
|
+
# dest - the IO stream to write to
|
10
|
+
# verbose - sets log-level to DEBUG, if true
|
11
|
+
#
|
12
|
+
def self.new(dest = $stderr, verbose = false)
|
13
|
+
::Logger.new(dest).tap do |logger|
|
14
|
+
logger.formatter = Formatter.new
|
15
|
+
logger.level = verbose ? ::Logger::DEBUG : ::Logger::INFO
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Formatter < ::Logger::Formatter
|
20
|
+
|
21
|
+
def call(severity, time, progname, msg)
|
22
|
+
"#{severity}: #{msg.strip}\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
require "console_logger"
|
4
|
+
require "stringio"
|
5
|
+
|
6
|
+
describe ConsoleLogger do
|
7
|
+
|
8
|
+
let(:output) { "" }
|
9
|
+
let(:output_stream) { StringIO.new(output) }
|
10
|
+
|
11
|
+
let(:logger) { ConsoleLogger.new(output_stream) }
|
12
|
+
|
13
|
+
%w(debug info warn error fatal).each do |level|
|
14
|
+
|
15
|
+
describe "##{level}" do
|
16
|
+
|
17
|
+
before do
|
18
|
+
logger.level = Logger::DEBUG
|
19
|
+
end
|
20
|
+
|
21
|
+
it "prepends #{level.upcase} to the message" do
|
22
|
+
logger.send(level, "message")
|
23
|
+
output.must_equal "#{level.upcase}: message\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#level" do
|
31
|
+
it "defaults to INFO" do
|
32
|
+
logger.level.must_equal Logger::INFO
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "verbose" do
|
37
|
+
|
38
|
+
let(:logger) { ConsoleLogger.new(output_stream, true) }
|
39
|
+
|
40
|
+
describe "#level" do
|
41
|
+
it "defaults to DEBUG" do
|
42
|
+
logger.level.must_equal Logger::DEBUG
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: console_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Williams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- mdub@dogbiscuit.org
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- console_logger.gemspec
|
54
|
+
- lib/console_logger.rb
|
55
|
+
- test/test_console_logger.rb
|
56
|
+
- test/test_helper.rb
|
57
|
+
homepage: https://github.com/mdub/console_logger
|
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.2.2
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: A Logger customised for console output.
|
81
|
+
test_files:
|
82
|
+
- test/test_console_logger.rb
|
83
|
+
- test/test_helper.rb
|