spyt 1.0.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: b1f4cd37c51f1e44bb150553d2a20abd74af0b71
4
+ data.tar.gz: f184d2f9e9a4694654cc237f5fe9ea010994be47
5
+ SHA512:
6
+ metadata.gz: fc80a32fd0592f97880c1b67c3fba1dc3e72e6253ad25f602fff291bcb4154cb14e0211919f6b5c9d3148179d7728f139c03ee8b5a3652b95b650697e425e12a
7
+ data.tar.gz: 35dbf06a4abc167ccf421f4342a3c9f32fd2565bb70dc6223b2e620c51d5dcd5c205579c735ff4a3cee6cd12cd966164ba3d692726d894f2a5b9ee215c5203a4
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .idea
2
+ Gemfile.lock
3
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Paul Duncan
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.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Spyt
2
+
3
+ Simplify your logging
4
+
5
+ ## Presentation
6
+
7
+ This library provides a simple logger for any kind of application.
8
+
9
+ ## Installation
10
+
11
+ ### Gemfile
12
+ ```ruby
13
+ gem 'spyt'
14
+ ```
15
+
16
+ ### Terminal
17
+ ```bash
18
+ gem install -V spyt
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Simply *extend* anything (module, class or whatever) with the *Spyt::Loggable* module.
24
+ This will provide a *log* method which can be used as follows:
25
+
26
+ ```ruby
27
+ module Foo
28
+ include Spyt::Loggable
29
+
30
+ def foo
31
+ log.debug 'Debug Info...'
32
+ log.info 'Hello World!'
33
+ log.error 'This is an error message'
34
+ end
35
+ end
36
+ ```
37
+
38
+ ### Configuration
39
+
40
+ Configuration of the Logger can be modified by playing with the Spyt::CONFIG object.
41
+ The following options can be modified:
42
+ * :out - Output stream on which to produce logs (default: $stdout)
43
+ * :lvl - Current log level (default: :info)
44
+
45
+ ```ruby
46
+ # Dumping all the logs to a simple string:
47
+ s = ''
48
+ Spyt::CONFIG[:out] = s
49
+ ```
50
+
51
+ ```ruby
52
+ # Changing the log level at runtime:
53
+ Spyt::CONFIG[:lvl] = :debug
54
+ ```
55
+
56
+ ### Levels
57
+
58
+ Three levels are available:
59
+ * debug
60
+ * info
61
+ * error
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rake/testtask'
2
+ require 'bundler/gem_tasks'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/test*.rb'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,17 @@
1
+ # Spyt
2
+ # by Eresse <eresse@eresse.net>
3
+
4
+ # Spyt Module
5
+ module Spyt
6
+
7
+ # Configuration:
8
+ # Defines Spyt's behavior.
9
+ CONFIG = {
10
+
11
+ # Output Stream
12
+ out: $stdout,
13
+
14
+ # Level
15
+ lvl: :info
16
+ }
17
+ end
@@ -0,0 +1,25 @@
1
+ # Spyt
2
+ # by Eresse <eresse@eresse.net>
3
+
4
+ # Internal Includes
5
+ require 'spyt/version'
6
+
7
+ # Spyt Module
8
+ module Spyt
9
+
10
+ # Levels:
11
+ # Available Log Levels, mapped to numeric values.
12
+ LEVELS = {
13
+ debug: 2,
14
+ info: 1,
15
+ error: 0
16
+ }
17
+
18
+ # Level Colors:
19
+ # When using Spiffup for colorization, this map defines which color corresponds to which level.
20
+ LEVEL_COLS = {
21
+ debug: :brown,
22
+ info: :green,
23
+ error: :red
24
+ }
25
+ end
@@ -0,0 +1,36 @@
1
+ # Spyt
2
+ # by Eresse <eresse@eresse.net>
3
+
4
+ # External Includes
5
+ require 'aromat'
6
+ require 'spiffup'
7
+
8
+ # Internal Includes
9
+ require 'spyt/levels'
10
+
11
+ # Spyt Module
12
+ module Spyt
13
+
14
+ # Loggable Module
15
+ module Loggable
16
+
17
+ # Logger Class:
18
+ # Internal class used by Loggable module to provide logging methods.
19
+ class Logger
20
+
21
+ # Construct:
22
+ # Builds a *Logger* to represent a given _source_.
23
+ # @param [String] source Name of this logger's source
24
+ def initialize source
25
+ @source = source
26
+ end
27
+
28
+ # Generic Log Handler:
29
+ # Proxy to Log::method_missing
30
+ def method_missing name, *args
31
+ super unless LEVELS.include? name
32
+ Spyt.send name, @source, *args
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ # Spyt
2
+ # by Eresse <eresse@eresse.net>
3
+
4
+ # External Includes
5
+ require 'aromat'
6
+
7
+ # Internal Includes
8
+ require 'spyt/levels'
9
+ require 'spyt/loggable/logger'
10
+
11
+ # Spyt Module
12
+ module Spyt
13
+
14
+ # Loggable Module:
15
+ # Include this into anything to provide logging capability.
16
+ module Loggable
17
+
18
+ # Log:
19
+ # Logger Access
20
+ # @return [Logger] A Logger tailored to the containing object
21
+ def log
22
+ @logger ||= Logger.new self.try(:name) || self.try(:class).try(:name) || self.to_s
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ # Spyt
2
+ # by Eresse <eresse@eresse.net>
3
+
4
+ # Spyt Module
5
+ module Spyt
6
+
7
+ # Version
8
+ VERSION = '1.0.0'
9
+ end
data/lib/spyt.rb ADDED
@@ -0,0 +1,49 @@
1
+ # Spyt
2
+ # by Eresse <eresse@eresse.net>
3
+
4
+ # Internal Includes
5
+ require 'spyt/version'
6
+ require 'spyt/levels'
7
+ require 'spyt/config'
8
+ require 'spyt/loggable'
9
+
10
+ # Spyt Module:
11
+ # Root Module for Spyt.
12
+ module Spyt
13
+
14
+ # Generic Log Handler:
15
+ # Route log calls to each level.
16
+ def self.method_missing name, *args
17
+
18
+ # Fail on unknown Methods
19
+ super unless LEVELS.include? name
20
+
21
+ # Push Log (Level shortcuts)
22
+ push name, args[0], args[1]
23
+ end
24
+
25
+ # Push Message:
26
+ # Writes a message _msg_ from _src_ as level _lvl_ to the log.
27
+ # @param [Symbol] lvl Log level (see LEVELS)
28
+ # @param [String] src Message source
29
+ # @param [String] msg Message text
30
+ def self.push lvl, src, msg
31
+
32
+ # Check Level
33
+ raise "Invalid Log Level [#{lvl.to_s.inspect.bred}] requested" unless LEVELS.include? lvl.to_sym
34
+
35
+ # Check Level
36
+ return unless LEVELS[lvl] <= LEVELS[CONFIG[:lvl]]
37
+
38
+ # Ensure Lock is available
39
+ @lock ||= Mutex.new
40
+
41
+ # Synchronize
42
+ @lock.synchronize do
43
+
44
+ # Write & Flush
45
+ CONFIG[:out] << "#{Time.now.to_s.blue} [#{lvl.to_s.send LEVEL_COLS[lvl.to_sym]}] #{src.bmagenta} :: #{msg}"
46
+ CONFIG[:out].flush if CONFIG[:out].respond_to? :flush
47
+ end
48
+ end
49
+ end
data/spyt.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spyt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'spyt'
8
+ spec.version = Spyt::VERSION
9
+ spec.authors = ['Eresse']
10
+ spec.email = ['eresse@eresse.net']
11
+
12
+ spec.summary = 'Simplify your logging'
13
+ spec.description = 'Provides a simple logger for any kind of application.'
14
+ spec.homepage = 'http://redmine.eresse.net/projects/spyt'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_runtime_dependency 'minitest'
23
+ spec.add_runtime_dependency 'spiffup'
24
+ spec.add_runtime_dependency 'aromat'
25
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spyt
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eresse
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-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: '0'
20
+ type: :development
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: spiffup
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aromat
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Provides a simple logger for any kind of application.
84
+ email:
85
+ - eresse@eresse.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/spyt.rb
96
+ - lib/spyt/config.rb
97
+ - lib/spyt/levels.rb
98
+ - lib/spyt/loggable.rb
99
+ - lib/spyt/loggable/logger.rb
100
+ - lib/spyt/version.rb
101
+ - spyt.gemspec
102
+ homepage: http://redmine.eresse.net/projects/spyt
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Simplify your logging
126
+ test_files: []