hedgelog 0.1.13.alpha.1 → 0.2.0

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: 875b58fb26d8f6cffda3998b8ab3a5e6a9350895c8c6ac5fb01dc7eebdd9052e
4
- data.tar.gz: 16636d198b831e232abcbcce6f6d55584ce3e1f0bfb635366031c8fdc594364e
3
+ metadata.gz: cf8635e3a83a61c6935a28fb8ea0aa72b47aec7810d1ec125cc507ccef939179
4
+ data.tar.gz: 97e10f2f2dcc69ae7cf73cf3e2a95c352bb8f477129cf9babee1549b8eb9106a
5
5
  SHA512:
6
- metadata.gz: 0bc28f6bdbf2a8757ad1bcd9f66b55ff9511ef4b08ae5f070a301e5286ec9de17dab61329904b21c0b7e39670ae59b122300884bf24d95d85f5890cea1ec04f5
7
- data.tar.gz: c281aeca41ab0516f8a77c922c544d7a5e0ef676d69141f99a884d68f45df4d6664657163aee47864b47d6553e1789adaeb706d9b246f381f764294d19a0a4ec
6
+ metadata.gz: 30155e59568b520b423762cae723b7eccd604bc3552aaa39e42bf62bf6fdf9171c6527eee27a88a0c46089d696813d166b7c1612bd370b9b19ae9d0d72aa257b
7
+ data.tar.gz: bd4d609ab864a0879f12b4624a9a4aef371a509d8f9ba24d798cfd9b4de0edb92e73cd69360f796496760d885bd9f2aeee719ccb8e6ab392bf181ba0f38c39ef
data/.rubocop.yml CHANGED
@@ -2,77 +2,66 @@
2
2
  inherit_from: #{RUBOCOP_HOME}/config/default.yml
3
3
 
4
4
  AllCops:
5
- SuggestExtensions: false
6
- TargetRubyVersion: 2.7
5
+ TargetRubyVersion: 2.4
7
6
  Exclude:
8
7
  - 'vendor/**/*'
9
8
  - 'Guardfile'
10
- NewCops: enable
11
9
 
12
- Gemspec/RequireMFA:
13
- Enabled: false
14
-
15
- Layout/LeadingCommentSpace:
16
- Enabled: false
17
-
18
- Layout/LineLength:
19
- Max: 150
20
-
21
- Layout/SpaceInsideHashLiteralBraces:
22
- EnforcedStyle: no_space
23
-
24
- Metrics/BlockLength:
25
- Exclude:
26
- - 'spec/**/*.rb'
27
-
28
- Metrics/BlockNesting:
29
- Max: 4
30
-
31
- Metrics/ClassLength:
32
- Enabled: false
33
-
34
- Metrics/CyclomaticComplexity:
10
+ CyclomaticComplexity:
35
11
  Max: 15
36
12
 
37
- Metrics/MethodLength:
13
+ PerceivedComplexity:
14
+ Max: 20
15
+
16
+ MethodLength:
38
17
  Max: 30
39
18
 
40
- Metrics/PerceivedComplexity:
41
- Max: 20
19
+ ClassLength:
20
+ Enabled: false
42
21
 
43
- Style/AccessModifierDeclarations:
44
- EnforcedStyle: inline
22
+ LineLength:
23
+ Max: 150
45
24
 
46
- Style/CommentAnnotation:
25
+ WordArray:
47
26
  Enabled: false
48
27
 
49
- Style/Documentation:
28
+ LeadingCommentSpace:
50
29
  Enabled: false
51
30
 
52
- Style/FrozenStringLiteralComment:
31
+ CommentAnnotation:
53
32
  Enabled: false
54
33
 
55
- Style/HashConversion:
56
- Enabled: true
34
+ Documentation:
35
+ Enabled: false
57
36
 
58
- Style/Next:
37
+ Next:
59
38
  Enabled: false
60
39
 
