|
1 | 1 | # Telemetry::Logger |
2 | 2 | A generic gem to handle logging for all other telemetry gems |
3 | 3 |
|
4 | | -Example |
| 4 | +#### Setting up the logger |
| 5 | +```ruby |
| 6 | +Telemetry::Logger.setup(level: 'warn', color: false, log_file: './telemetry.log') |
| 7 | + |
| 8 | +opts = { |
| 9 | + include_pid: false, |
| 10 | + level: 'info', |
| 11 | + log_file: nil, |
| 12 | + color: true, |
| 13 | + application: 'telemetry', |
| 14 | + app_version: Telemetry::Logger::VERSION |
| 15 | +} |
| 16 | +``` |
| 17 | + |
| 18 | +#### Example Logging |
5 | 19 | ```ruby |
6 | 20 | Telemetry::Logger.setup(level: 'info') |
7 | 21 | Telemetry::Logger.info 'test info' |
| 22 | + |
8 | 23 | Telemetry::Logger.debug 'test debug' |
9 | 24 | Telemetry::Logger.warn 'test warn' |
10 | 25 | Telemetry::Logger.error 'test error' |
11 | 26 | Telemetry::Logger.fatal 'test fatal' |
12 | 27 | Telemetry::Logger.unknown 'test unknown' |
13 | 28 | ``` |
| 29 | + |
| 30 | +#### Example Exception Tracking |
| 31 | +Instead of repeating the same error method all over the place for exceptions, you can use the `exception` method to |
| 32 | +save on complexity and automatically report exceptions to supported APMs |
| 33 | + |
| 34 | +```ruby |
| 35 | +Telemetry::Logger.setup(level: 'info') |
| 36 | +Telemetry::Logger.exception(StandardError.new('test error'), level: 'warn') |
| 37 | +Telemetry::Logger.exception(StandardError.new('test error'), level: 'fatal') |
| 38 | +Telemetry::Logger.exception(StandardError.new('test error'), handled: true) |
| 39 | +Telemetry::Logger.exception(StandardError.new('test error'), backtrace: true) |
| 40 | + |
| 41 | +# options for exception method |
| 42 | +opts = { |
| 43 | + level: 'error', # sets the log level |
| 44 | + handled: true, # tells the apms if we handled this exception |
| 45 | + backtrace: true, # should we log the backtrace? |
| 46 | + backtrace_limit: 20, # how many lines should we limit the backtrace to? |
| 47 | + raise: false, # should we reraise this exception instead of swallowing it? |
| 48 | +} |
| 49 | +``` |
0 commit comments