foghorn-logger 1.0.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +63 -0
- data/VERSION +1 -0
- data/lib/foghorn.rb +106 -0
- metadata +67 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 615404bf7ff107b827f75138fadaf00500525c06620a69e94f6e4ab1a2b3390a
|
|
4
|
+
data.tar.gz: d893624c31ee5c54c4a4df388ce55ef3736873bcb6ec5951e3ca029e31edbd37
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: eecda944787209cc6e1462e2e87733bf31ac250c028090ad5dd6d6f105f9639c82a020f50f1faa26a1f95fd53d448e1ea21c6bf9c97f42b004a426302157dea2
|
|
7
|
+
data.tar.gz: d8d5b0b1be8c7528176addef926b208e1a703ecfa0c025829817005ec43e36ac6c2a9707139b88ee35df89b45c70cb96294af6e4639d4707f20c98ca3389981a
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 egee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# 🌫️ Foghorn
|
|
2
|
+
|
|
3
|
+
A readable, terminal-friendly logger for Ruby!
|
|
4
|
+
|
|
5
|
+
Foghorn gives you colored console output with optional dual-write to a plain-text log file. No monkey-patching, no enterprise bloat — just clear signals through the noise.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add to your Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'foghorn'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
require 'foghorn'
|
|
19
|
+
|
|
20
|
+
Foghorn.info "Deploying to production..."
|
|
21
|
+
Foghorn.success "All services healthy"
|
|
22
|
+
Foghorn.warn "Memory at 72%"
|
|
23
|
+
Foghorn.error "Connection refused"
|
|
24
|
+
Foghorn.debug "Checking state..." # only shown at debug level
|
|
25
|
+
Foghorn.verbose "Detailed output..." # shown at verbose or debug level
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Log Levels
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
Foghorn.level = :quiet # errors only
|
|
32
|
+
Foghorn.level = :normal # info, success, warn, error (default)
|
|
33
|
+
Foghorn.level = :verbose # adds verbose messages
|
|
34
|
+
Foghorn.level = :debug # adds debug messages
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### File Logging
|
|
38
|
+
|
|
39
|
+
Dual-write to terminal (with color) and a plain-text log file (without color):
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
Foghorn.enable_file_logging('production')
|
|
43
|
+
# => Creates ./logs/production-20260218-183000.log
|
|
44
|
+
|
|
45
|
+
# Custom log directory
|
|
46
|
+
Foghorn.enable_file_logging('myapp', log_dir: '/var/log/myapp')
|
|
47
|
+
|
|
48
|
+
# Close when done
|
|
49
|
+
Foghorn.close_log
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Development
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
bundle install
|
|
56
|
+
rake test # lint + specs
|
|
57
|
+
rake build # build the gem
|
|
58
|
+
rake release # lint, test, bump, tag
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
MIT
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.0
|
data/lib/foghorn.rb
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rainbow'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
|
|
6
|
+
# Foghorn — A readable, terminal-friendly logger for Ruby CLIs.
|
|
7
|
+
# Provides colored console output with optional dual-write to a plain-text log file.
|
|
8
|
+
module Foghorn
|
|
9
|
+
VERSION = File.read(File.join(__dir__, '..', 'VERSION')).strip
|
|
10
|
+
|
|
11
|
+
# Log levels (higher = more verbose)
|
|
12
|
+
LEVELS = {
|
|
13
|
+
quiet: 0,
|
|
14
|
+
normal: 1,
|
|
15
|
+
verbose: 2,
|
|
16
|
+
debug: 3
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
19
|
+
@level = :normal
|
|
20
|
+
@log_file = nil
|
|
21
|
+
|
|
22
|
+
class << self
|
|
23
|
+
attr_accessor :level
|
|
24
|
+
|
|
25
|
+
# Enable file logging. Creates a timestamped log file.
|
|
26
|
+
# All messages are written to both terminal (with color) and file (plain text).
|
|
27
|
+
def enable_file_logging(label, log_dir: File.join(Dir.pwd, 'logs'))
|
|
28
|
+
FileUtils.mkdir_p(log_dir)
|
|
29
|
+
|
|
30
|
+
timestamp = Time.now.strftime('%Y%m%d-%H%M%S')
|
|
31
|
+
log_path = File.join(log_dir, "#{label}-#{timestamp}.log")
|
|
32
|
+
@log_file = File.open(log_path, 'a')
|
|
33
|
+
@log_file.sync = true
|
|
34
|
+
|
|
35
|
+
info("Logging to #{log_path}")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def close_log
|
|
39
|
+
return unless @log_file
|
|
40
|
+
|
|
41
|
+
@log_file.close
|
|
42
|
+
@log_file = nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def quiet?
|
|
46
|
+
@level == :quiet
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def verbose?
|
|
50
|
+
@level == :verbose || @level == :debug
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def debug?
|
|
54
|
+
@level == :debug
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def info(message)
|
|
58
|
+
return if quiet?
|
|
59
|
+
|
|
60
|
+
puts message
|
|
61
|
+
log_to_file(message)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def success(message)
|
|
65
|
+
return if quiet?
|
|
66
|
+
|
|
67
|
+
puts Rainbow(message).green
|
|
68
|
+
log_to_file(message)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def warn(message)
|
|
72
|
+
return if quiet?
|
|
73
|
+
|
|
74
|
+
puts Rainbow(message).yellow
|
|
75
|
+
log_to_file("[WARN] #{message}")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def error(message)
|
|
79
|
+
# Always show errors, even in quiet mode
|
|
80
|
+
puts Rainbow(message).red
|
|
81
|
+
log_to_file("[ERROR] #{message}")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def debug(message)
|
|
85
|
+
return unless debug?
|
|
86
|
+
|
|
87
|
+
puts Rainbow("[DEBUG] #{message}").darkgray
|
|
88
|
+
log_to_file("[DEBUG] #{message}")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def verbose(message)
|
|
92
|
+
return unless verbose?
|
|
93
|
+
|
|
94
|
+
puts Rainbow(message).darkgray
|
|
95
|
+
log_to_file(message)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
private
|
|
99
|
+
|
|
100
|
+
def log_to_file(message)
|
|
101
|
+
return unless @log_file
|
|
102
|
+
|
|
103
|
+
@log_file.puts("[#{Time.now.strftime('%H:%M:%S')}] #{message}")
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: foghorn-logger
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- egee
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-02-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rainbow
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.1'
|
|
27
|
+
description: Foghorn provides colored console output with optional dual-write to a
|
|
28
|
+
plain-text log file. Built for CLI tools that need beautiful terminal output and
|
|
29
|
+
persistent logs without the complexity of enterprise logging.
|
|
30
|
+
email:
|
|
31
|
+
- egee@egee.io
|
|
32
|
+
executables: []
|
|
33
|
+
extensions: []
|
|
34
|
+
extra_rdoc_files: []
|
|
35
|
+
files:
|
|
36
|
+
- LICENSE
|
|
37
|
+
- README.md
|
|
38
|
+
- VERSION
|
|
39
|
+
- lib/foghorn.rb
|
|
40
|
+
homepage: https://github.com/egeexyz/foghorn
|
|
41
|
+
licenses:
|
|
42
|
+
- MIT
|
|
43
|
+
metadata:
|
|
44
|
+
homepage_uri: https://github.com/egeexyz/foghorn
|
|
45
|
+
source_code_uri: https://github.com/egeexyz/foghorn
|
|
46
|
+
changelog_uri: https://github.com/egeexyz/foghorn/blob/main/CHANGELOG.md
|
|
47
|
+
rubygems_mfa_required: 'true'
|
|
48
|
+
post_install_message:
|
|
49
|
+
rdoc_options: []
|
|
50
|
+
require_paths:
|
|
51
|
+
- lib
|
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '3.0'
|
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
requirements: []
|
|
63
|
+
rubygems_version: 3.5.22
|
|
64
|
+
signing_key:
|
|
65
|
+
specification_version: 4
|
|
66
|
+
summary: A readable, terminal-friendly logger for Ruby CLIs
|
|
67
|
+
test_files: []
|