61
- Style/OptionalArguments:
40
+ OptionalArguments:
62
41
  Enabled: false
63
42
 
64
- Style/RedundantStringEscape:
65
- Enabled: true
43
+ SpaceInsideHashLiteralBraces:
44
+ EnforcedStyle: no_space
66
45
 
67
- Style/SignalException:
46
+ SignalException:
68
47
  EnforcedStyle: only_raise
69
48
 
49
+ TrivialAccessors:
50
+ AllowPredicates: true
51
+
52
+ BlockNesting:
53
+ Max: 4
54
+
70
55
  Style/StringLiterals:
71
56
  Enabled: true
72
57
  EnforcedStyle: single_quotes
73
58
 
74
- Style/TrivialAccessors:
75
- AllowPredicates: true
59
+ Metrics/BlockLength:
60
+ Exclude:
61
+ - 'spec/**/*.rb'
76
62
 
77
- Style/WordArray:
78
- Enabled: false
63
+ Style/FrozenStringLiteralComment:
64
+ Enabled: false
65
+
66
+ Style/AccessModifierDeclarations:
67
+ EnforcedStyle: inline
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7
1
+ 2.4
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  cache: bundler
3
- rvm: 2.7
3
+ rvm: 2.4
4
4
  before_install:
5
5
  - gem update --system
6
6
  - gem install bundler
data/bin/profile CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env ruby
1
2
 
2
3
  require 'bundler/setup'
3
4
  require 'hedgelog'
data/hedgelog.gemspec CHANGED
@@ -5,13 +5,12 @@ require 'hedgelog/version'
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'hedgelog'
7
7
  spec.version = Hedgelog::VERSION
8
- spec.required_ruby_version = '>= 2.7.0'
9
8
  spec.licenses = ['MIT']
10
9
  spec.authors = ['Jeff Utter']
11
10
  spec.email = ['jeff.utter@firespring.com']
12
11
 
13
12
  spec.homepage = 'https://github.com/firespring/hedgelog'
14
- spec.summary = 'A structured JSON logger for Ruby'
13
+ spec.summary = 'A strucutred JSON logger for Ruby'
15
14
  spec.description = 'An opinionated/structured JSON logger for Ruby'
16
15
 
17
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -7,13 +7,13 @@ class Hedgelog
7
7
  end
8
8
 
9
9
  def normalize_struct(struct)
10
- normalize_hash(struct.each_pair.to_a.to_h)
10
+ normalize_hash(Hash[struct.each_pair.to_a])
11
11
  end
12
12
 
13
13
  def normalize_hash(hash)
14
- hash.transform_values do |val|
15
- normalize_thing(val)
16
- end
14
+ Hash[hash.map do |key, val|
15
+ [key, normalize_thing(val)]
16
+ end]
17
17
  end
18
18
 
19
19
  def normalize_array(array)
@@ -3,9 +3,16 @@ require 'hedgelog/scrub_replacement'
3
3
  class Hedgelog
4
4
  class Scrubber
5
5
  def initialize(replacements = nil)
6
- @replacements = replacements || [
7
- ScrubReplacement.new('password', '**********')
8
- ]
6
+ @replacements = [ScrubReplacement.new('password', '**********')]
7
+ unless replacements.nil?
8
+ replacements.each do |x|
9
+ if x.instance_of?(ScrubReplacement)
10
+ @replacements << x
11
+ else
12
+ @replacements << ScrubReplacement.new(x,'**********')
13
+ end
14
+ end
15
+ end
9
16
  end
10
17
 
11
18
  def scrub(data)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Hedgelog
4
- VERSION = '0.1.13.alpha.1'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/hedgelog.rb CHANGED
@@ -25,12 +25,12 @@ class Hedgelog
25
25
  attr_reader :level
26
26
  attr_writer :app
27
27
 
28
- def initialize(logdev = $stdout, shift_age = nil, shift_size = nil)
28
+ def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil, cleaner=nil)
29
29
  @level = LEVELS[:debug]
