Skip to content

Commit d070f68

Browse files
authored
Merge pull request #587 from singnet/update-logger/README.md
Update logger README.md
2 parents e3f3a7a + c2dd9b4 commit d070f68

File tree

1 file changed

+58
-53
lines changed

1 file changed

+58
-53
lines changed

logger/README.md

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ configuration is one JSON object located in ```log``` field.
2222
* **formatter** - set of properties with ```log.formatter.``` prefix
2323
describes logger formatter configuration.
2424

25-
* **type** (default: json) - type of the log formatter. Two types are
26-
supported, which correspond to ```zap``` formatter types
25+
* **type** (default: text) - type of the log formatter. Two types are
26+
supported, which correspond to ```zap``` formatter types:
2727
* json
2828
* text
2929

30-
* **timestamp_format** (default: "2006-01-02T15:04:05.999999999Z07:00") -
30+
* **timestamp_format** (default: "2006-01-02T15:04:05.999Z07:00") -
3131
timestamp format to use in log lines, standard time.Time formats are
3232
supported, see [time.Time.Format](https://golang.org/pkg/time/#Time.Format)
3333

3434
* **output** - set of properties with ```log.output.``` prefix describes
3535
logger output configuration.
3636

37-
* **type** (default: file) - type of the logger output. Two types are
37+
* **type** (default: file & stdout) - type of the logger output. You can specify one or several values at the same time by using an array [(examples are provided below)](#examples). Types are
3838
supported:
3939
* file -
4040
[lumberjack](https://github.com/natefinch/lumberjack)
@@ -88,80 +88,85 @@ configuration is one JSON object located in ```log``` field.
8888
* **password** (required) - password (to send from a Google account, you will need to create the special "app password").
8989
* **application_name** (optional, default empty) - for smtp auth.
9090

91-
#### Telegram bot hook configuration
91+
#### Telegram bot hook configuration
9292

93-
For hook type `telegram_bot`:
93+
For hook type `telegram_bot`:
9494

9595
* **telegram_api_key** (required) - api key of your telegram bot.
9696
* **telegram_chat_id** (required) - the chat id to which the logs will be sent.
9797
* **disable_notification** (optional, default `false`) - if `true`, the bot will send the message silently.
9898

99+
## Examples
99100

100-
## Default logger configuration in JSON format
101+
### Simple configuration with logs output both to the console and to a file in JSON format
101102

102103
```json
103-
"log": {
104-
"formatter": {
105-
"timestamp_format": "2006-01-02T15:04:05.999999999Z07:00",
106-
"type": "text"
104+
"log": {
105+
"formatter": {
106+
"type": "json"
107+
},
108+
"output": {
109+
"type": ["file", "stdout"]
110+
},
111+
}
112+
```
113+
114+
### Logger configuration with text format in file
115+
116+
```json
117+
"log": {
118+
"formatter": {
119+
"timestamp_format": "2006-01-02T15:04:05.999Z07:00",
120+
"type": "text"
107121
},
108122
"level": "info",
109123
"output": {
110-
"current_link": "./snet-daemon.log",
111-
"file_pattern": "./snet-daemon.%Y%m%d.log",
112-
"max_age_in_days": 604800,
113-
"rotation_count": 0,
114-
"max_size_in_mb": 86400,
115-
"type": "file"
124+
"current_link": "./snet-daemon.log",
125+
"file_pattern": "./snet-daemon.%Y%m%d.log",
126+
"max_age_in_days": 1,
127+
"rotation_count": 0,
128+
"max_size_in_mb": 300,
129+
"type": "file"
116130
},
117131
"timezone": "UTC"
118132
}
119133
```
120134

121-
## Email hook configuration
122-
135+
### Email hook configuration
123136

124137
```json
125138
"log": {
126-
...
127-
"hooks": ["send-mail"],
128-
"send-mail": {
129-
"type": "email",
130-
"levels": ["error", "warn", "fatal"],
131-
"config": {
132-
"application_name": "test-application-name",
133-
"host": "smtp.gmail.com",
134-
"port": 587,
135-
"from": "from-user@gmail.com",
136-
"to": "to-user@gmail.com",
137-
"username": "from-user@gmail.com",
138-
"password": "secret"
139-
}
140-
},
139+
"hooks": ["send-mail"],
140+
"send-mail": {
141+
"type": "email",
142+
"levels": ["error", "warn", "fatal", "panic"],
143+
"application_name": "test-application-name",
144+
"host": "smtp.gmail.com",
145+
"port": 587,
146+
"from": "from-user@gmail.com",
147+
"to": "to-user@gmail.com",
148+
"username": "from-user@gmail.com",
149+
"password": "secret"
150+
},
141151
}
142152
```
143153

144-
## Telegram bot hook configuration
154+
### Telegram bot hook configuration
145155

146-
```
147-
"hooks":["tg"],
148-
"tg": {
149-
"telegram_api_key": "7258436601:AAFlAm8gIGIyOTEv7lb9ipHcuB7YTR9-TuR",
150-
"telegram_chat_id": -4103253970,
151-
"disable_notification": false,
152-
"type": "telegram_bot",
153-
"levels": [
154-
"error",
155-
"panic"
156-
]
156+
```json
157+
"log": {
158+
"hooks":["tg"],
159+
"tg": {
160+
"telegram_api_key": "7258436601:AAFlAm8gIGIyOTEv7lb9ipHcuB7YTR9-TuR",
161+
"telegram_chat_id": -4103253970,
162+
"disable_notification": false,
163+
"type": "telegram_bot",
164+
"levels": [ "fatal", "panic"]
157165
},
166+
}
158167
```
159168

160-
## Adding new hooks implementations
161-
162-
Adding a new hook implementation is trivial. You should implement factory method
163-
which inputs hook configuration as [Viper](https://godoc.org/github.com/spf13/viper#Viper)
164-
config and returns new instance of the Hook structure. Then register the new hook
165-
type by calling RegisterHookType() function from init() method.
169+
### Adding new hooks implementations
166170

167-
Please see "email" hook implementation as example in hook.go file
171+
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
172+
type by calling RegisterHookType() function from init() method. Please see "email" hook implementation as example in hook.go file.

0 commit comments

Comments
 (0)