berkeley_library-logging 0.2.2 → 0.2.3

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
2
  SHA256:
3
- metadata.gz: 1c60520b7195f791061df89827e2a6c7b00ac1352262d7cf750511a125d30c02
4
- data.tar.gz: bcb3ddb18cb7bfa442a52bbe5116316b74ae7f6d7c4e2e414812a5838e4a84fa
3
+ metadata.gz: 2d520b09c106d1976a6d47efb671ba9c9ee8696f573e4aeb2571cdd1706744ae
4
+ data.tar.gz: f801c8ee42f5e4cfee28f4148775b2142d3dfe26bb0f6e3633292bb7cd5ef747
5
5
  SHA512:
6
- metadata.gz: '085e7cc941c61021cfa90d6c2f2cb7c53d05d8900dc067aa87cc2ba6302e96032e31683ff3e9d1d2ba62770556569ebda96566f81c8eee0eec50c7683ed00b36'
7
- data.tar.gz: 0ca861efeca0e9b7c94cf87bbf410a0d826cfd9a1918e5b351148f102a9b8bbc64e4e7979aeb6044ab122def7d6bf82e798447ed19fe36ef7a34b47fa502ad61
6
+ metadata.gz: 3ecb69bb4608198f67eed2b4215ddc105096f86a469b504f72ff331ef3380616afe83c9fe0a63f375f09453f7d23eca8a8032b6e8452db8ae84811ad079e996f
7
+ data.tar.gz: f9c681893d8e25c2e1588fa5fa51b44db09cf8c782bf650a9b4606b9ffa26f380a6678155a23692025f149791684ec2201e1ec41c9c90bd8ea2c1ea39f957aba
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.2.3 (2021-09-02)
2
+
3
+ - JSON formatter now strips all ANSI 7-bit C1 escapes from strings
4
+ (fixes [#1](https://github.com/BerkeleyLibrary/logging/issues/1) properly)
5
+
1
6
  # 0.2.2 (2021-09-02)
2
7
 
3
8
  - JSON formatter now strips ANSI color escapes from strings
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # BerkeleyLibrary::Logging
2
2
 
3
3
  [![Build Status](https://github.com/BerkeleyLibrary/logging/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/BerkeleyLibrary/logging/actions/workflows/build.yml)
4
- [![Gem Version](https://img.shields.io/gem/v/berkeley_library-logging.svg)](https://github.com/BerkeleyLibrary/logging/releases)
4
+ [![Gem Version](https://img.shields.io/gem/v/berkeley_library-logging.svg)](https://rubygems.org/gems/berkeley_library-logging/)
5
5
 
6
6
  Opinionated logging for UCB Library IT Rails applications.
7
7
 
@@ -34,7 +34,6 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency 'brakeman', '~> 4.9'
35
35
  spec.add_development_dependency 'bundle-audit', '~> 0.1'
36
36
  spec.add_development_dependency 'ci_reporter_rspec', '~> 1.0'
37
- spec.add_development_dependency 'colorize', '~> 0.8'
38
37
  spec.add_development_dependency 'dotenv', '~> 2.7'
39
38
  spec.add_development_dependency 'irb', '~> 1.2' # workaroundfor https://github.com/bundler/bundler/issues/6929
40
39
  spec.add_development_dependency 'listen', '>= 3.0.5', '< 3.2'
@@ -5,6 +5,10 @@ module BerkeleyLibrary
5
5
  module Formatters
6
6
 
7
7
  class << self
8
+
9
+ # See https://stackoverflow.com/a/14693789/27358
10
+ ANSI_7C1_RE = %r{\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])}.freeze
11
+
8
12
  def new_json_formatter
9
13
  Bunyan.new
10
14
  end
@@ -24,11 +28,11 @@ module BerkeleyLibrary
24
28
  { msg: message }
25
29
  end
26
30
 
27
- def decolorize(message)
31
+ def strip_ansi_escapes(message)
28
32
  return unless message
29
- return message.uncolorize if message.is_a?(String)
30
- return message.map { |v| decolorize(v) } if message.is_a?(Array)
31
- return message.transform_values { |v| decolorize(v) } if message.is_a?(Hash)
33
+ return message.gsub(ANSI_7C1_RE, '') if message.is_a?(String)
34
+ return message.map { |v| strip_ansi_escapes(v) } if message.is_a?(Array)
35
+ return message.transform_values { |v| strip_ansi_escapes(v) } if message.is_a?(Hash)
32
36
 
33
37
  message
34
38
  end
@@ -87,7 +91,7 @@ module BerkeleyLibrary
87
91
 
88
92
  def _call(severity, time, progname, data)
89
93
  original_data = Formatters.ensure_hash(data)
90
- decolorized_data = Formatters.decolorize(original_data)
94
+ decolorized_data = Formatters.strip_ansi_escapes(original_data)
91
95
 
92
96
  # Ougai::Formatters::Bunyan replaces the human-readable severity string
93
97
  # with a numeric level, so we add it here as a separate attribute
@@ -7,7 +7,7 @@ module BerkeleyLibrary
7
7
  SUMMARY = 'Opinionated Ruby/Rails logging for UC Berkeley Library'.freeze
8
8
  DESCRIPTION = 'A gem providing shared logging code for UC Berkeley Library gems and Rails applications'.freeze
9
9
  LICENSE = 'MIT'.freeze
10
- VERSION = '0.2.2'.freeze
10
+ VERSION = '0.2.3'.freeze
11
11
  HOMEPAGE = 'https://github.com/BerkeleyLibrary/logging'.freeze
12
12
 
13
13
  private_class_method :new
@@ -67,6 +67,15 @@ module BerkeleyLibrary
67
67
  expect(additional_data['another_string']).to eq(expected_string)
68
68
  expect(additional_data['more_strings']).to eq([expected_string, expected_string])
69
69
  end
70
+
71
+ it 'removes ANSI formatting from ActiveRecord logs' do
72
+ original = " \e[1m\e[36mLendingItem Load (2.0ms)\e[0m \e[1m\e[34mSELECT \"lending_items\".* FROM \"lending_items\" WHERE \"lending_items\".\"directory\" = $1 LIMIT $2\e[0m [[\"directory\", \"b135297126_C068087930\"], [\"LIMIT\", 1]]"
73
+ expected = ' LendingItem Load (2.0ms) SELECT "lending_items".* FROM "lending_items" WHERE "lending_items"."directory" = $1 LIMIT $2 [["directory", "b135297126_C068087930"], ["LIMIT", 1]]'
74
+ logger.info(original)
75
+ logged_json = JSON.parse(out.string)
76
+ msg = logged_json['msg']
77
+ expect(msg).to eq(expected)
78
+ end
70
79
  end
71
80
 
72
81
  describe :ensure_hash do
@@ -65,6 +65,15 @@ module BerkeleyLibrary
65
65
  expect(additional_data['another_string']).to eq(expected_string)
66
66
  expect(additional_data['more_strings']).to eq([expected_string, expected_string])
67
67
  end
68
+
69
+ it 'removes ANSI formatting from ActiveRecord logs' do
70
+ original = " \e[1m\e[36mLendingItem Load (2.0ms)\e[0m \e[1m\e[34mSELECT \"lending_items\".* FROM \"lending_items\" WHERE \"lending_items\".\"directory\" = $1 LIMIT $2\e[0m [[\"directory\", \"b135297126_C068087930\"], [\"LIMIT\", 1]]"
71
+ expected = ' LendingItem Load (2.0ms) SELECT "lending_items".* FROM "lending_items" WHERE "lending_items"."directory" = $1 LIMIT $2 [["directory", "b135297126_C068087930"], ["LIMIT", 1]]'
72
+ logger.info(original)
73
+ logged_json = JSON.parse(out.string)
74
+ msg = logged_json['msg']
75
+ expect(msg).to eq(expected)
76
+ end
68
77
  end
69
78
 
70
79
  describe :ensure_hash do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkeley_library-logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '1.0'
125
- - !ruby/object:Gem::Dependency
126
- name: colorize
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '0.8'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '0.8'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: dotenv
141
127
  requirement: !ruby/object:Gem::Requirement