30
30
  @channel = nil
31
31
  @logdev = nil
32
32
  @app = nil
33
- @scrubber = Hedgelog::Scrubber.new
33
+ @scrubber = Hedgelog::Scrubber.new(cleaner)
34
34
  @normalizer = Hedgelog::Normalizer.new
35
35
  @channel_context = Hedgelog::Context.new(@scrubber, @normalizer)
36
36
 
@@ -48,7 +48,6 @@ class Hedgelog
48
48
  @level = int_level
49
49
  end
50
50
 
51
- # rubocop:disable Metrics/ParameterLists
52
51
  def add(severity = LEVELS[:unknown], message = nil, progname = nil, context = {}, &block)
53
52
  return true if (@logdev.nil? && @channel.nil?) || severity < @level
54
53
 
@@ -63,7 +62,6 @@ class Hedgelog
63
62
 
64
63
  @channel&.add(severity, nil, progname, context)
65
64
  end
66
- # rubocop:enable Metrics/ParameterLists
67
65
 
68
66
  def []=(key, val)
69
67
  @channel_context[key] = val
@@ -149,7 +147,7 @@ class Hedgelog
149
147
  data[:caller] = debugharder(caller(4, 1).first) if debug?
150
148
  data = extract_top_level_keys(data)
151
149
 
152
- @logdev.write("#{Yajl::Encoder.encode(data)}\n")
150
+ @logdev.write(Yajl::Encoder.encode(data) + "\n")
153
151
  true
154
152
  end
155
153
 
@@ -178,7 +176,7 @@ class Hedgelog
178
176
  whence = $LOAD_PATH.find { |p| path.start_with?(p) }
179
177
  file = if whence
180
178
  # Remove the RUBYLIB path portion of the full file name
181
- path[whence.length + 1..]
179
+ path[whence.length + 1..-1]
182
180
  else
183
181
  # We get here if the path is not in $:
184
182
  path
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hedgelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13.alpha.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Utter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-09 00:00:00.000000000 Z
11
+ date: 2020-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby
@@ -68,10 +68,6 @@ files:
68
68
  - lib/hedgelog/scrub_replacement.rb
69
69
  - lib/hedgelog/scrubber.rb
70
70
  - lib/hedgelog/version.rb
71
- - script/.bash_helpers
72
- - script/.env.colors
73
- - script/.exit_handler
74
- - script/publish.sh
75
71
  homepage: https://github.com/firespring/hedgelog
76
72
  licenses:
77
73
  - MIT
@@ -84,15 +80,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
80
  requirements:
85
81
  - - ">="
86
82
  - !ruby/object:Gem::Version
87
- version: 2.7.0
83
+ version: '0'
88
84
  required_rubygems_version: !ruby/object:Gem::Requirement
89
85
  requirements:
90
- - - ">"
86
+ - - ">="
91
87
  - !ruby/object:Gem::Version
92
- version: 1.3.1
88
+ version: '0'
93
89
  requirements: []
94
- rubygems_version: 3.1.4
90
+ rubygems_version: 3.0.3
95
91
  signing_key:
96
92
  specification_version: 4
97
- summary: A structured JSON logger for Ruby
93
+ summary: A strucutred JSON logger for Ruby
98
94
  test_files: []
