simple_structured_logger 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 315fe583360fe762860bf5b41c12ddd9b253759e
4
- data.tar.gz: 27a68f4612e092dc60d297529f3ee421e4c21667
2
+ SHA256:
3
+ metadata.gz: bd3c01ed526e586a28acf3c9dcc9c3d8220bea4547c264568cf32c4293c9a77c
4
+ data.tar.gz: dc3beaa6509ca46fb2be4405e6211b75b373f87221dca5f7ba66e25ed723c4a2
5
5
  SHA512:
6
- metadata.gz: 91459af84ce0e26f4a3883effa6fe307de46c8591bf77815667fa7e8b98d267425e84683923b10a38649108ac30efc5321edb861b6b34a067c97dadf16caf3b8
7
- data.tar.gz: 8508a7487d73be951791e1e6859f3b10d0859dade862fd434301eaa37034a4d4ec9837e33f29205ef3c873588fe0532b6951cd0ae7a2b402a9ad927082646a88
6
+ metadata.gz: 9a1a5ba635be779a15ea83a4d17d8e71af96f0dc5cc0324bc2ac83af8e76fb959047d236b9e1191990481dfeaaf390469c0b737bfbc532f3bc24fe4979cdf636
7
+ data.tar.gz: 94830ac9e6452c82183564f9a67e58560d9eacd617a7aea1d69c1d291ffc4187da7726c386895361f78da3e1faa4f020c12c452ac4b01e639c1cbf06bf13a1c2
@@ -0,0 +1,7 @@
1
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2
+ version: 2
3
+ updates:
4
+ - package-ecosystem: "bundler"
5
+ directory: "/" # Location of package manifests
6
+ schedule:
7
+ interval: "monthly"
@@ -0,0 +1,33 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.6', '2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby-version }}
30
+ bundler-cache: true
31
+ - name: Run tests
32
+ run: bundle exec rake
33
+
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.7.3
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in simple_structured_logger.gemspec
4
2
  gemspec
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Ruby](https://github.com/iloveitaly/simple_structured_logger/actions/workflows/ruby.yml/badge.svg)](https://github.com/iloveitaly/simple_structured_logger/actions/workflows/ruby.yml)
2
+ [![gem](https://img.shields.io/gem/v/simple_structured_logger.svg)](https://rubygems.org/gems/simple_structured_logger)
3
+
1
4
  # SimpleStructuredLogger
2
5
 
3
6
  Dead-simple structured logging in ruby with a dead-simple codebase. That's it.
@@ -32,6 +35,7 @@ gem 'simple_structured_logger'
32
35
  * https://github.com/asenchi/scrolls
33
36
  * https://github.com/stripe/chalk-log
34
37
  * https://github.com/nishidayuya/structured_logger
38
+ * https://github.com/rocketjob/semantic_logger
35
39
 
36
40
  ## Why is structured logging important?
37
41
 
@@ -45,7 +49,26 @@ PaperTrail and easily grab an audit trail for a specific context, i.e. `the_job=
45
49
 
46
50
  ## Usage
47
51
 
48
- TODO: Write usage instructions here
52
+ ```ruby
53
+ # config/initializers/logger.rb
54
+ if Rails.env.development? || Rails.env.test?
55
+ SimpleStructuredLogger::Writer.instance.logger = Rails.logger
56
+ end
57
+
58
+ # models/order.rb
59
+ class Order
60
+ include SimpleStructuredLogger
61
+
62
+ def initialize
63
+ log.reset_context!
64
+ log.default_tags[:global] = 'key'
65
+ end
66
+
67
+ def do_something
68
+ log.info 'simple structured logging', key: value, shopify_id: 123
69
+ end
70
+ end
71
+ ```
49
72
 
50
73
  ## Testing
51
74
 
@@ -1,4 +1,5 @@
1
1
  require 'logger'
2
+ require 'singleton'
2
3
 
3
4
  module SimpleStructuredLogger
4
5
  def log
@@ -6,7 +7,6 @@ module SimpleStructuredLogger
6
7
  end
7
8
 
8
9
  def self.included(klass)
9
-
10
10
  # TODO there's got to be a cleaner way to add a class method from `include`
11
11
  klass.class_eval do
12
12
  def self.log
@@ -39,10 +39,10 @@ module SimpleStructuredLogger
39
39
  class Writer
40
40
  include Singleton
41
41
 
42
- attr_reader :default_tags
42
+ attr_accessor :default_tags, :logger
43
43
 
44
44
  def initialize
45
- @l = ::Logger.new(STDOUT)
45
+ @logger = ::Logger.new(STDOUT)
46
46
  @default_tags = {}
47
47
  end
48
48
 
@@ -53,31 +53,43 @@ module SimpleStructuredLogger
53
53
  def set_context(context)
54
54
  reset_context!
55
55
 
56
+ if self.respond_to?(:expand_context)
57
+ context = self.expand_context(context)
58
+ end
59
+
56
60
  @default_tags.merge!(context)
57
61
  end
58
62
 
59
63
  def error(msg, opts={})
60
- @l.error("#{msg}: #{stringify_tags(opts)}")
64
+ @logger.error("#{msg}: #{stringify_tags(opts)}")
61
65
  end
62
66
 
63
67
  def info(msg, opts={})
64
- @l.info("#{msg}: #{stringify_tags(opts)}")
68
+ @logger.info("#{msg}: #{stringify_tags(opts)}")
65
69
  end
66
70
 
67
71
  def debug(msg, opts={})
68
- @l.debug("#{msg}: #{stringify_tags(opts)}")
72
+ @logger.debug("#{msg}: #{stringify_tags(opts)}")
69
73
  end
70
74
 
71
75
  def warn(msg, opts={})
72
- @l.warn("#{msg}: #{stringify_tags(opts)}")
76
+ # TODO consider returning the generated log string with structured keys
77
+
78
+ @logger.warn("#{msg}: #{stringify_tags(opts)}")
73
79
  end
74
80
 
75
81
  private
76
82
 
83
+ def generate_log(msg, opts)
84
+ #code
85
+ end
86
+
77
87
  def stringify_tags(additional_tags)
78
88
  additional_tags = additional_tags.dup
79
89
 
80
- # TODO expand
90
+ if self.respond_to?(:expand_log)
91
+ additional_tags = self.expand_log(additional_tags)
92
+ end
81
93
 
82
94
  @default_tags.merge(additional_tags).map { |k,v| "#{k}=#{v}" }.join(' ')
83
95
  end
@@ -4,11 +4,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "simple_structured_logger"
7
- spec.version = '0.1.0'
7
+ spec.version = '0.1.5'
8
8
  spec.authors = ["Michael Bianco"]
9
- spec.email = ["mike@cliffsidemedia.com"]
9
+ spec.email = ["mike@mikebian.co"]
10
10
 
11
- spec.summary = "Dead-simple structured logging in ruby with a dead-simple codebase."
11
+ spec.summary = "Dead-simple structured logging in ruby with a simple codebase."
12
12
  # spec.description = %q{TODO: Write a longer description or delete this line.}
13
13
  spec.homepage = "https://github.com/iloveitaly/simple_structured_logger"
14
14
 
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.11"
21
- spec.add_development_dependency "rake", "~> 10.0"
20
+ spec.add_development_dependency "bundler", "~> 2.2.15"
21
+ spec.add_development_dependency "rake", "~> 12.3.3"
22
22
  spec.add_development_dependency "minitest", "~> 5.0"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_structured_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bianco
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-12 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: 2.2.15
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.11'
26
+ version: 2.2.15
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,14 +52,17 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
- description:
55
+ description:
56
56
  email:
57
- - mike@cliffsidemedia.com
57
+ - mike@mikebian.co
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".github/dependabot.yml"
63
+ - ".github/workflows/ruby.yml"
62
64
  - ".gitignore"
65
+ - ".tool-versions"
63
66
  - Gemfile
64
67
  - README.md
65
68
  - Rakefile
@@ -70,7 +73,7 @@ files:
70
73
  homepage: https://github.com/iloveitaly/simple_structured_logger
71
74
  licenses: []
72
75
  metadata: {}
73
- post_install_message:
76
+ post_install_message:
74
77
  rdoc_options: []
75
78
  require_paths:
76
79
  - lib
@@ -85,9 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
88
  - !ruby/object:Gem::Version
86
89
  version: '0'
87
90
  requirements: []
88
- rubyforge_project:
89
- rubygems_version: 2.5.1
90
- signing_key:
91
+ rubygems_version: 3.1.6
92
+ signing_key:
91
93
  specification_version: 4
92
- summary: Dead-simple structured logging in ruby with a dead-simple codebase.
94
+ summary: Dead-simple structured logging in ruby with a simple codebase.
93
95
  test_files: []