https://github.com/optum/telemetry-logger
A general logging gem used by the other Telemetry gems
https://github.com/optum/telemetry-logger
logger logging ruby telemetry
Last synced: about 1 year ago
JSON representation
A general logging gem used by the other Telemetry gems
- Host: GitHub
- URL: https://github.com/optum/telemetry-logger
- Owner: Optum
- License: apache-2.0
- Created: 2021-06-23T21:25:11.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-08-12T19:16:16.000Z (almost 5 years ago)
- Last Synced: 2025-04-14T15:22:06.154Z (about 1 year ago)
- Topics: logger, logging, ruby, telemetry
- Language: Ruby
- Homepage:
- Size: 35.2 KB
- Stars: 2
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Telemetry::Logger
A generic gem to handle logging for all other telemetry gems
#### Setting up the logger
```ruby
Telemetry::Logger.setup(level: 'warn', color: false, log_file: './telemetry.log')
opts = {
include_pid: false,
level: 'info',
log_file: nil,
color: true,
application: 'telemetry',
app_version: Telemetry::Logger::VERSION
}
```
#### Example Logging
```ruby
Telemetry::Logger.setup(level: 'info')
Telemetry::Logger.info 'test info'
Telemetry::Logger.debug 'test debug'
Telemetry::Logger.warn 'test warn'
Telemetry::Logger.error 'test error'
Telemetry::Logger.fatal 'test fatal'
Telemetry::Logger.unknown 'test unknown'
```
#### Example Exception Tracking
Instead of repeating the same error method all over the place for exceptions, you can use the `exception` method to
save on complexity and automatically report exceptions to supported APMs
```ruby
Telemetry::Logger.setup(level: 'info')
Telemetry::Logger.exception(StandardError.new('test error'), level: 'warn')
Telemetry::Logger.exception(StandardError.new('test error'), level: 'fatal')
Telemetry::Logger.exception(StandardError.new('test error'), handled: true)
Telemetry::Logger.exception(StandardError.new('test error'), backtrace: true)
# options for exception method
opts = {
level: 'error', # sets the log level
handled: true, # tells the apms if we handled this exception
backtrace: true, # should we log the backtrace?
backtrace_limit: 20, # how many lines should we limit the backtrace to?
raise: false, # should we reraise this exception instead of swallowing it?
}
```