data/script/.bash_helpers DELETED
@@ -1,47 +0,0 @@
1
- #!/bin/bash
2
- base_dir=$(dirname $BASH_SOURCE)
3
- . ${base_dir}/.env.colors
4
-
5
- die()
6
- {
7
- echo
8
- set_red
9
- echo >&2 "$@"
10
- reset_colors
11
- exit 2
12
- }
13
-
14
- finish()
15
- {
16
- echo
17
- set_white
18
- echo "$@"
19
- reset_colors
20
- exit 0
21
- }
22
-
23
- confirm()
24
- {
25
- prompt="${1:-Are you sure? [y/N]}"
26
-
27
- set_yellow
28
- echo -n "$prompt "
29
- reset_colors
30
-
31
- if [ "${NO_INPUT:-}" == 'true' ]
32
- then
33
- # Continue if 'NO_INPUT' has been set
34
- true
35
- else
36
- # call with a prompt string or use a default
37
- read -r response
38
- case "$response" in
39
- [yY][eE][sS]|[yY])
40
- true
41
- ;;
42
- *)
43
- false
44
- ;;
45
- esac
46
- fi
47
- }
data/script/.env.colors DELETED
@@ -1,94 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo_red()
4
- {
5
- set_red
6
- echo "$@"
7
- reset_colors
8
- }
9
-
10
- set_red()
11
- {
12
- echo -ne "\033[31;1m"
13
- }
14
-
15
- set_background_red()
16
- {
17
- echo -ne "\033[41;1m"
18
- }
19
-
20
- set_light_red()
21
- {
22
- echo -ne "\033[91;1m"
23
- }
24
-
25
- echo_green()
26
- {
27
- set_green
28
- echo "$@"
29
- reset_colors
30
- }
31
-
32
- set_green()
33
- {
34
- echo -ne "\033[32;1m"
35
- }
36
-
37
- set_background_green()
38
- {
39
- echo -ne "\033[42;1m"
40
- }
41
-
42
- set_light_green()
43
- {
44
- echo -ne "\033[92;1m"
45
- }
46
-
47
- echo_yellow()
48
- {
49
- set_yellow
50
- echo "$@"
51
- reset_colors
52
- }
53
-
54
- set_yellow()
55
- {
56
- echo -ne "\033[33;1m"
57
- }
58
-
59
- set_background_yellow()
60
- {
61
- echo -ne "\033[43;1m"
62
- }
63
-
64
- set_light_yellow()
65
- {
66
- echo -ne "\033[93;1m"
67
- }
68
-
69
- set_white()
70
- {
71
- echo -ne "\033[37;1m"
72
- }
73
-
74
- set_background_white()
75
- {
76
- echo -ne "\033[47;1m"
77
- }
78
-
79
- echo_light_white()
80
- {
81
- set_light_white
82
- echo "$@"
83
- reset_colors
84
- }
85
-
86
- set_light_white()
87
- {
88
- echo -ne "\033[97;1m"
89
- }
90
-
91
- reset_colors()
92
- {
93
- echo -ne "\033[0m"
94
- }
data/script/.exit_handler DELETED
@@ -1,50 +0,0 @@
1
- #!/bin/bash
2
- base_dir=$(dirname $BASH_SOURCE)
3
- . ${base_dir}/.env.colors
4
-
5
- exit_handler()
6
- {
7
- RETVAL=$?
8
-
9
- echo
10
- if [ $RETVAL -eq 0 ]
11
- then
12
- echo_green " Command [ ${BASH_SOURCE[1]} ] completed successfully"
13
- else
14
- set +o xtrace
15
- set_background_red
16
- echo " Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]} - '${BASH_COMMAND}' exited with status $RETVAL"
17
-
18
- # Print out the stack trace
19
- if [ ${#FUNCNAME[@]} -gt 2 ]
20
- then
21
- echo
22
- echo " Stacktrace:"
23
- for ((i=1;i<${#FUNCNAME[@]}-1;i++))
24
- do
25
- echo " $i: ${BASH_SOURCE[$i+1]}:${BASH_LINENO[$i]} ${FUNCNAME[$i]}(...)"
26
- done
27
- fi
28
- reset_colors
29
- fi
30
-
31
- echo
32
- exit $RETVAL
33
- }
34
-
35
- int_handler()
36
- {
37
- echo
38
- echo_yellow " Ctrl-C received, exiting"
39
- echo
40
- exit 130
41
- }
42
-
43
- SHOULD_ADD_EXIT_HANDLER=${SHOULD_ADD_EXIT_HANDLER:-}
44
- if [ "$SHOULD_ADD_EXIT_HANDLER" = '' ]
45
- then
46
- trap exit_handler EXIT
47
- trap int_handler INT
48
- fi
49
- export SHOULD_ADD_EXIT_HANDLER=1
50
- set -o errtrace
data/script/publish.sh DELETED
@@ -1,161 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- base_dir=$(dirname $BASH_SOURCE)
4
- . ${base_dir}/.env.colors
5
- . ${base_dir}/.exit_handler
6
- . ${base_dir}/.bash_helpers
7
-
8
- HEDGELOG_DIR=$(readlink -f ${base_dir}/../)
9
-
10
- HEDGELOG_VERSION_FILE="${HEDGELOG_DIR}/lib/hedgelog/version.rb"
11
-
12
- HEDGELOG_VERSION=${HEDGELOG_VERSION:-}
13
- VALID_VERSION_FORMAT="^[0-9]+.[0-9]+.[0-9]+(\.alpha.[0-9+])?$"
14
-
15
- RUBYGEMS_CRED_FILE=".gem/credentials"
16
- RUBYGEMS_USER_CRED_FILE="${HOME}/${RUBYGEMS_CRED_FILE}"
17
- RUBYGEMS_ROOT_CRED_FILE="/root/${RUBYGEMS_CRED_FILE}"
18
- RUBYGEMS_CRED_VOLUME="${RUBYGEMS_USER_CRED_FILE}:${RUBYGEMS_ROOT_CRED_FILE}"
19
- touch "${RUBYGEMS_USER_CRED_FILE}"
20
- chmod 600 "${RUBYGEMS_USER_CRED_FILE}"
21
-
22
-
23
- usage() {
24
- echo "USAGE: $(basename "$0")"
25
- echo
26
- echo " Input parameters can be specified via environmental variables:"
27
- echo " HEDGELOG_VERSION (default: <none>) must be in the format '${VALID_VERSION_FORMAT}'"
28
- echo
29
- echo " the following will update the hedgelog version to 4.8.1.alpha.2"
30
- echo " HEDGELOG_VERSION=4.8.1.alpha.2 $(basename "$0")"
31
- }
32
-
33
- validate()
34
- {
35
- [ "$*" == "" ] || finish "$(usage)"
36
-
37
- found_version_to_update=''
38
- STARTING_HEDGELOG_VERSION=$(get_gem_version "${HEDGELOG_VERSION_FILE}")
39
- if [ "${HEDGELOG_VERSION}" == "" ]
40
- then
41
- echo_light_white "No hedgelog version given. Leaving at [ ${STARTING_HEDGELOG_VERSION} ]"
42
- else
43
- found_version_to_update='true'
44
- validate_version_format "${HEDGELOG_VERSION}" || die "Version [ ${HEDGELOG_VERSION} ] must be in the format ${VALID_VERSION_FORMAT}"
45
- echo_light_white "This will update the hedgelog version from [ ${STARTING_HEDGELOG_VERSION} ] to [ ${HEDGELOG_VERSION} ]."
46
- fi
47
-
48
- if [ "${found_version_to_update}" == 'true' ]
49
- then
50
- echo
51
- confirm " Do you wish to continue? (y/n)" || finish "Exiting..."
52
- else
53
- echo
54
- echo_yellow "No versions given to update"
55
- echo
56
- exit 0
57
- fi
58
- }
59
-
60
- validate_version_format()
61
- {
62
- local version=$1
63
- echo "${version}" | grep -qE "${VALID_VERSION_FORMAT}"
64
- }
65
-
66
- main()
67
- {
68
- echo
69
- validate $*
70
- echo
71
-
72
- hedgelog_gem_update=""
73
- if [ "${HEDGELOG_VERSION}" != "" ]
74
- then
75
- hedgelog_gem_update="hedgelog=$(normalize_gem_version "${HEDGELOG_VERSION}")"
76
- publish_hedgelog "${HEDGELOG_VERSION}"
77
- fi
78
-
79
- # GEMS="${hedgelog_gem_update}" ${base_dir}/update_gems.sh
80
-
81
- # I'm doing this because I don't want persistent cred files on our dev servers which would give access to publish
82
- # gems - in case a dev server was ever compromised
83
- [[ -f ${RUBYGEMS_USER_CRED_FILE} ]] && rm -f ${RUBYGEMS_USER_CRED_FILE}
84
-
85
- echo
86
- echo_light_white "Hedgelog has successfully been upgraded from version [ ${STARTING_HEDGELOG_VERSION} ] to [ ${HEDGELOG_VERSION} ]"
87
- echo
88
- }
89
-
90
- publish_hedgelog()
91
- {
92
- local desired_version=$1
93
-
94
- # Change the version in the file
95
- update_gem_version "${HEDGELOG_VERSION_FILE}" "${desired_version}"
96
-
97
- # Make sure hedgelog is up to date
98
- echo "Checking to see if the hedgelog gem needs to be published..."
99
-
100
- # versions="$(MSYS_NO_PATHCONV=1 docker-compose ${COMPOSE_FILES} run --no-deps -v "${RUBYGEMS_CRED_VOLUME}" --entrypoint /bin/sh client-ruby -c "gem query --all --pre --remote stbaldricks")"
101
- versions=`gem query --all --pre --remote hedgelog`
102
- if echo "${versions}" | grep -Eq "(\(| )${desired_version}(,|\))"
103
- then
104
- # Make sure the user expected this to have already been published
105
- confirm " Hedgelog gem version ${desired_version} has already been published. Is this expected? (y/n)" || finish "Exiting..."
106
- else
107
- # Publish the gem
108
- echo "Starting ruby container to build and publish gem"
109
- # MSYS_NO_PATHCONV=1 docker-compose ${COMPOSE_FILES} run --no-deps -v "${RUBYGEMS_CRED_VOLUME}" --entrypoint /bin/sh client-ruby -c "gem build stbaldricks.gemspec && gem push stbaldricks-${desired_version}.gem"
110
- gem build hedgelog.gemspec && gem push "hedgelog-${desired_version}.gem"
111
- fi
112
- echo
113
- }
114
-
115
- get_gem_version()
116
- {
117
- local version_file=$1
118
- normalize_version "$(sed -nre "s@.*VERSION.*=.*('|\")(.*)('|\").*@\2@gp" ${version_file})"
119
- }
120
-
121
- update_gem_version()
122
- {
123
- local version_file=$1
124
- local version=$2
125
- local gem_version=$(normalize_gem_version "${version}")
126
-
127
- # Try to update the gem version in the file
128
- sed -i -re "s@(.*VERSION.*=.*)('|\")(.*)('|\")(.*)@\1\2${gem_version}\4\5@g" "${version_file}"
129
-
130
- # Verify the version is now what we wanted
131
- updated_version=$(get_gem_version "${version_file}")
132
- if [ "${updated_version}" != "${version}" ]
133
- then
134
- die "Unable to update version [ ${version} ] in [ ${version_file} ] (got ${updated_version})"
135
- fi
136
- git add "${version_file}"
137
- }
138
-
139
- normalize_version()
140
- {
141
- local version=$1
142
- echo $version | sed -re "s@([0-9]).(alpha)@\1.\2@g"
143
- }
144
-
145
- normalize_gem_version()
146
- {
147
- local version=$1
148
- echo $version | sed -re "s@([0-9]).(alpha)@\1.\2@g"
149
- }
150
-
151
- strip_alpha()
152
- {
153
- local starting_version=$1
154
- echo ${starting_version} | sed -re 's@(.*).alpha.[0-9]+@\1@g'
155
- }
156
-
157
- export -f get_gem_version strip_alpha
158
-
159
- # Only run main if this script isn't currently being sourced
160
- $(return >/dev/null 2>&1) || main $*
161
-