logsaber 1.0.0 → 1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1fb9c4ba5b8572cf1343d8f6c78c4ca41cb31361ba7ab028b00e85cd728285cc
4
+ data.tar.gz: 71a9a4c4ba811a381a13ae6377491c0d0473c94496582ecbf7b19ba725543ecc
5
+ SHA512:
6
+ metadata.gz: 3f37e4f231970523cf0b24f49c148442148ca08e6a20c61794b95054caf6b7f2fe36b6978113f50c0f2520d39fc0089e44f108f339e3d67c618660088feb1184
7
+ data.tar.gz: e280a3df89f1f3c4a477edd634d19b8c3052b931fa2500e0da32e769cc0d5467bb85580c0fbca5855ab63dd0d3d29a5f53a8baa8a61f8e42828bee66d50404a4
@@ -0,0 +1,21 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@0.1.2
4
+
5
+ jobs:
6
+ build:
7
+ docker:
8
+ - image: circleci/ruby:2.6.3-stretch-node
9
+ executor: ruby/default
10
+ steps:
11
+ - checkout
12
+ - run:
13
+ name: Which bundler?
14
+ command: bundle -v
15
+ - ruby/bundle-install
16
+ test:
17
+ executor: ruby/default
18
+ steps:
19
+ - run:
20
+ name: Uspec tests
21
+ command: uspec
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ logsaber
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.1.2
data/README.markdown CHANGED
@@ -3,12 +3,11 @@ Logsaber
3
3
 
4
4
  A logger for a more civilized age.
5
5
 
