logger_head 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c9468862f9d5144ae46bea82b1758d8aeff9e4c6d8411d080769df19b2047734
4
+ data.tar.gz: f4e3fbfd161c1464b14dadff378a83342b33bd16e93dbeb77f33c8c4d34f5967
5
+ SHA512:
6
+ metadata.gz: a83a13eec52d7c483afefa6b66bd832f18c34e4a075214b2fb42a507e34e958b2621a21576f970fd5ecef43838755aabc796936019b4257f431eeefed205f96b
7
+ data.tar.gz: 0e341aebd3d17c2754fadd492205c2cdf91d03ac72aaf51e19978a302cee6eaa4398390293e2b822566058fc043b89b3fa7d3f3e6fb87759ae3b3c8964938494
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # LoggerHead
2
+
3
+ A simple structured error logging utility with context support for Ruby applications. LoggerHead provides structured error logging with contextual information for better debugging and error tracking.
4
+
5
+ Originally extracted from DetectionTek patterns, LoggerHead offers consistent error logging that works in both Rails and non-Rails environments.
6
+
7
+ ## Features
8
+
9
+ - **Structured Error Logging**: Logs errors with contextual information
10
+ - **Automatic Backtrace Logging**: Captures and logs full error backtraces
11
+ - **Context-Aware**: Allows adding descriptive context to errors for better debugging
12
+ - **Environment Agnostic**: Works with Rails.logger or standard Ruby Logger
13
+ - **Zero Dependencies**: Pure Ruby with no external dependencies
14
+ - **Simple API**: Easy to integrate into existing codebases
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'logger_head'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ ```bash
27
+ bundle install
28
+ ```
29
+
30
+ Or install it yourself as:
31
+
32
+ ```bash
33
+ gem install logger_head
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ### Basic Usage
39
+
40
+ ```ruby
41
+ require 'logger_head'
42
+
43
+ begin
44
+ # Some operation that might fail
45
+ raise StandardError, "Something went wrong"
46
+ rescue => error
47
+ # Log with context
48
+ LoggerHead.new(error, provided_context: "during user creation").call
49
+ end
50
+ ```
51
+
52
+ ### With Custom Context
53
+
54
+ ```ruby
55
+ # Log error with specific context
56
+ error = StandardError.new("Database connection failed")
57
+ LoggerHead.new(error, provided_context: "in payment processing").call
58
+
59
+ # Output:
60
+ # ERROR -- : There was an error in payment processing: Database connection failed
61
+ # ERROR -- : /path/to/file:123:in `method_name'
62
+ # /path/to/file:456:in `other_method'
63
+ # ...
64
+ ```
65
+
66
+ ### In Rails Applications
67
+
68
+ LoggerHead automatically uses `Rails.logger` when available:
69
+
70
+ ```ruby
71
+ class UsersController < ApplicationController
72
+ def create
73
+ User.create!(user_params)
74
+ rescue => error
75
+ LoggerHead.new(error, provided_context: "creating user #{params[:name]}").call
76
+ render json: { error: "User creation failed" }, status: 422
77
+ end
78
+ end
79
+ ```
80
+
81
+ ### In Service Objects
82
+
83
+ ```ruby
84
+ class CreateUserService
85
+ def call
86
+ # ... service logic
87
+ rescue => error
88
+ LoggerHead.new(error, provided_context: "in #{self.class.name}").call
89
+ # Handle error appropriately
90
+ end
91
+ end
92
+ ```
93
+
94
+ ### Integration with Hmibo
95
+
96
+ LoggerHead is integrated into the [Hmibo gem](https://github.com/wendcare/hmibo) for service object patterns:
97
+
98
+ ```ruby
99
+ class MyService < Hmibo::Base
100
+ def perform
101
+ # Any errors are automatically logged with LoggerHead
102
+ raise StandardError, "Something went wrong"
103
+ end
104
+ end
105
+
106
+ # Automatically logs: "There was an error in MyService execution: Something went wrong"
107
+ ```
108
+
109
+ ## Development
110
+
111
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
112
+
113
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
114
+
115
+ ## API Reference
116
+
117
+ ### LoggerHead.new(error, provided_context: nil)
118
+
119
+ Creates a new LoggerHead instance.
120
+
121
+ **Parameters:**
122
+ - `error` (Exception): The error/exception to log
123
+ - `provided_context` (String, optional): Additional context information
124
+
125
+ **Returns:** LoggerHead instance
126
+
127
+ ### #call
128
+
129
+ Executes the logging operation, writing both the error message and backtrace to the logger.
130
+
131
+ **Returns:** nil
132
+
133
+ ## Testing
134
+
135
+ The gem includes a comprehensive test suite. Run tests with:
136
+
137
+ ```bash
138
+ bundle exec rspec
139
+ ```
140
+
141
+ ## Contributing
142
+
143
+ Bug reports and pull requests are welcome on GitHub at https://github.com/detectiontek/logger_head.
144
+
145
+ 1. Fork the repository
146
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
147
+ 3. Write tests for your changes
148
+ 4. Ensure all tests pass (`bundle exec rspec`)
149
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
150
+ 6. Push to the branch (`git push origin my-new-feature`)
151
+ 7. Create a new Pull Request
152
+
153
+ ## License
154
+
155
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoggerHeadGem
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "logger_head/version"
4
+
5
+ class LoggerHead
6
+ VERSION = LoggerHeadGem::VERSION
7
+
8
+ def initialize(error, provided_context: nil)
9
+ @error = error
10
+ @provided_context = provided_context
11
+ end
12
+
13
+ def call
14
+ log_error
15
+ log_backtrace
16
+ end
17
+
18
+ def log_error
19
+ boilerplate = "There was an error"
20
+ error_context = [boilerplate, provided_context].compact.join(" ")
21
+ logger.error "#{error_context}: #{error.message}"
22
+ end
23
+
24
+ def log_backtrace
25
+ logger.error error.backtrace&.join("\n")
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :error, :provided_context
31
+
32
+ def logger
33
+ @logger ||= if defined?(Rails)
34
+ Rails.logger
35
+ else
36
+ require 'logger'
37
+ Logger.new($stdout)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ module LoggerHead
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logger_head
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dan Brown
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-07-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: LoggerHead provides structured error logging with contextual information
14
+ for better debugging and error tracking in Ruby applications.
15
+ email:
16
+ - dbrown@occameducation.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - README.md
24
+ - Rakefile
25
+ - lib/logger_head.rb
26
+ - lib/logger_head/version.rb
27
+ - sig/logger_head.rbs
28
+ homepage: https://github.com/detectiontek/logger_head
29
+ licenses:
30
+ - MIT
31
+ metadata:
32
+ source_code_uri: https://github.com/detectiontek/logger_head
33
+ changelog_uri: https://github.com/detectiontek/logger_head/blob/main/CHANGELOG.md
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.1.0
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.5.22
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: A simple structured error logging utility with context support
53
+ test_files: []