simple_structured_logger 0.1.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: 315fe583360fe762860bf5b41c12ddd9b253759e
4
+ data.tar.gz: 27a68f4612e092dc60d297529f3ee421e4c21667
5
+ SHA512:
6
+ metadata.gz: 91459af84ce0e26f4a3883effa6fe307de46c8591bf77815667fa7e8b98d267425e84683923b10a38649108ac30efc5321edb861b6b34a067c97dadf16caf3b8
7
+ data.tar.gz: 8508a7487d73be951791e1e6859f3b10d0859dade862fd434301eaa37034a4d4ec9837e33f29205ef3c873588fe0532b6951cd0ae7a2b402a9ad927082646a88
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_structured_logger.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # SimpleStructuredLogger
2
+
3
+ Dead-simple structured logging in ruby with a dead-simple codebase. That's it.
4
+
5
+ ```ruby
6
+ gem 'simple_structured_logger'
7
+ ```
8
+
9
+ ## Design Goals
10
+
11
+ * Extremely simple codebase that's easy to read and override
12
+ * Structured logging that reads nicely
13
+ * Ability to easily set context, and expand context with user-configurable hook
14
+ * Ability to easily add structured log pre-processing. I want to be able to pass
15
+ in an object specific to my application and for the relavent important keys to
16
+ be expanded automatically.
17
+ * `Rails.logger = SimpleStructuredLogger.new(STDOUT)`
18
+ * Not designed around massive systems or scale
19
+ * Don't support multiple log destinations
20
+ * Don't build in fancy pre-processing for errors or other common ruby objects
21
+
22
+ ### Opinionated Devops Setup
23
+
24
+ * Errors are tracked using Rollbar, Airbrake, Sentry, etc.
25
+ * Log to STDOUT
26
+ * Pipe STDOUT to PaperTrail, Loggly, etc
27
+ * Great for Heroku or [dokku/docker](http://mikebian.co/sending-dokku-container-logs-to-papertrail/) hosted system
28
+
29
+ ## Alternatives
30
+
31
+ * https://github.com/jordansissel/ruby-cabin
32
+ * https://github.com/asenchi/scrolls
33
+ * https://github.com/stripe/chalk-log
34
+ * https://github.com/nishidayuya/structured_logger
35
+
36
+ ## Why is structured logging important?
37
+
38
+ * https://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-about-real-time-datas-unifying
39
+ * http://juliusdavies.ca/logging.html
40
+
41
+ ## What about Rail's tagged logging?
42
+
43
+ Tagged logging is not structured logging. I want to be able to search through
44
+ PaperTrail and easily grab an audit trail for a specific context, i.e. `the_job=FailingJob the_user=1`.
45
+
46
+ ## Usage
47
+
48
+ TODO: Write usage instructions here
49
+
50
+ ## Testing
51
+
52
+ ```
53
+ bundle exec rake
54
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simple_structured_logger"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,86 @@
1
+ require 'logger'
2
+
3
+ module SimpleStructuredLogger
4
+ def log
5
+ SimpleStructuredLogger::Writer.instance
6
+ end
7
+
8
+ def self.included(klass)
9
+
10
+ # TODO there's got to be a cleaner way to add a class method from `include`
11
+ klass.class_eval do
12
+ def self.log
13
+ SimpleStructuredLogger::Writer.instance
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ module Configuration
20
+ extend self
21
+
22
+ def expand_context(&block)
23
+ if block.nil?
24
+ @expand_context = block
25
+ else
26
+ @expand_context
27
+ end
28
+ end
29
+
30
+ def expand_log(&block)
31
+ if block.nil?
32
+ @expand_log = block
33
+ else
34
+ @expand_log
35
+ end
36
+ end
37
+ end
38
+
39
+ class Writer
40
+ include Singleton
41
+
42
+ attr_reader :default_tags
43
+
44
+ def initialize
45
+ @l = ::Logger.new(STDOUT)
46
+ @default_tags = {}
47
+ end
48
+
49
+ def reset_context!
50
+ @default_tags = {}
51
+ end
52
+
53
+ def set_context(context)
54
+ reset_context!
55
+
56
+ @default_tags.merge!(context)
57
+ end
58
+
59
+ def error(msg, opts={})
60
+ @l.error("#{msg}: #{stringify_tags(opts)}")
61
+ end
62
+
63
+ def info(msg, opts={})
64
+ @l.info("#{msg}: #{stringify_tags(opts)}")
65
+ end
66
+
67
+ def debug(msg, opts={})
68
+ @l.debug("#{msg}: #{stringify_tags(opts)}")
69
+ end
70
+
71
+ def warn(msg, opts={})
72
+ @l.warn("#{msg}: #{stringify_tags(opts)}")
73
+ end
74
+
75
+ private
76
+
77
+ def stringify_tags(additional_tags)
78
+ additional_tags = additional_tags.dup
79
+
80
+ # TODO expand
81
+
82
+ @default_tags.merge(additional_tags).map { |k,v| "#{k}=#{v}" }.join(' ')
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "simple_structured_logger"
7
+ spec.version = '0.1.0'
8
+ spec.authors = ["Michael Bianco"]
9
+ spec.email = ["mike@cliffsidemedia.com"]
10
+
11
+ spec.summary = "Dead-simple structured logging in ruby with a dead-simple codebase."
12
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
13
+ spec.homepage = "https://github.com/iloveitaly/simple_structured_logger"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "minitest", "~> 5.0"
23
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_structured_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bianco
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-12 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description:
56
+ email:
57
+ - mike@cliffsidemedia.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - lib/simple_structured_logger.rb
69
+ - simple_structured_logger.gemspec
70
+ homepage: https://github.com/iloveitaly/simple_structured_logger
71
+ licenses: []
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.5.1
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Dead-simple structured logging in ruby with a dead-simple codebase.
93
+ test_files: []