6
- - Edge Logsaber README: https://github.com/acook/logsaber#readme
7
- - Release version README: http://rubydoc.info/gems/logsaber/file/README.markdown
6
+ Reference documentation for the [Latest Released](http://rubydoc.info/gems/logsaber/file/README.markdown) and [Edge Version](https://github.com/acook/logsaber#readme) is available.
8
7
 
9
- [![Build Status](https://travis-ci.org/acook/logsaber.png?branch=master)](https://travis-ci.org/acook/logsaber)
10
- [![Code Climate](https://codeclimate.com/github/acook/logsaber.png)](https://codeclimate.com/github/acook/logsaber)
11
- [![Dependency Status](https://gemnasium.com/acook/logsaber.png)](https://gemnasium.com/acook/logsaber)
8
+ [![Gem Version](https://img.shields.io/gem/v/logsaber.svg?style=for-the-badge)](https://rubygems.org/gems/logsaber/)
9
+ [![CircleCI](https://img.shields.io/circleci/build/github/acook/logsaber?style=for-the-badge&token=de887bd244ab55306432fef45b8307ef4c18075c)](https://app.circleci.com/pipelines/github/acook/logsaber)
10
+ [![Code Climate](https://img.shields.io/codeclimate/maintainability/acook/logsaber?style=for-the-badge)](https://codeclimate.com/github/acook/logsaber)
12
11
 
13
12
  Philosophy / Why Logsaber?
14
13
  --------------------------
@@ -193,4 +192,4 @@ Contributing
193
192
  Author
194
193
  ======
195
194
 
196
- Anthony M. Cook 2013
195
+ Anthony M. Cook 2013-2021
@@ -2,16 +2,22 @@ module Logsaber
2
2
  class Entry
3
3
  def self.create all_details, &block
4
4
  all_details << block.call if block
5
- new all_details.length, all_details.shift, Array(all_details)
5
+ new all_details.shift, Array(all_details)
6
6
  end
7
7
 
8
- def initialize length, primary, secondary
9
- @length, @primary, @secondary = length, primary, secondary
8
+ def initialize primary, secondary
9
+ @primary, @secondary = primary, secondary
10
10
  end
11
- attr :length, :primary, :secondary
11
+ attr :primary, :secondary
12
12
 
13
13
  def parse
14
- [text, value]
14
+ {
15
+ label: label,
16
+ info: info,
17
+ primary: primary,
18
+ secondary: secondary,
19
+ object: value
20
+ }
15
21
  end
16
22
 
17
23
  protected
@@ -20,10 +26,6 @@ module Logsaber
20
26
  secondary.last || primary
21
27
  end
22
28
 
23
- def text
24
- "#{label} : #{info}"
25
- end
26
-
27
29
  def label
28
30
  if !secondary.empty? then
29
31
  view primary
@@ -36,14 +38,14 @@ module Logsaber
36
38
 
37
39
  def info
38
40
  if secondary.empty? then
39
- view primary
41
+ Array view primary
40
42
  else
41
43
  details
42
44
  end
43
45
  end
44
46
 
45
47
  def details
46
- secondary.map{|item| analyze item }.join ' | '
48
+ secondary.map{|item| analyze item }
47
49
  end
48
50
 
49
51
  def view object
@@ -17,6 +17,7 @@ module Logsaber
17
17
  end
18
18
 
19
19
  def color!
20
+ require 'logsaber/simple_color'
20
21
  @color = SimpleColor.new
21
22
  end
22
23
 
@@ -36,7 +37,11 @@ module Logsaber
36
37
  end
37
38
 
38
39
  def layout severity, contents
39
- %(#{timestamp} [#{severity_info severity}] #{process_info} | #{contents})
40
+ %(#{timestamp} [#{severity_info severity}] #{process_info} | #{view contents})
41
+ end
42
+
43
+ def view contents
44
+ "#{contents[:label]} : #{contents[:info].join ' | '}"
40
45
  end
41
46
 
42
47
  def timestamp
data/lib/logsaber/log.rb CHANGED
@@ -17,7 +17,7 @@ module Logsaber
17
17
  SEVERITY_LEVELS ||= [:debug, :info, :warn, :error, :fatal, :off]
18
18
 
19
19
  def initialize output, level, appname, formatter
20
- @output = outputize output
20
+ self.output = output
21
21
  @level = level.to_sym
22
22
  @appname = appname
23
23
  @formatter = formatter.set_log self
@@ -39,6 +39,10 @@ module Logsaber
39
39
  END_OF_METHOD
40
40
  end
41
41
 
42
+ def output= new_output
43
+ @output = [new_output].flatten.map {|io| outputize(io) }
44
+ end
45
+
42
46
  protected
43
47
 
44
48
  def log severity, *details, &block
@@ -50,8 +54,10 @@ module Logsaber
50
54
  end
51
55
 
52
56
  def out text
53
- output.puts text
54
- output.flush
57
+ output.each do |io|
58
+ io.puts text
59
+ io.flush
60
+ end
55
61
  end
56
62
 
57
63
  def format *args
@@ -1,5 +1,7 @@
1
+ require 'ostruct'
2
+
1
3
  module Logsaber
2
- class Options < OpenStruct
4
+ class Options < ::OpenStruct
3
5
  def self.extract_from args, defaults = {}, primary = nil
4
6
  options = args.last.is_a?(Hash) ? args.pop : Hash.new
5
7
  options[primary] = args.shift if primary && args.first
@@ -1,6 +1,6 @@
1
1
  module Logsaber
2
2
  class SimpleColor
3
- attr_accessor colors
3
+ attr_accessor :colors
4
4
 
5
5
  def colorize index, text = nil, &block
6
6
  "#{color index}#{text || yield}#{esc 0}"
@@ -1,3 +1,3 @@
1
1
  module Logsaber
2
- VERSION = "1.0.0"
2
+ VERSION = '1.0.1'
3
3
  end
data/logsaber.gemspec CHANGED
@@ -4,18 +4,18 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'logsaber/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "logsaber"
7
+ gem.name = 'logsaber'
8
8
  gem.version = Logsaber::VERSION
9
- gem.authors = ["Anthony Cook"]
10
- gem.email = ["anthonymichaelcook@gmail.com"]
9
+ gem.authors = ['Anthony Cook']
10
+ gem.email = ['anthonymichaelcook@gmail.com']
11
11
  gem.description = %q{A logger for a more civilized age. Intelligent logs for your applications.}
12
12
  gem.summary = %q{A logger for a more civilized age.}
13
- gem.homepage = "http://github.com/acook/logsaber"
13
+ gem.homepage = 'http://github.com/acook/logsaber'
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
18
+ gem.require_paths = ['lib']
19
19
 
20
20
  gem.add_development_dependency 'uspec'
21
21
  end
@@ -0,0 +1,13 @@
1
+ require_relative 'spec_helper'
2
+
3
+ spec 'does stuff' do
4
+ stringio = StringIO.new
5
+ log = Logsaber.create stringio
6
+
7
+ log.info 5
8
+ expecting = /20\d\d-\d\d-\d\d \d\d:\d\d:\d\d.\d\d\d \[ INFO\] #{Process.pid} \| OBJ : 5\n/
9
+ actual = stringio.tap(&:rewind).read
10
+ match = expecting.match actual
11
+
12
+ !!match || actual
13
+ end
data/spec/log_spec.rb CHANGED
@@ -1,5 +1,21 @@
1
1
  require_relative 'spec_helper'
2
2
 
3
+ def self.capture
4
+ readme, writeme = IO.pipe
5
+ pid = fork do
6
+ $stdout.reopen writeme
7
+ readme.close
8
+
9
+ yield
10
+ end
11
+
12
+ writeme.close
13
+ output = readme.read
14
+ Process.waitpid(pid)
15
+
16
+ output
17
+ end
18
+
3
19
  test_string = 'foo'
4
20
 
5
21
  spec 'will output to a file, given a filename' do
@@ -149,3 +165,23 @@ spec 'Log#log allows many items' do
149
165
  @log.info :foo, '1', '2', '3'
150
166
  @output.string.include? format('foo', '1 | 2 | 3')
151
167
  end
168
+
169
+ spec 'Log.create can take an array of outputs' do
170
+ Logsaber::Log.create output: [StringIO.new, StringIO.new]
171
+ true
172
+ end
173
+
174
+ spec 'Logging goes to every output' do
175
+ s1 = StringIO.new
176
+ s2 = StringIO.new
177
+
178
+ text = 'What we display??'
179
+
180
+ @log = Logsaber::Log.create output: [s1, s2]
181
+
182
+ @log.error text
183
+
184
+ s1.string.include?(text) && s2.string.include?(text) || s2.string
185
+ end
186
+
187
+
data/spec/spec_helper.rb CHANGED
@@ -9,19 +9,3 @@ Dir.chdir File.dirname(__FILE__)
9
9
  require_relative '../lib/logsaber'
10
10
 
11
11
  extend Uspec
12
-
13
- def self.capture
14
- readme, writeme = IO.pipe
15
- pid = fork do
16
- $stdout.reopen writeme
17
- readme.close
18
-
19
- yield
20
- end
21
-
22
- writeme.close
23
- output = readme.read
24
- Process.waitpid(pid)
25
-
26
- output
27
- end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logsaber
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Anthony Cook
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-11 00:00:00.000000000 Z
11
+ date: 2023-02-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: uspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: A logger for a more civilized age. Intelligent logs for your applications.
@@ -34,9 +31,10 @@ executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
38
- - .rvmrc
39
- - .travis.yml
34
+ - ".circleci/config.yml"
35
+ - ".gitignore"
36
+ - ".ruby-gemset"
37
+ - ".ruby-version"
40
38
  - Gemfile
41
39
  - LICENSE.txt
42
40
  - README.markdown
@@ -49,32 +47,32 @@ files:
49
47
  - lib/logsaber/simple_color.rb
50
48
  - lib/logsaber/version.rb
51
49
  - logsaber.gemspec
50
+ - spec/log_feature_spec.rb
52
51
  - spec/log_spec.rb
53
52
  - spec/spec_helper.rb
54
53
  homepage: http://github.com/acook/logsaber
55
54
  licenses: []
56
- post_install_message:
55
+ metadata: {}
56
+ post_install_message:
57
57
  rdoc_options: []
58
58
  require_paths:
59
59
  - lib
60
60
  required_ruby_version: !ruby/object:Gem::Requirement
61
- none: false
62
61
  requirements:
63
- - - ! '>='
62
+ - - ">="
64
63
  - !ruby/object:Gem::Version
65
64
  version: '0'
66
65
  required_rubygems_version: !ruby/object:Gem::Requirement
67
- none: false
68
66
  requirements:
69
- - - ! '>='
67
+ - - ">="
70
68
  - !ruby/object:Gem::Version
71
69
  version: '0'
72
70
  requirements: []
73
- rubyforge_project:
74
- rubygems_version: 1.8.25
75
- signing_key:
76
- specification_version: 3
71
+ rubygems_version: 3.3.7
72
+ signing_key:
73
+ specification_version: 4
77
74
  summary: A logger for a more civilized age.
78
75
  test_files:
76
+ - spec/log_feature_spec.rb
79
77
  - spec/log_spec.rb
80
78
  - spec/spec_helper.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm --create ruby-1.9.3-p385@logsaber
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 1.9.2
5
- - rbx-19mode
6
- - ruby-head
7
- script: bundle exec ruby spec/log_spec.rb
8
- before_install:
9
- - gem update bundler
10
- before_script:
11
- - bundle exec gem list