-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3f3a7a
commit 43b05bc
Showing
1 changed file
with
55 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ configuration is one JSON object located in ```log``` field. | |
* **output** - set of properties with ```log.output.``` prefix describes | ||
logger output configuration. | ||
|
||
* **type** (default: file) - type of the logger output. Two types are | ||
* **type** (default: file) - type of the logger output. You can also specify the file and stdout at the same time using array (examples below). Types are | ||
supported: | ||
* file - | ||
[lumberjack](https://github.com/natefinch/lumberjack) | ||
|
@@ -88,80 +88,85 @@ configuration is one JSON object located in ```log``` field. | |
* **password** (required) - password (to send from a Google account, you will need to create the special "app password"). | ||
* **application_name** (optional, default empty) - for smtp auth. | ||
|
||
#### Telegram bot hook configuration | ||
#### Telegram bot hook configuration | ||
|
||
For hook type `telegram_bot`: | ||
For hook type `telegram_bot`: | ||
|
||
* **telegram_api_key** (required) - api key of your telegram bot. | ||
* **telegram_chat_id** (required) - the chat id to which the logs will be sent. | ||
* **disable_notification** (optional, default `false`) - if `true`, the bot will send the message silently. | ||
|
||
## Examples | ||
|
||
## Default logger configuration in JSON format | ||
### Simple configuration with logs output both to the console and to a file in JSON format | ||
|
||
```json | ||
"log": { | ||
"formatter": { | ||
"timestamp_format": "2006-01-02T15:04:05.999999999Z07:00", | ||
"type": "text" | ||
"log": { | ||
"formatter": { | ||
"type": "json" | ||
}, | ||
"output": { | ||
"type": ["file", "stdout"] | ||
}, | ||
} | ||
``` | ||
|
||
### Logger configuration with text format in file | ||
|
||
```json | ||
"log": { | ||
"formatter": { | ||
"timestamp_format": "2006-01-02T15:04:05.999Z07:00", | ||
"type": "text" | ||
}, | ||
"level": "info", | ||
"output": { | ||
"current_link": "./snet-daemon.log", | ||
"file_pattern": "./snet-daemon.%Y%m%d.log", | ||
"max_age_in_days": 604800, | ||
"rotation_count": 0, | ||
"max_size_in_mb": 86400, | ||
"type": "file" | ||
"current_link": "./snet-daemon.log", | ||
"file_pattern": "./snet-daemon.%Y%m%d.log", | ||
"max_age_in_days": 1, | ||
"rotation_count": 0, | ||
"max_size_in_mb": 300, | ||
"type": "file" | ||
}, | ||
"timezone": "UTC" | ||
} | ||
``` | ||
|
||
## Email hook configuration | ||
|
||
### Email hook configuration | ||
|
||
```json | ||
"log": { | ||
... | ||
"hooks": ["send-mail"], | ||
"send-mail": { | ||
"type": "email", | ||
"levels": ["error", "warn", "fatal"], | ||
"config": { | ||
"application_name": "test-application-name", | ||
"host": "smtp.gmail.com", | ||
"port": 587, | ||
"from": "[email protected]", | ||
"to": "[email protected]", | ||
"username": "[email protected]", | ||
"password": "secret" | ||
} | ||
}, | ||
"hooks": ["send-mail"], | ||
"send-mail": { | ||
"type": "email", | ||
"levels": ["error", "warn", "fatal", "panic"], | ||
"application_name": "test-application-name", | ||
"host": "smtp.gmail.com", | ||
"port": 587, | ||
"from": "[email protected]", | ||
"to": "[email protected]", | ||
"username": "[email protected]", | ||
"password": "secret" | ||
}, | ||
} | ||
``` | ||
|
||
## Telegram bot hook configuration | ||
### Telegram bot hook configuration | ||
|
||
``` | ||
"hooks":["tg"], | ||
"tg": { | ||
"telegram_api_key": "7258436601:AAFlAm8gIGIyOTEv7lb9ipHcuB7YTR9-TuR", | ||
"telegram_chat_id": -4103253970, | ||
"disable_notification": false, | ||
"type": "telegram_bot", | ||
"levels": [ | ||
"error", | ||
"panic" | ||
] | ||
```json | ||
"log": { | ||
"hooks":["tg"], | ||
"tg": { | ||
"telegram_api_key": "7258436601:AAFlAm8gIGIyOTEv7lb9ipHcuB7YTR9-TuR", | ||
"telegram_chat_id": -4103253970, | ||
"disable_notification": false, | ||
"type": "telegram_bot", | ||
"levels": [ "fatal", "panic"] | ||
}, | ||
} | ||
``` | ||
|
||
## Adding new hooks implementations | ||
|
||
Adding a new hook implementation is trivial. You should implement factory method | ||
which inputs hook configuration as [Viper](https://godoc.org/github.com/spf13/viper#Viper) | ||
config and returns new instance of the Hook structure. Then register the new hook | ||
type by calling RegisterHookType() function from init() method. | ||
### Adding new hooks implementations | ||
|
||
Please see "email" hook implementation as example in hook.go file | ||
Adding a new hook implementation is trivial. You should implement interface hook with method `call` which inputs `entry zapcore.Entry`. Also you need impelement init method which inputs configuration as [Viper](https://godoc.org/github.com/spf13/viper#Viper) config and returns new instance of the Hook structure. Then register the new hook | ||
type by calling RegisterHookType() function from init() method. Please see "email" hook implementation as example in hook.go file. |