-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Carlos Palhares <[email protected]>
- Loading branch information
Showing
33 changed files
with
480 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: lumberaxe | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
ruby: | ||
uses: ./.github/workflows/_ruby-package.yml | ||
with: | ||
package: ${{ github.workflow }} | ||
ruby: '["2.7.4", "3.1.2"]' | ||
rails: '["7.0.3.1","6.1.6.1","6.0.5.1","5.2.8.1"]' | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/_yardoc/ | ||
coverage | ||
pkg | ||
/spec/reports/ | ||
**/tmp/* | ||
!**/tmp/.gitkeep | ||
!tmp/.gitignore | ||
vendor/bundle | ||
*.log | ||
*.sqlite | ||
*.sqlite3 | ||
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
inherit_from: .rubocop_todo.yml | ||
|
||
require: | ||
- rubocop-powerhome | ||
|
||
AllCops: | ||
TargetRubyVersion: 2.7 | ||
|
||
Rails: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This configuration was generated by | ||
# `rubocop --auto-gen-config --exclude-limit 500` | ||
# on 2022-08-11 19:45:17 UTC using RuboCop version 1.29.1. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
git_source(:github) do |repo_name| | ||
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") | ||
"https://github.com/#{repo_name}.git" | ||
end | ||
|
||
gemspec | ||
|
||
rails_version = ENV.fetch("RAILS_VERSION", ">= 5.2.8.1") | ||
|
||
gem "rails", rails_version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env rake | ||
|
||
# frozen_string_literal: true | ||
|
||
require "rspec/core/rake_task" | ||
require "rubocop/rake_task" | ||
|
||
begin | ||
require "bundler/setup" | ||
rescue LoadError | ||
puts "You must `gem install bundler` and `bundle install` to run rake tasks" | ||
end | ||
begin | ||
require "yard" | ||
YARD::Rake::YardocTask.new do |t| | ||
t.files = ["lib/**/*.rb"] | ||
t.options = [ | ||
"--no-private", | ||
] | ||
end | ||
rescue LoadError | ||
warn "Could not require() YARD! Install with 'gem install yard' to get the 'yardoc' task" | ||
end | ||
|
||
Bundler::GemHelper.install_tasks | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
RuboCop::RakeTask.new(:rubocop) | ||
|
||
task default: %i[spec rubocop] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rubygems" | ||
require "bundler" | ||
|
||
Bundler.require :default, :development | ||
|
||
Combustion.initialize! :all | ||
run Combustion::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
- - :inherit_from | ||
- https://raw.githubusercontent.com/powerhome/oss-guide/master/license_rules.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Lumberaxe | ||
|
||
Lumberaxe handles logging output formatting. | ||
|
||
# Usage | ||
|
||
After installing the gem, require it as part of your application configuration. | ||
|
||
```ruby | ||
# application.rb | ||
|
||
require "lumberaxe" | ||
``` | ||
|
||
## Setting JSON logging | ||
|
||
To set up JSON logging on puma, add this to your puma config: | ||
|
||
```ruby | ||
# puma.rb | ||
|
||
log_formatter(&Lumberaxe.puma_formatter) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require "logger" | ||
require "active_support" | ||
require "lumberaxe/railtie" if defined?(Rails) | ||
require "lumberaxe/logger" | ||
require "lumberaxe/json_formatter" | ||
|
||
module Lumberaxe | ||
def self.puma_formatter(level: "INFO", progname: "puma") | ||
->(message) do | ||
{ | ||
level: level, | ||
time: Time.now, | ||
progname: progname, | ||
message: message, | ||
}.to_json.concat("\r\n") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "active_support/tagged_logging" | ||
|
||
module Lumberaxe | ||
class JSONFormatter < ::Logger::Formatter | ||
include ActiveSupport::TaggedLogging::Formatter | ||
|
||
def call(severity, time, progname, data) | ||
data = data.is_a?(Hash) ? format_data(data) : { message: data.to_s } | ||
|
||
{ | ||
level: severity, | ||
time: time, | ||
progname: progname, | ||
}.merge(data).to_json.concat("\r\n") | ||
end | ||
|
||
def format_data(data) | ||
data.merge!(current_tags.each_with_object({}) do |tag, hash| | ||
if tag.include?("=") | ||
key, value = tag.split("=") | ||
hash[key] = value | ||
else | ||
hash[:tags] ||= [] | ||
hash[:tags] << key | ||
end | ||
hash | ||
end) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lumberaxe | ||
class Logger < ::ActiveSupport::Logger | ||
cattr_accessor :log_level | ||
|
||
def initialize(output = $stdout, progname:, level: log_level) | ||
super output | ||
|
||
self.progname = progname | ||
self.level = level | ||
|
||
self.formatter = JSONFormatter.new | ||
extend ActiveSupport::TaggedLogging | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require "lograge" | ||
|
||
module Lumberaxe | ||
class Railtie < Rails::Railtie | ||
initializer "lumberaxe.configurations", before: :initialize_logger do |app| | ||
Rails.logger = app.config.logger || Lumberaxe::Logger.new(progname: "app", level: app.config.log_level) | ||
|
||
app.config.log_tags = [ | ||
->(req) { "request_id=#{req.uuid}" }, | ||
->(req) { "IP=#{req.remote_ip}" }, | ||
] | ||
|
||
Lumberaxe::Logger.log_level = app.config.log_level | ||
end | ||
|
||
initializer "lumberaxe.lograge" do | ||
config.lograge.enabled = true | ||
config.lograge.formatter = Lograge::Formatters::Raw.new | ||
config.lograge.custom_options = ->(event) do | ||
{ "params" => event.payload[:params].without("controller", "action") } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lumberaxe | ||
VERSION = "0.1.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "lib/lumberaxe/version" | ||
|
||
$LOAD_PATH.push File.expand_path("lib", __dir__) | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "lumberaxe" | ||
spec.version = Lumberaxe::VERSION | ||
spec.authors = ["Carlos Palhares", "Jill Klang"] | ||
spec.email = ["[email protected]", "[email protected]"] | ||
|
||
spec.summary = "Power-ful logging wrapper" | ||
spec.description = "Lumberaxe handles logging output formatting." | ||
spec.homepage = "https://github.com/powerhome/power-tools" | ||
spec.license = "MIT" | ||
spec.required_ruby_version = ">= 2.7" | ||
|
||
spec.metadata["rubygems_mfa_required"] = "true" | ||
spec.metadata["homepage_uri"] = spec.homepage | ||
spec.metadata["source_code_uri"] = spec.homepage | ||
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/packages/lumberaxe/docs/CHANGELOG.md" | ||
|
||
# Specify which files should be added to the gem when it is released. | ||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git. | ||
spec.files = Dir.chdir(__dir__) do | ||
`git ls-files -z`.split("\x0").reject do |f| | ||
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) | ||
end | ||
end | ||
spec.bindir = "exe" | ||
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_dependency "activesupport", ">= 5.2.8.1" | ||
spec.add_dependency "lograge", "0.10.0" | ||
|
||
spec.add_development_dependency "bundler", "~> 2.1" | ||
spec.add_development_dependency "combustion", "~> 1.3" | ||
spec.add_development_dependency "license_finder", ">= 7.0" | ||
spec.add_development_dependency "parser", ">= 2.5", "!= 2.5.1.1" | ||
spec.add_development_dependency "pry-byebug", "3.9.0" | ||
spec.add_development_dependency "rails", ">= 5.2.8.1" | ||
spec.add_development_dependency "rainbow", "2.2.2" | ||
spec.add_development_dependency "rake", "~> 13.0" | ||
spec.add_development_dependency "rspec", "~> 3.0" | ||
spec.add_development_dependency "rspec-rails", "~> 5.1.2" | ||
spec.add_development_dependency "rubocop-powerhome", "0.5.0" | ||
spec.add_development_dependency "simplecov", "0.15.1" | ||
spec.add_development_dependency "sqlite3", "~> 1.4.2" | ||
spec.add_development_dependency "test-unit", "3.1.5" | ||
spec.add_development_dependency "yard", "0.9.21" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
site_name: Lumberaxe | ||
nav: | ||
- "Home": "README.md" | ||
plugins: | ||
- techdocs-core |
Empty file.
4 changes: 4 additions & 0 deletions
4
packages/lumberaxe/spec/internal/app/controllers/application_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationController < ActionController::Base | ||
end |
16 changes: 16 additions & 0 deletions
16
packages/lumberaxe/spec/internal/app/controllers/campgrounds_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class CampgroundsController < ApplicationController | ||
def create | ||
campground_params = params.require(:campground).permit(:name) | ||
campground = Campground.new(campground_params) | ||
|
||
Rails.logger.warn("Creating campground named #{campground.name}") | ||
|
||
if campground.save | ||
render json: campground, status: :created | ||
else | ||
render json: campground.errors, status: :unprocessable_entity | ||
end | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
packages/lumberaxe/spec/internal/app/models/application_record.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationRecord < ActiveRecord::Base | ||
self.abstract_class = true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Campground < ApplicationRecord | ||
self.table_name = "internal_campgrounds" | ||
|
||
validates :name, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test: | ||
adapter: sqlite3 | ||
database: db/combustion_test.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
Rails.application.routes.draw do | ||
resources :campgrounds, only: :create | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test: | ||
service: Disk | ||
root: /Users/jill/power-tools/packages/lumberaxe/tmp/storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
ActiveRecord::Schema.define do | ||
create_table(:internal_campgrounds, force: true) do |t| | ||
t.string :name | ||
t.timestamps | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.log |
Empty file.
Oops, something went wrong.