stderr_logger 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stderr_logger.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Guillermo Álvarez
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,29 @@
1
+ # StderrLogger
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'stderr_logger'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install stderr_logger
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+
4
+ task :test do
5
+ sh "ruby -rubygems -I lib -I test test/test_logger.rb"
6
+ end
@@ -0,0 +1,46 @@
1
+ require "stderr_logger/version"
2
+ require 'logger'
3
+ require 'colored'
4
+
5
+ module StderrLogger
6
+ class Logger < ::Logger
7
+ include Colored
8
+ USE_COLOR=STDERR.tty?
9
+ SEVERITY_TO_COLOR={
10
+ "INFO" => {:foreground => :white},
11
+ "DEBUG" => {:foreground => :yellow},
12
+ "ERROR" => {:foreground => :red}
13
+ }
14
+
15
+ def initialize()
16
+ super(STDERR)
17
+ if USE_COLOR
18
+ self.formatter = proc { |severity, datetime, progname, msg|
19
+ time = datetime.strftime("%b %e %H:%M:%S")
20
+ "#{time} #{File.basename($0)} : #{colorize(msg, SEVERITY_TO_COLOR[severity])}"
21
+ }
22
+ else
23
+ self.formatter = proc { |severity, datetime, progname, msg|
24
+ time = datetime.strftime("%b %e %H:%M:%S")
25
+ "#{time} #{File.basename($0)} #{severity} : #{msg}"
26
+ }
27
+ end
28
+ end
29
+ end
30
+
31
+ def self.logger
32
+ @logger ||= Logger.new
33
+ end
34
+ end
35
+
36
+ class Object
37
+ def debug(*args)
38
+ StderrLogger.logger.debug(*args)
39
+ end
40
+ def info(*args)
41
+ StderrLogger.logger.info(*args)
42
+ end
43
+ def error(*args)
44
+ StderrLogger.logger.info(*args)
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module StderrLogger
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stderr_logger/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "stderr_logger"
8
+ gem.version = StderrLogger::VERSION
9
+ gem.authors = ["Guillermo A\314\201lvarez"]
10
+ gem.email = ["guillermo@cientifico.net"]
11
+ gem.description = %q{Simple logger that add info debug and error to Object and always output to STDERR}
12
+ gem.summary = %q{Simple logger}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
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 "colored"
21
+ gem.add_development_dependency "mocha"
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "delorean"
24
+ end
@@ -0,0 +1,32 @@
1
+ require 'test/unit'
2
+ require 'stderr_logger'
3
+ require 'mocha'
4
+ require 'delorean'
5
+ require 'colored'
6
+ require 'time'
7
+
8
+ class TestStderrLogger < Test::Unit::TestCase
9
+ include ::Colored
10
+
11
+ def setup
12
+ Delorean.time_travel_to "2012/01/01 23:23"
13
+ $0 = "el_programa"
14
+ StderrLogger.const_set("USE_COLOR", true)
15
+ @logger = StderrLogger.logger
16
+ @logdev = @logger.instance_variable_get("@logdev")
17
+ end
18
+
19
+ def test_info
20
+ @logdev.expects(:write).with("Jan 1 23:23:00 el_programa INFO : hola")
21
+ info "hola"
22
+ end
23
+ def test_error
24
+ @logdev.expects(:write).with("Jan 1 23:23:00 el_programa ERROR : hola")
25
+ error "hola"
26
+ end
27
+ def test_debug
28
+ @logdev.expects(:write).with("Jan 1 23:23:00 el_programa DEBUG : hola")
29
+ info "hola"
30
+ end
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stderr_logger
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - "Guillermo A\xCC\x81lvarez"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-11-07 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
+ name: colored
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ requirement: *id001
33
+ type: :runtime
34
+ - !ruby/object:Gem::Dependency
35
+ prerelease: false
36
+ name: mocha
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ requirement: *id002
47
+ type: :development
48
+ - !ruby/object:Gem::Dependency
49
+ prerelease: false
50
+ name: rake
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirement: *id003
61
+ type: :development
62
+ - !ruby/object:Gem::Dependency
63
+ prerelease: false
64
+ name: delorean
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ requirement: *id004
75
+ type: :development
76
+ description: Simple logger that add info debug and error to Object and always output to STDERR
77
+ email:
78
+ - guillermo@cientifico.net
79
+ executables: []
80
+
81
+ extensions: []
82
+
83
+ extra_rdoc_files: []
84
+
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - lib/stderr_logger.rb
92
+ - lib/stderr_logger/version.rb
93
+ - stderr_logger.gemspec
94
+ - test/test_logger.rb
95
+ homepage: ""
96
+ licenses: []
97
+
98
+ post_install_message:
99
+ rdoc_options: []
100
+
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project:
124
+ rubygems_version: 1.8.24
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Simple logger
128
+ test_files:
129
+ - test/test_logger.rb