hedgelog 0.2.1.alpha1 → 0.2.1.alpha.2

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: 9cc391e68818c718c16a61d8f2ea7451e1b6946999bd9d522f4f4af247b03c64
4
- data.tar.gz: 5cdd8ab414e100af8f2f704d69f53d98535e94da64326de379691ba865cf0b3c
3
+ metadata.gz: a915a38ceea8fdbc48a652f94b75493d7010a8c1939153649efb75e9223a228f
4
+ data.tar.gz: 5981f5963d84a73e9a745bdbd1f04a0be9bf1fee8c4137fcf1074d8d74073795
5
5
  SHA512:
6
- metadata.gz: a53dee188a2b3faa410869b539883622817879e29ef38367526124a7544b00b4280aa0856ce8681dfb0b6e4c63eae0ae6d7a6f3c931bba87c153e2420f8085ff
7
- data.tar.gz: d57485bb04c42ae7137012c2f8b51906398bfeb5e2ea4f2851d152355db6c3abaee1f91c8ca43d004ababc85ed50112353bf33da9deebc998704e4db46b11c4f
6
+ metadata.gz: 351dc9f6f84d0cc2ba11074b75c07f99eb2bdc7232d3036f88971a6bd109a97f2bb7276de799caa765f6b8cf41b716a93dec3302a60885ee675eaa2664561f2d
7
+ data.tar.gz: 25d7ee05b1e0727b659cce6c34df0f17efcd773db5540df0edb34b225e179aafe8549cbe818227cb63c981e28c082ee70067ab4e346ab1e83e25c8e5035ca63c
data/.rubocop.yml CHANGED
@@ -2,66 +2,77 @@
2
2
  inherit_from: #{RUBOCOP_HOME}/config/default.yml
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 2.4
5
+ SuggestExtensions: false
6
+ TargetRubyVersion: 2.7
6
7
  Exclude:
7
8
  - 'vendor/**/*'
8
9
  - 'Guardfile'
10
+ NewCops: enable
9
11
 
10
- CyclomaticComplexity:
11
- Max: 15
12
-
13
- PerceivedComplexity:
14
- Max: 20
15
-
16
- MethodLength:
17
- Max: 30
12
+ Gemspec/RequireMFA:
13
+ Enabled: false
18
14
 
19
- ClassLength:
15
+ Layout/LeadingCommentSpace:
20
16
  Enabled: false
21
17
 
22
- LineLength:
18
+ Layout/LineLength:
23
19
  Max: 150
24
20
 
25
- WordArray:
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:
26
32
  Enabled: false
27
33
 
28
- LeadingCommentSpace:
34
+ Metrics/CyclomaticComplexity:
35
+ Max: 15
36
+
37
+ Metrics/MethodLength:
38
+ Max: 30
39
+
40
+ Metrics/PerceivedComplexity:
41
+ Max: 20
42
+
43
+ Style/AccessModifierDeclarations:
44
+ EnforcedStyle: inline
45
+
46
+ Style/CommentAnnotation:
29
47
  Enabled: false
30
48
 
31
- CommentAnnotation:
49
+ Style/Documentation:
32
50
  Enabled: false
33
51
 
34
- Documentation:
52
+ Style/FrozenStringLiteralComment:
35
53
  Enabled: false
36
54
 
37
- Next:
55
+ Style/HashConversion:
56
+ Enabled: true
57
+
58
+ Style/Next:
38
59
  Enabled: false
39
60
 
40
- OptionalArguments:
61
+ Style/OptionalArguments:
41
62
  Enabled: false
42
63
 
43
- SpaceInsideHashLiteralBraces:
44
- EnforcedStyle: no_space
64
+ Style/RedundantStringEscape:
65
+ Enabled: true
45
66
 
46
- SignalException:
67
+ Style/SignalException:
47
68
  EnforcedStyle: only_raise
48
69
 
49
- TrivialAccessors:
50
- AllowPredicates: true
51
-
52
- BlockNesting:
53
- Max: 4
54
-
55
70
  Style/StringLiterals:
56
71
  Enabled: true
57
72
  EnforcedStyle: single_quotes
58
73
 
59
- Metrics/BlockLength:
60
- Exclude:
61
- - 'spec/**/*.rb'
62
-
63
- Style/FrozenStringLiteralComment:
64
- Enabled: false
74
+ Style/TrivialAccessors:
75
+ AllowPredicates: true
65
76
 
66
- Style/AccessModifierDeclarations:
67
- EnforcedStyle: inline
77
+ Style/WordArray:
78
+ Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4
1
+ 2.7
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  cache: bundler
3
- rvm: 2.4
3
+ rvm: 2.7
4
4
  before_install:
5
5
  - gem update --system
6
6
  - gem install bundler
