logging_by_bean 0.0.2 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53ced3a7ba6438bfdbe0fdc32a4f8385cee6088c
4
- data.tar.gz: fd9bc463275278e6ddc00b3df337d5a44077bb14
3
+ metadata.gz: 88763963b29f16e50bfc2c2066dfcdf805bb74dc
4
+ data.tar.gz: cc7e08c1bac8ab71203bccef2e94def74ab1d2bd
5
5
  SHA512:
6
- metadata.gz: 908f9b98bfbd9fd7cff2c23cef3324b555d842e80db81370b9030cbaa4e3420ff4dc190faf39d5ae0d3baefed3f313beeae509767a0dcc6ea2cbc46d1b134807
7
- data.tar.gz: 029cf89df72d21167fdf9f95b920749359bd96eb94c681086683e06f294034c57773bcc97eafe61346a54a02f4245d9ae96980cdb1fcd8b0ffff263ca0049528
6
+ metadata.gz: b561b9e7dd262a40fb6041f320fb8854d8f2480013e1cb575aaf9dd33bb3cc0fb443d1ed27553c982cafcb266c7794f4e09f0a7fdf3095947ff70451ed572b40
7
+ data.tar.gz: 6b6f0c4ca88806bd916e72fe24a6b6c0d6ba37fa563925ca751ac1bc9bc7b7e65430962c3d06c38be1a9b8d3150da496d1ed552dd62e7d639a1dbf9dff8e49e2
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ 0.4 -
2
+ - added install generator
3
+ - populated README
4
+ - created this file
data/README.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # LoggingByBean
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/logging_by_bean`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ I've grown tired of looking through Rails logs and wanted something more
4
+ readable. I found a nice treatment of this at https://cbpowell.wordpress.com/2013/08/09/beautiful-logging-for-ruby-on-rails-4/,
5
+ but I wanted something that was truly fire-and-forget. This gem handles the
6
+ installation of an initializer and modification of the application.rb file
7
+ to use nicer logging.
4
8
 
5
- TODO: Delete this and the text above, and describe your gem
9
+ NOTE: This is my first gem, and I'm doing this as much to learn how to
10
+ generate gems as anything else. Apologies if it's clunky.
6
11
 
7
12
  ## Installation
8
13
 
@@ -20,9 +25,15 @@ Or install it yourself as:
20
25
 
21
26
  $ gem install logging_by_bean
22
27
 
28
+ Then run the installer:
29
+
30
+ $ rails generator logging_by_bean:install
31
+
23
32
  ## Usage
24
33
 
25
- TODO: Write usage instructions here
34
+ Once you've rebundled with the gem and run the installation, you're good to go.
35
+ The gem consists of two side effects: it creates a logging_by_bean.rb initializer
36
+ file and it modifies your application.rb to switch out the default Rails logger.
26
37
 
27
38
  ## Development
28
39
 
@@ -1,44 +1,16 @@
1
1
  module LoggingByBean
2
2
  module Generators
3
3
  class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
4
5
 
5
6
  def create_configuration
6
- create_file "config/initializers/logging_by_bean.rb" do <<CONFIG_FILE_CONTENTS
7
-
8
- class ActiveSupport::Logger::SimpleFormatter
9
- SEVERITY_TO_TAG_MAP = {'DEBUG'=>'meh', 'INFO'=>'fyi', 'WARN'=>'hmm', 'ERROR'=>'wtf', 'FATAL'=>'omg', 'UNKNOWN'=>'???'}
10
- SEVERITY_TO_COLOR_MAP = {'DEBUG'=>'0;37', 'INFO'=>'32', 'WARN'=>'33', 'ERROR'=>'31', 'FATAL'=>'31', 'UNKNOWN'=>'37'}
11
- USE_HUMOROUS_SEVERITIES = false
12
-
13
- def call(severity, time, progname, msg)
14
- if USE_HUMOROUS_SEVERITIES
15
- formatted_severity = sprintf("%-3s",SEVERITY_TO_TAG_MAP[severity])
16
- else
17
- formatted_severity = sprintf("%-5s",severity)
18
- end
19
-
20
- call_details = Kernel.caller[4].gsub(/#{Rails.root}/, '')
21
- call_details.match /(.+):(.+):/
22
- filename = $1
23
- line = $2
24
-
25
- formatted_time = time.strftime("%Y-%m-%d %H:%M:%S.") << time.usec.to_s[0..2].rjust(3)
26
- color = SEVERITY_TO_COLOR_MAP[severity]
27
-
28
- base_msg = "\033[0;37m#{formatted_time}\033[0m [\033[#{color}m#{formatted_severity}\033[0m] #{msg.strip} "
29
-
30
- # if this is an error or fatal or unknown exception, include the file and line number
31
- if severity.match(/ERROR|FATAL|UNKNOWN/)
32
- base_msg += "(at: #{filename}:#{line} on pid:#{$$})\n"
33
- base_msg += Kernel.caller[4,10].map{ |l| ' ' * 35 + l.gsub(/#{Rails.root}/,'')}.join("\n")
34
- end
35
-
36
- return base_msg + "\n"
37
- end
38
- end
39
- CONFIG_FILE_CONTENTS
40
-
7
+ template "config_file_contents.rb", "config/initializers/logging_by_bean.rb"
8
+ end
41
9
 
10
+ def update_application_config
11
+ application 'config.logger = ActiveSupport::TaggedLogging.new(Logger.new(Pathname.new(Rails.root) + "log" + "#{Rails.env}.log"))' + "\n"
12
+ application '# (See config/logging_by_bean.rb for details)'
13
+ application '# Added automatically by logging_by_bean:install'
42
14
  end
43
15
  end
44
16
  end
@@ -0,0 +1,38 @@
1
+ # Logging by Bean Gem
2
+ #
3
+ # Provides better log messages than the default Rails logger. Inspired by
4
+ # https://cbpowell.wordpress.com/2013/08/09/beautiful-logging-for-ruby-on-rails-4/
5
+ class ActiveSupport::Logger::SimpleFormatter
6
+ SEVERITY_TO_TAG_MAP = {'DEBUG'=>'meh', 'INFO'=>'fyi', 'WARN'=>'hmm', 'ERROR'=>'wtf', 'FATAL'=>'omg', 'UNKNOWN'=>'???'}
7
+ SEVERITY_TO_COLOR_MAP = {'DEBUG'=>'0;37', 'INFO'=>'32', 'WARN'=>'33', 'ERROR'=>'31', 'FATAL'=>'31', 'UNKNOWN'=>'37'}
8
+ USE_HUMOROUS_SEVERITIES = false
9
+
10
+ def call(severity, time, progname, msg)
11
+ if USE_HUMOROUS_SEVERITIES
12
+ formatted_severity = sprintf("%-3s",SEVERITY_TO_TAG_MAP[severity])
13
+ else
14
+ formatted_severity = sprintf("%-5s",severity)
15
+ end
16
+
17
+ call_details = Kernel.caller[4].gsub(/#{Rails.root}/, '')
18
+ call_details.match /(.+):(.+):/
19
+ filename = $1
20
+ line = $2
21
+
22
+ formatted_time = time.strftime("%Y-%m-%d %H:%M:%S.") << time.usec.to_s[0..2].rjust(3)
23
+ color = SEVERITY_TO_COLOR_MAP[severity]
24
+
25
+ base_msg = "\033[0;37m#{formatted_time}\033[0m [\033[#{color}m#{formatted_severity}\033[0m] #{msg.strip} "
26
+
27
+ # if this is an error or fatal or unknown exception, include the file and line number
28
+ if severity.match(/ERROR|FATAL|UNKNOWN/)
29
+ base_msg += "(at: #{filename}:#{line} on pid:#{$$})\n"
30
+ # Note that starting at the 5th item in the call stack is an educated guess...it may need to
31
+ # be tweaked for your application. I'm also printing out the next 10 calls in the stack because
32
+ # I like that. You may want to change this to what suits you.
33
+ base_msg += Kernel.caller[4,10].map{ |l| ' ' * 35 + l.gsub(/#{Rails.root}/,'')}.join("\n")
34
+ end
35
+
36
+ return base_msg + "\n"
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module LoggingByBean
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
+ spec.add_dependency "thor"
30
31
  spec.add_development_dependency "bundler", "~> 1.9"
31
32
  spec.add_development_dependency "rake", "~> 10.0"
32
33
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logging_by_bean
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David L Bean
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-07 00:00:00.000000000 Z
11
+ date: 2016-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -48,6 +62,7 @@ files:
48
62
  - ".gitignore"
49
63
  - ".rspec"
50
64
  - ".travis.yml"
65
+ - CHANGELOG.md
51
66
  - Gemfile
52
67
  - LICENSE.txt
53
68
  - README.md
@@ -55,6 +70,7 @@ files:
55
70
  - bin/console
56
71
  - bin/setup
57
72
  - lib/generators/logging_by_bean/install/install_generator.rb
73
+ - lib/generators/logging_by_bean/install/templates/config_file_contents.rb
58
74
  - lib/logging_by_bean.rb
59
75
  - lib/logging_by_bean/version.rb
60
76
  - logging_by_bean.gemspec