Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 45 additions & 34 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,77 @@
inherit_from: #{RUBOCOP_HOME}/config/default.yml

AllCops:
TargetRubyVersion: 2.4
SuggestExtensions: false
TargetRubyVersion: 2.7
Exclude:
- 'vendor/**/*'
- 'Guardfile'
NewCops: enable

CyclomaticComplexity:
Max: 15

PerceivedComplexity:
Max: 20

MethodLength:
Max: 30
Gemspec/RequireMFA:
Enabled: false

ClassLength:
Layout/LeadingCommentSpace:
Enabled: false

LineLength:
Layout/LineLength:
Max: 150

WordArray:
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'

Metrics/BlockNesting:
Max: 4

Metrics/ClassLength:
Enabled: false

LeadingCommentSpace:
Metrics/CyclomaticComplexity:
Max: 15

Metrics/MethodLength:
Max: 30

Metrics/PerceivedComplexity:
Max: 20

Style/AccessModifierDeclarations:
EnforcedStyle: inline

Style/CommentAnnotation:
Enabled: false

CommentAnnotation:
Style/Documentation:
Enabled: false

Documentation:
Style/FrozenStringLiteralComment:
Enabled: false

Next:
Style/HashConversion:
Enabled: true

Style/Next:
Enabled: false

OptionalArguments:
Style/OptionalArguments:
Enabled: false

SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space
Style/RedundantStringEscape:
Enabled: true

SignalException:
Style/SignalException:
EnforcedStyle: only_raise

TrivialAccessors:
AllowPredicates: true

BlockNesting:
Max: 4

Style/StringLiterals:
Enabled: true
EnforcedStyle: single_quotes

Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'

Style/FrozenStringLiteralComment:
Enabled: false
Style/TrivialAccessors:
AllowPredicates: true