data/bin/profile CHANGED
@@ -17,4 +17,4 @@ result.eliminate_methods!([/Integer#times/])
17
17
 
18
18
  # printer = RubyProf::GraphPrinter.new(result)
19
19
  printer = RubyProf::FlatPrinterWithLineNumbers.new(result)
20
- printer.print(STDOUT)
20
+ printer.print($stdout)
data/hedgelog.gemspec CHANGED
@@ -5,12 +5,13 @@ 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'
8
9
  spec.licenses = ['MIT']
9
10
  spec.authors = ['Jeff Utter']
10
11
  spec.email = ['jeff.utter@firespring.com']
11
12
 
12
13
  spec.homepage = 'https://github.com/firespring/hedgelog'
13
- spec.summary = 'A strucutred JSON logger for Ruby'
14
+ spec.summary = 'A structured JSON logger for Ruby'
14
15
  spec.description = 'An opinionated/structured JSON logger for Ruby'
15
16
 
16
17
  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(Hash[struct.each_pair.to_a])
10
+ normalize_hash(struct.each_pair.to_a.to_h)
11
11
  end
12
12
 
13
13
  def normalize_hash(hash)
14
- Hash[hash.map do |key, val|
15
- [key, normalize_thing(val)]
16
- end]
14
+ hash.transform_values do |val|
15
+ normalize_thing(val)
16
+ end
17
17
  end
18
18
 
19
19
  def normalize_array(array)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Hedgelog
4
- VERSION = '0.2.1.alpha1'
4
+ VERSION = '0.2.1.alpha.2'
5
5
  end
data/lib/hedgelog.rb CHANGED
@@ -25,7 +25,8 @@ 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, cleaner = nil)
28
+ # rubocop:disable Metrics/ParameterLists
29
+ def initialize(logdev = $stdout, shift_age = nil, shift_size = nil, cleaner = nil)
29
30
  @level = LEVELS[:debug]
30
31
  @channel = nil
31
32
  @logdev = nil
@@ -40,6 +41,7 @@ class Hedgelog
40
41
  @logdev = Logger::LogDevice.new(logdev, shift_age: shift_age, shift_size: shift_size)
41
42
  end
42
43
  end
44
+ # rubocop:enable Metrics/ParameterLists
43
45
 
44
46
  def level=(level)
45
47
  int_level = level_to_int(level)
@@ -48,6 +50,7 @@ class Hedgelog
48
50
  @level = int_level
49
51
  end
50
52
 
53
+ # rubocop:disable Metrics/ParameterLists
51
54
  def add(severity = LEVELS[:unknown], message = nil, progname = nil, context = {}, &block)
52
55
  return true if (@logdev.nil? && @channel.nil?) || severity < @level
53
56
 
@@ -62,6 +65,7 @@ class Hedgelog
62
65
 
63
66
  @channel&.add(severity, nil, progname, context)
64
67
  end
68
+ # rubocop:enable Metrics/ParameterLists
65
69
 
66
70
  def []=(key, val)
67
71
  @channel_context[key] = val
@@ -147,7 +151,7 @@ class Hedgelog
147
151
  data[:caller] = debugharder(caller(4, 1).first) if debug?
148
152
  data = extract_top_level_keys(data)
149
153
 
150
- @logdev.write(Yajl::Encoder.encode(data) + "\n")
154
+ @logdev.write("#{Yajl::Encoder.encode(data)}\n")
151
155
  true
152
156
  end
153
157
 
@@ -176,7 +180,7 @@ class Hedgelog
176
180
  whence = $LOAD_PATH.find { |p| path.start_with?(p) }
177
181
  file = if whence
178
182
  # Remove the RUBYLIB path portion of the full file name
179
- path[whence.length + 1..-1]
183
+ path[whence.length + 1..]
180
184
  else
181
185
  # We get here if the path is not in $:
182
186
  path
@@ -0,0 +1,47 @@
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
+ }
@@ -0,0 +1,94 @@
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
+ }
@@ -0,0 +1,50 @@
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 ADDED
@@ -0,0 +1,161 @@
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
+
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.2.1.alpha1
4
+ version: 0.2.1.alpha.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Utter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-08 00:00:00.000000000 Z
11
+ date: 2022-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby
@@ -68,6 +68,10 @@ 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
71
75
  homepage: https://github.com/firespring/hedgelog
72
76
  licenses:
73
77
  - MIT
@@ -80,15 +84,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
84
  requirements:
81
85
  - - ">="
82
86
  - !ruby/object:Gem::Version
83
- version: '0'
87
+ version: 2.7.0
84
88
  required_rubygems_version: !ruby/object:Gem::Requirement
85
89
  requirements:
86
90
  - - ">"
87
91
  - !ruby/object:Gem::Version
88
92
  version: 1.3.1
89
93
  requirements: []
90
- rubygems_version: 3.0.3
94
+ rubygems_version: 3.0.9
91
95
  signing_key:
92
96
  specification_version: 4
93
- summary: A strucutred JSON logger for Ruby
97
+ summary: A structured JSON logger for Ruby
94
98
  test_files: []