Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iktakahiro/slclogger
Simple and Human Friendly Slack Client for Logging Written in Go Programming Language
https://github.com/iktakahiro/slclogger
go golang logging slack slack-client
Last synced: 11 days ago
JSON representation
Simple and Human Friendly Slack Client for Logging Written in Go Programming Language
- Host: GitHub
- URL: https://github.com/iktakahiro/slclogger
- Owner: iktakahiro
- License: mit
- Created: 2016-12-09T11:55:15.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-14T01:34:54.000Z (over 5 years ago)
- Last Synced: 2024-09-28T09:16:38.941Z (about 1 month ago)
- Topics: go, golang, logging, slack, slack-client
- Language: Go
- Homepage:
- Size: 84 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SlcLogger
[![Build Status](https://travis-ci.org/iktakahiro/slclogger.svg?branch=master)](https://travis-ci.org/iktakahiro/slclogger)
**Simple and Human Friendly Slack Client for Logging/Notification written in Go**
## Install
```bash
go get "github.com/iktakahiro/slclogger/v2"
```## How to Use
### Basic Usage
```go
package mainimport (
"errors""github.com/iktakahiro/slclogger/v2"
)func something() error {
return errors.New("an error has occurred")
}func main() {
logger, _ := slclogger.NewSlcLogger(&slclogger.LoggerParams{
WebHookURL: "https://hooks.slack.com/services/YOUR_WEBHOOK_URL",
})if err := something(); err != nil {
logger.Error(err, "Error Notification")
}
}
```When you execute the above sample code, your Slack channel will receive the message.
![](./example/example-slack1.png)
### Log Levels
The default log level is *Info*. You can set it when initializing a SlcLogger struct.
```go
package mainimport (
"github.com/iktakahiro/slclogger/v2"
)func main() {
logger, _ := slclogger.NewSlcLogger(&slclogger.LoggerParams{
WebHookURL: "https://hooks.slack.com/services/YOUR_WEBHOOK_URL",
LogLevel: slclogger.LevelDebug,
})logger.Debug("Debug Message")
logger.Info("Info Message")
logger.Warn("Warn Message")
logger.Error("Error Message")
}
```![](./example/example-slack2.png)
You can also change the level at any time.
```go
package mainimport (
"github.com/iktakahiro/slclogger/v2"
)func main() {
logger, _ := slclogger.NewSlcLogger(&slclogger.LoggerParams{
WebHookURL: "https://hooks.slack.com/services/YOUR_WEBHOOK_URL",
})logger.SetLogLevel(slclogger.LevelWarn)
// The following notification will be ignored.
logger.Debug("Debug Message")
}
```### Configure Options
All options are shown below.
```go
package mainimport (
"github.com/iktakahiro/slclogger/v2"
)func main() {
logger, err := slclogger.NewSlcLogger(&slclogger.LoggerParams{
WebHookURL: "https://hooks.slack.com/services/YOUR_WEBHOOK_URL",
DefaultTitle: "Default Title",
DefaultChannel: "general",
DebugChannel: "debug-channel",
InfoChannel: "info-channel",
WarnChannel : "warn-channel",
ErrorChannel : "error-channel",
LogLevel: slclogger.LevelWarn,
IconURL: "https://example.com",
UserName: "My Logger",
})
}
```Param | Default Value
------ | ------------
WebHookURL (*require*) | --
DefaultTitle | "Notification"
DefaultChannel | "" (When this param is omitted, the default channel of specified WebHook is used.)
DebugChannel | "" (When this param is omitted, the value of DefaultChannel is used.)
InfoChannel | "" (When this param is omitted, the value of DefaultChannel is used.)
WarnChannel | "" (When this param is omitted, the value of DefaultChannel is used.)
ErrorChannel | "" (When this param is omitted, the value of DefaultChannel is used.)
LogLevel | Info
IconURL | ""
UseName | ""## Error Handling
If you want to handle errors, use SlcErr.
```go
if err := logger.Info("info message"); err != nil {
if slcErr, ok := err.(*slclogger.SlcErr); ok {
fmt.Println(slcErr)
fmt.Println(slcErr.Code)
}
}
```## Test
```bash
make test
```## Documents
- [slclogger \- GoDoc](https://godoc.org/github.com/iktakahiro/slclogger)