https://github.com/messeb/mssentrycocoalumberjack
Custom logger for CocoaLumberjack that logs to Sentry
https://github.com/messeb/mssentrycocoalumberjack
Last synced: 10 months ago
JSON representation
Custom logger for CocoaLumberjack that logs to Sentry
- Host: GitHub
- URL: https://github.com/messeb/mssentrycocoalumberjack
- Owner: messeb
- License: mit
- Created: 2016-05-27T16:53:47.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-03-29T21:57:10.000Z (about 2 years ago)
- Last Synced: 2025-08-13T17:58:44.127Z (10 months ago)
- Language: Swift
- Size: 189 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MSSentryCocoaLumberjack
[](https://travis-ci.org/messeb/MSSentryCocoaLumberjack)
[](http://cocoapods.org/pods/MSSentryCocoaLumberjack)
[](http://cocoapods.org/pods/MSSentryCocoaLumberjack)
[](http://cocoapods.org/pods/MSSentryCocoaLumberjack)
MSSentryLogger is a custom logger for [CocoaLumberjack](https://github.com/CocoaLumberjack/CocoaLumberjack) that logs to [Sentry](https://www.getsentry.com/).
It contains a mapping from the CocoaLumberJack `DDLogFlag` to the `RavenLogEvent`. You can call the CocoaLumberjack logging function and it will produce a corresponding event in Sentry.
### Mapping
| CocoaLumberjack | Sentry |
|-----------------|--------|
| DDLogDebug | Debug |
| DDLogInfo | Info |
| DDLogWarn | Warning|
| DDLogError | Error |
### Custom tags and extra
You can add custom tags und extra data in your CocoaLumberjack message.
Custom tags can be added as semicolon seperated list in square brackets, like
```
[id=userId;version=1.2.0;filename=Class.swift]
```
Custom extra data can be added as semicolon seperated list in curly brackets, like
```
{device=iPhone7;action=readFile}
```
A complete message can be:
```
Fatal error message, can execute action [id=userId;version=1.2.0;filename=Class.swift] {device=iPhone7;action=readFile}
```
##Installation
Using [CocoaPods](http://www.cocoapods.org):
```ruby
pod "MSSentryCocoaLumberjack"
```
## Usage
You need a [Sentry](https://getsentry.com) account.
Import the pod and create a new `MSSentryLogger` instance with your credentials (DSN)
```
import MSSentryCocoaLumberjack
// ...
let sentryLogger = MSSentryLogger(dsn: )
```
Than add the new logger to the CocoaLumberjack loggers
```
DDLog.addLogger(sentryLogger)
```
Now you can call the CocoaLumberjack logging functions (`DDLogDebug`, `DDLogInfo`, `DDLogWarn`, `DDLogError`) and a Sentry log event will be created.
If you only want to see a certain level, such as errors, add with a level
```
DDLog.addLogger(sentryLogger, withLevel: .Error)
```
### Sentry properties
On the `MSSentryLogger` instance you can modify values for `user`, `tags` and `extra`. These are `[String: AnyObject]` dictionaries and the set values will be send in the next requests.
```
// user has predefined keys by Sentry
sentryLogger?.user = ["id": "4711", "username": "John Doe", "email": "john.doe@example.com", "ip_address":
"127.0.0.1"]
sentryLogger?.tags = ["tag1": "value1", "tag2": "value2"]
sentryLogger?.extra = ["extra1": ""valueXYZ"]
```
You can always set new values to `user`, `tags` and `extra`. For more information take a look at the Sentry documentation: [https://docs.getsentry.com/hosted/learn/context/](https://docs.getsentry.com/hosted/learn/context/)
## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first.
In the example app you can add your credentials and trigger logs to Sentry:

You will see the event instantly in your Sentry account
## Author
messeb
## License
MSSentryCocoaLumberjack is available under the MIT license. See the LICENSE file for more info.