Style/AccessModifierDeclarations:
EnforcedStyle: inline
Style/WordArray:
Enabled: false
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4
2.7
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: ruby
cache: bundler
rvm: 2.4
rvm: 2.7
before_install:
- gem update --system
- gem install bundler
Expand Down
2 changes: 1 addition & 1 deletion bin/profile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ result.eliminate_methods!([/Integer#times/])

# printer = RubyProf::GraphPrinter.new(result)
printer = RubyProf::FlatPrinterWithLineNumbers.new(result)
printer.print(STDOUT)
printer.print($stdout)
8 changes: 4 additions & 4 deletions hedgelog.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ require 'hedgelog/version'
Gem::Specification.new do |spec|
spec.name = 'hedgelog'
spec.version = Hedgelog::VERSION
spec.required_ruby_version = '>= 2.7.0'
spec.licenses = ['MIT']
spec.authors = ['Jeff Utter']
spec.email = ['jeff.utter@firespring.com']
spec.authors = ['Firespring']
spec.email = ['opensource@firespring.com']

spec.homepage = 'https://github.com/firespring/hedgelog'
spec.summary = 'A strucutred JSON logger for Ruby'
spec.summary = 'A structured JSON logger for Ruby'
spec.description = 'An opinionated/structured JSON logger for Ruby'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'yajl-ruby', '~> 1.4'
spec.add_development_dependency 'bundler'
end
12 changes: 8 additions & 4 deletions lib/hedgelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'hedgelog/scrubber'
require 'hedgelog/normalizer'
require 'logger'
require 'yajl'
require 'json'

class Hedgelog
LEVELS = %w[DEBUG INFO WARN ERROR FATAL UNKNOWN].each_with_object({}).with_index do |(v, h), i|
Expand All @@ -25,7 +25,8 @@ class Hedgelog
attr_reader :level
attr_writer :app

def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil, cleaner = nil)
# rubocop:disable Metrics/ParameterLists
def initialize(logdev = $stdout, shift_age = nil, shift_size = nil, cleaner = nil)
@level = LEVELS[:debug]
@channel = nil
@logdev = nil
Expand All @@ -40,6 +41,7 @@ def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil, cleaner = nil
@logdev = Logger::LogDevice.new(logdev, shift_age: shift_age, shift_size: shift_size)
end
end
# rubocop:enable Metrics/ParameterLists

def level=(level)
int_level = level_to_int(level)
Expand All @@ -48,6 +50,7 @@ def level=(level)
@level = int_level
end

# rubocop:disable Metrics/ParameterLists
def add(severity = LEVELS[:unknown], message = nil, progname = nil, context = {}, &block)
return true if (@logdev.nil? && @channel.nil?) || severity < @level

Expand All @@ -62,6 +65,7 @@ def add(severity = LEVELS[:unknown], message = nil, progname = nil, context = {}

@channel&.add(severity, nil, progname, context)
end
# rubocop:enable Metrics/ParameterLists

def []=(key, val)
@channel_context[key] = val
Expand Down Expand Up @@ -147,7 +151,7 @@ def formatter=(_value)
data[:caller] = debugharder(caller(4, 1).first) if debug?
data = extract_top_level_keys(data)

@logdev.write(Yajl::Encoder.encode(data) + "\n")
@logdev.write("#{JSON.generate(data)}\n")
true
end

Expand Down Expand Up @@ -176,7 +180,7 @@ def formatter=(_value)
whence = $LOAD_PATH.find { |p| path.start_with?(p) }
file = if whence
# Remove the RUBYLIB path portion of the full file name
path[whence.length + 1..-1]
path[whence.length + 1..]
else
# We get here if the path is not in $:
path
Expand Down
8 changes: 4 additions & 4 deletions lib/hedgelog/normalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ def normalize(data)
end

def normalize_struct(struct)
normalize_hash(Hash[struct.each_pair.to_a])
normalize_hash(struct.each_pair.to_a.to_h)
end

def normalize_hash(hash)
Hash[hash.map do |key, val|
[key, normalize_thing(val)]
end]
hash.transform_values do |val|
normalize_thing(val)
end
end

def normalize_array(array)
Expand Down
2 changes: 1 addition & 1 deletion lib/hedgelog/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Hedgelog
VERSION = '0.2.0'
VERSION = '0.2.1.alpha.2'
end
47 changes: 47 additions & 0 deletions script/.bash_helpers
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
base_dir=$(dirname $BASH_SOURCE)
. ${base_dir}/.env.colors

die()
{
echo
set_red
echo >&2 "$@"
reset_colors
exit 2
}

finish()
{
echo
set_white
echo "$@"
reset_colors
exit 0
}

confirm()
{
prompt="${1:-Are you sure? [y/N]}"

set_yellow
echo -n "$prompt "
reset_colors

if [ "${NO_INPUT:-}" == 'true' ]
then
# Continue if 'NO_INPUT' has been set
true
else
# call with a prompt string or use a default
read -r response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
fi
}
94 changes: 94 additions & 0 deletions script/.env.colors
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

echo_red()
{
set_red
echo "$@"
reset_colors
}

set_red()
{
echo -ne "\033[31;1m"
}

set_background_red()
{
echo -ne "\033[41;1m"
}

set_light_red()
{
echo -ne "\033[91;1m"
}

echo_green()
{
set_green
echo "$@"
reset_colors
}

set_green()
{
echo -ne "\033[32;1m"
}

set_background_green()
{
echo -ne "\033[42;1m"
}

set_light_green()
{
echo -ne "\033[92;1m"
}

echo_yellow()
{
set_yellow
echo "$@"
reset_colors
}

set_yellow()
{
echo -ne "\033[33;1m"
}

set_background_yellow()
{
echo -ne "\033[43;1m"
}

set_light_yellow()
{
echo -ne "\033[93;1m"
}

set_white()
{
echo -ne "\033[37;1m"
}

set_background_white()
{
echo -ne "\033[47;1m"
}

echo_light_white()
{
set_light_white
echo "$@"
reset_colors
}

set_light_white()
{
echo -ne "\033[97;1m"
}

reset_colors()
{
echo -ne "\033[0m"
}
Loading