dfc_log 0.1.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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +33 -0
- data/Rakefile +6 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/dfc_log.gemspec +31 -0
- data/lib/dfc_log/dfc_log_formatter.rb +28 -0
- data/lib/dfc_log/version.rb +3 -0
- data/lib/dfc_log.rb +12 -0
- data/log/.keep +0 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a67d9e10b47bdb3b7a8b211b428fb1626b8b4c21
|
4
|
+
data.tar.gz: 40d0bb50b7ef753dc33f54e11bb2db911b00c394
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95ca7812aac5e3a8c7703b00e9cc3c20d8e97a5371f41fba7b3ad21b6ab52351903ea721acb8598ca2615ecc5c4cfb21fdbc24f1a9874a78e06e3aa93dc62cc3
|
7
|
+
data.tar.gz: b0b7bd9683595c2a9a07e4d4374515d2afeaa01ed59edda093927b668e108401a29d4a5bdd5aa9f9c64f02216d84bc686c96da399d4cd815b9d33c83ed6ca5d9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# DfcLog
|
2
|
+
This gem adds logging to your rails application and provides a convienent constant called Log to make log calls.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'dfc_log'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install dfc_log
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Use Log.debug etc.
|
23
|
+
|
24
|
+
## Development
|
25
|
+
|
26
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
27
|
+
|
28
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/devforce/dfc_log.
|
33
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rails'
|
5
|
+
require 'dfc_log'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require 'pry'
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
data/dfc_log.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dfc_log/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dfc_log'
|
8
|
+
spec.version = DfcLog::VERSION
|
9
|
+
spec.authors = ['Mike Papper']
|
10
|
+
spec.email = ['bodaro@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Sets up Rails logging for Heroku apps.'
|
13
|
+
spec.description = 'Uses custom Log Formatter, one for development and ' \
|
14
|
+
'one for Heroku. Ensure Heroku request IDs are ' \
|
15
|
+
'in the logs. Limits logs to 2500 bytes per entry. Adds a constant ' \
|
16
|
+
'called Log to ease logging.'
|
17
|
+
spec.homepage = 'https://github.com/devforce/dfc-log'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_dependency 'rails'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# N.B. we limit log message length to 2500 characters
|
2
|
+
class DfcLogFormatter
|
3
|
+
SEVERITY_TO_COLOR_MAP = { 'DEBUG' => '0;37', 'INFO' => '32',
|
4
|
+
'WARN' => '33', 'ERROR' => '31',
|
5
|
+
'FATAL' => '31', 'UNKNOWN' => '37' }.freeze
|
6
|
+
|
7
|
+
def call(severity, time, _progname, msg)
|
8
|
+
msg = 'BLANK MESSAGE' if msg.blank?
|
9
|
+
msg = msg.strip
|
10
|
+
|
11
|
+
Rails.env.production? ? log_non_local(severity, msg) : log_local(severity, time, msg)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def log_local(severity, time, msg)
|
17
|
+
color = SEVERITY_TO_COLOR_MAP[severity]
|
18
|
+
formatted_severity = format('%-5s', severity)
|
19
|
+
formatted_time = time.strftime('%Y-%m-%d %H:%M:%S.') << time.usec.to_s[0..2].rjust(3)
|
20
|
+
"\033[0;37m#{formatted_time}\033[0m [\033[#{color}m#{formatted_severity}\033[0m] #{msg}\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
def log_non_local(severity, msg)
|
24
|
+
# limit to 2500 characters max for hosted logging (unless $DEBUG is set)
|
25
|
+
msg = msg[0..2500] + (msg.length > 2500 ? '...' : '') unless $DEBUG
|
26
|
+
"DFC-#{format('%-5s', severity)} #{msg}\n"
|
27
|
+
end
|
28
|
+
end
|
data/lib/dfc_log.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'dfc_log/version'
|
2
|
+
require 'dfc_log/dfc_log_formatter'
|
3
|
+
|
4
|
+
# DfcLog main class - sets up the formatter
|
5
|
+
module DfcLog
|
6
|
+
mylog = Logger.new(Rails.env.production? ? STDOUT : "log/#{Rails.env}.log")
|
7
|
+
mylog.formatter = DfcLogFormatter.new
|
8
|
+
Rails.logger = ActiveSupport::TaggedLogging.new(mylog)
|
9
|
+
end
|
10
|
+
|
11
|
+
# define convenieience object so you can do Log.debug('...') easily throughout your code
|
12
|
+
Log = Rails.logger
|
data/log/.keep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dfc_log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Papper
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Uses custom Log Formatter, one for development and one for Heroku. Ensure
|
70
|
+
Heroku request IDs are in the logs. Limits logs to 2500 bytes per entry. Adds a
|
71
|
+
constant called Log to ease logging.
|
72
|
+
email:
|
73
|
+
- bodaro@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- dfc_log.gemspec
|
87
|
+
- lib/dfc_log.rb
|
88
|
+
- lib/dfc_log/dfc_log_formatter.rb
|
89
|
+
- lib/dfc_log/version.rb
|
90
|
+
- log/.keep
|
91
|
+
homepage: https://github.com/devforce/dfc-log
|
92
|
+
licenses: []
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Sets up Rails logging for Heroku apps.
|
114
|
+
test_files: []
|