pax_global_header 0000666 0000000 0000000 00000000064 14741030435 0014513 g ustar 00root root 0000000 0000000 52 comment=c754b60f06075c830867aa06817e6b05ffa2eeac
slog-slack-2.7.3/ 0000775 0000000 0000000 00000000000 14741030435 0013563 5 ustar 00root root 0000000 0000000 slog-slack-2.7.3/.github/ 0000775 0000000 0000000 00000000000 14741030435 0015123 5 ustar 00root root 0000000 0000000 slog-slack-2.7.3/.github/FUNDING.yml 0000664 0000000 0000000 00000000021 14741030435 0016731 0 ustar 00root root 0000000 0000000 github: [samber]
slog-slack-2.7.3/.github/dependabot.yml 0000664 0000000 0000000 00000000303 14741030435 0017747 0 ustar 00root root 0000000 0000000 version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
slog-slack-2.7.3/.github/workflows/ 0000775 0000000 0000000 00000000000 14741030435 0017160 5 ustar 00root root 0000000 0000000 slog-slack-2.7.3/.github/workflows/lint.yml 0000664 0000000 0000000 00000000676 14741030435 0020662 0 ustar 00root root 0000000 0000000 name: Lint
on:
push:
pull_request:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: 1.21
stable: false
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
args: --timeout 120s --max-same-issues 50
- name: Bearer
uses: bearer/bearer-action@v2
slog-slack-2.7.3/.github/workflows/release.yml 0000664 0000000 0000000 00000002521 14741030435 0021323 0 ustar 00root root 0000000 0000000 name: Release
on:
workflow_dispatch:
inputs:
semver:
type: string
description: 'Semver (eg: v1.2.3)'
required: true
jobs:
release:
if: github.triggering_actor == 'samber'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21
stable: false
- name: Test
run: make test
# remove tests in order to clean dependencies
- name: Remove xxx_test.go files
run: rm -rf *_test.go ./examples ./images
# cleanup test dependencies
- name: Cleanup dependencies
run: go mod tidy
- name: List files
run: tree -Cfi
- name: Write new go.mod into logs
run: cat go.mod
- name: Write new go.sum into logs
run: cat go.sum
- name: Create tag
run: |
git config --global user.name '${{ github.triggering_actor }}'
git config --global user.email "${{ github.triggering_actor}}@users.noreply.github.com"
git add .
git commit --allow-empty -m 'bump ${{ inputs.semver }}'
git tag ${{ inputs.semver }}
git push origin ${{ inputs.semver }}
- name: Release
uses: softprops/action-gh-release@v2
with:
name: ${{ inputs.semver }}
tag_name: ${{ inputs.semver }}
slog-slack-2.7.3/.github/workflows/test.yml 0000664 0000000 0000000 00000001312 14741030435 0020657 0 ustar 00root root 0000000 0000000 name: Tests
on:
push:
tags:
branches:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
go:
- '1.21'
- '1.22'
- '1.x'
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
stable: false
- name: Build
run: make build
- name: Test
run: make test
- name: Test
run: make coverage
- name: Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./cover.out
flags: unittests
verbose: true
if: matrix.go == '1.21'
slog-slack-2.7.3/.gitignore 0000664 0000000 0000000 00000001365 14741030435 0015560 0 ustar 00root root 0000000 0000000
# Created by https://www.toptal.com/developers/gitignore/api/go
# Edit at https://www.toptal.com/developers/gitignore?templates=go
### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
### Go Patch ###
/vendor/
/Godeps/
# End of https://www.toptal.com/developers/gitignore/api/go
cover.out
cover.html
.vscode
.idea/
slog-slack-2.7.3/LICENSE 0000664 0000000 0000000 00000002056 14741030435 0014573 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2023 Samuel Berthe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
slog-slack-2.7.3/Makefile 0000664 0000000 0000000 00000002010 14741030435 0015214 0 ustar 00root root 0000000 0000000
build:
go build -v ./...
test:
go test -race -v ./...
watch-test:
reflex -t 50ms -s -- sh -c 'gotest -race -v ./...'
bench:
go test -benchmem -count 3 -bench ./...
watch-bench:
reflex -t 50ms -s -- sh -c 'go test -benchmem -count 3 -bench ./...'
coverage:
go test -v -coverprofile=cover.out -covermode=atomic ./...
go tool cover -html=cover.out -o cover.html
tools:
go install github.com/cespare/reflex@latest
go install github.com/rakyll/gotest@latest
go install github.com/psampaz/go-mod-outdated@latest
go install github.com/jondot/goweight@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go get -t -u golang.org/x/tools/cmd/cover
go install github.com/sonatype-nexus-community/nancy@latest
go mod tidy
lint:
golangci-lint run --timeout 60s --max-same-issues 50 ./...
lint-fix:
golangci-lint run --timeout 60s --max-same-issues 50 --fix ./...
audit:
go list -json -m all | nancy sleuth
outdated:
go list -u -m -json all | go-mod-outdated -update -direct
weight:
goweight
slog-slack-2.7.3/README.md 0000664 0000000 0000000 00000017666 14741030435 0015062 0 ustar 00root root 0000000 0000000
# slog: Slack handler
[](https://github.com/samber/slog-slack/releases)

[](https://pkg.go.dev/github.com/samber/slog-slack)

[](https://goreportcard.com/report/github.com/samber/slog-slack)
[](https://codecov.io/gh/samber/slog-slack)
[](https://github.com/samber/slog-slack/graphs/contributors)
[](./LICENSE)
A [Slack](https://slack.com) Handler for [slog](https://pkg.go.dev/golang.org/log/slog) Go library.
**See also:**
- [slog-multi](https://github.com/samber/slog-multi): `slog.Handler` chaining, fanout, routing, failover, load balancing...
- [slog-formatter](https://github.com/samber/slog-formatter): `slog` attribute formatting
- [slog-sampling](https://github.com/samber/slog-sampling): `slog` sampling policy
- [slog-mock](https://github.com/samber/slog-mock): `slog.Handler` for test purposes
**HTTP middlewares:**
- [slog-gin](https://github.com/samber/slog-gin): Gin middleware for `slog` logger
- [slog-echo](https://github.com/samber/slog-echo): Echo middleware for `slog` logger
- [slog-fiber](https://github.com/samber/slog-fiber): Fiber middleware for `slog` logger
- [slog-chi](https://github.com/samber/slog-chi): Chi middleware for `slog` logger
- [slog-http](https://github.com/samber/slog-http): `net/http` middleware for `slog` logger
**Loggers:**
- [slog-zap](https://github.com/samber/slog-zap): A `slog` handler for `Zap`
- [slog-zerolog](https://github.com/samber/slog-zerolog): A `slog` handler for `Zerolog`
- [slog-logrus](https://github.com/samber/slog-logrus): A `slog` handler for `Logrus`
**Log sinks:**
- [slog-datadog](https://github.com/samber/slog-datadog): A `slog` handler for `Datadog`
- [slog-betterstack](https://github.com/samber/slog-betterstack): A `slog` handler for `Betterstack`
- [slog-rollbar](https://github.com/samber/slog-rollbar): A `slog` handler for `Rollbar`
- [slog-loki](https://github.com/samber/slog-loki): A `slog` handler for `Loki`
- [slog-sentry](https://github.com/samber/slog-sentry): A `slog` handler for `Sentry`
- [slog-syslog](https://github.com/samber/slog-syslog): A `slog` handler for `Syslog`
- [slog-logstash](https://github.com/samber/slog-logstash): A `slog` handler for `Logstash`
- [slog-fluentd](https://github.com/samber/slog-fluentd): A `slog` handler for `Fluentd`
- [slog-graylog](https://github.com/samber/slog-graylog): A `slog` handler for `Graylog`
- [slog-quickwit](https://github.com/samber/slog-quickwit): A `slog` handler for `Quickwit`
- [slog-slack](https://github.com/samber/slog-slack): A `slog` handler for `Slack`
- [slog-telegram](https://github.com/samber/slog-telegram): A `slog` handler for `Telegram`
- [slog-mattermost](https://github.com/samber/slog-mattermost): A `slog` handler for `Mattermost`
- [slog-microsoft-teams](https://github.com/samber/slog-microsoft-teams): A `slog` handler for `Microsoft Teams`
- [slog-webhook](https://github.com/samber/slog-webhook): A `slog` handler for `Webhook`
- [slog-kafka](https://github.com/samber/slog-kafka): A `slog` handler for `Kafka`
- [slog-nats](https://github.com/samber/slog-nats): A `slog` handler for `NATS`
- [slog-parquet](https://github.com/samber/slog-parquet): A `slog` handler for `Parquet` + `Object Storage`
- [slog-channel](https://github.com/samber/slog-channel): A `slog` handler for Go channels
## 🚀 Install
```sh
go get github.com/samber/slog-slack/v2
```
**Compatibility**: go >= 1.21
No breaking changes will be made to exported APIs before v3.0.0.
## 💡 Usage
GoDoc: [https://pkg.go.dev/github.com/samber/slog-slack/v2](https://pkg.go.dev/github.com/samber/slog-slack/v2)
### Handler options
```go
type Option struct {
// log level (default: debug)
Level slog.Leveler
// slack webhook url
WebhookURL string
// slack bot token
BotToken string
// slack channel (default: webhook channel)
Channel string
// bot username (default: webhook username)
Username string
// bot emoji (default: webhook emoji)
IconEmoji string
// bot emoji (default: webhook emoji)
IconURL string
// Not implemented yet, but we would like your feedback here: #7
// ThreadTimestamp string
// API request timeout (default: 10s)
Timeout time.Duration
// optional: customize Slack message builder
Converter Converter
// optional: see slog.HandlerOptions
AddSource bool
ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
}
```
Attributes will be injected in message attachments.
Other global parameters:
```go
slogslack.SourceKey = "source"
slogslack.ColorMapping = map[slog.Level]string{...}
```

### Example
#### Using webhook
Generate a webhook [here](https://slack.com/apps/A0F7XDUAZ-incoming-webhooks).
```go
import (
slogslack "github.com/samber/slog-slack/v2"
"log/slog"
)
func main() {
webhook := "https://hooks.slack.com/services/xxx/yyy/zzz"
channel := "alerts"
logger := slog.New(slogslack.Option{Level: slog.LevelError, WebhookURL: webhook, Channel: channel}.NewSlackHandler())
logger = logger.
With("environment", "dev").
With("release", "v1.0.0")
// log error
logger.
With("category", "sql").
With("query.statement", "SELECT COUNT(*) FROM users;").
With("query.duration", 1*time.Second).
With("error", fmt.Errorf("could not count users")).
Error("caramba!")
// log user signup
logger.
With(
slog.Group("user",
slog.String("id", "user-123"),
slog.Time("created_at", time.Now()),
),
).
Info("user registration")
// push record to a thread
logger.ErrorContext(
slogslack.WithThreadTimestamp(context.Background(), "1714929099.4238"),
"An error",
)
}
```
#### Using bot token
Use [Bot token](https://api.slack.com/authentication/token-types#bot).
```go
import (
slogslack "github.com/samber/slog-slack/v2"
"log/slog"
)
func main() {
token := "xoxb-"
channel := "alerts"
logger := slog.New(slogslack.Option{Level: slog.LevelError, BotToken: token, Channel: channel}.NewSlackHandler())
logger = logger.
With("environment", "dev").
With("release", "v1.0.0")
}
```
## 🤝 Contributing
- Ping me on twitter [@samuelberthe](https://twitter.com/samuelberthe) (DMs, mentions, whatever :))
- Fork the [project](https://github.com/samber/slog-slack)
- Fix [open issues](https://github.com/samber/slog-slack/issues) or request new features
Don't hesitate ;)
```bash
# Install some dev dependencies
make tools
# Run tests
make test
# or
make watch-test
```
## 👤 Contributors

## 💫 Show your support
Give a ⭐️ if this project helped you!
[](https://github.com/sponsors/samber)
## 📝 License
Copyright © 2023 [Samuel Berthe](https://github.com/samber).
This project is [MIT](./LICENSE) licensed.
slog-slack-2.7.3/context.go 0000664 0000000 0000000 00000001356 14741030435 0015603 0 ustar 00root root 0000000 0000000 package slogslack
import "context"
type threadTimestampCtxKey struct{}
// reply in thread to posts with timestamps set this
func WithThreadTimestamp(ctx context.Context, ts string) context.Context {
return context.WithValue(ctx, threadTimestampCtxKey{}, ts)
}
func contextThreadTimestamp(ctx context.Context) string {
if v, ok := ctx.Value(threadTimestampCtxKey{}).(string); ok {
return v
}
return ""
}
type replyBroadcastCtxKey struct{}
// broadcast to channel when replies to thread if set
func WithReplyBroadcast(ctx context.Context) context.Context {
return context.WithValue(ctx, replyBroadcastCtxKey{}, true)
}
func contextReplyBroadcast(ctx context.Context) bool {
_, ok := ctx.Value(replyBroadcastCtxKey{}).(bool)
return ok
}
slog-slack-2.7.3/converter.go 0000664 0000000 0000000 00000003072 14741030435 0016123 0 ustar 00root root 0000000 0000000 package slogslack
import (
"log/slog"
slogcommon "github.com/samber/slog-common"
"github.com/slack-go/slack"
)
var SourceKey = "source"
type Converter func(addSource bool, replaceAttr func(groups []string, a slog.Attr) slog.Attr, loggerAttr []slog.Attr, groups []string, record *slog.Record) *slack.WebhookMessage
func DefaultConverter(addSource bool, replaceAttr func(groups []string, a slog.Attr) slog.Attr, loggerAttr []slog.Attr, groups []string, record *slog.Record) *slack.WebhookMessage {
// aggregate all attributes
attrs := slogcommon.AppendRecordAttrsToAttrs(loggerAttr, groups, record)
// developer formatters
if addSource {
attrs = append(attrs, slogcommon.Source(SourceKey, record))
}
attrs = slogcommon.ReplaceAttrs(replaceAttr, []string{}, attrs...)
attrs = slogcommon.RemoveEmptyAttrs(attrs)
// handler formatter
message := &slack.WebhookMessage{}
message.Text = record.Message
message.Attachments = []slack.Attachment{
{
Color: ColorMapping[record.Level],
Fields: []slack.AttachmentField{},
},
}
attrToSlackMessage("", attrs, message)
return message
}
func attrToSlackMessage(base string, attrs []slog.Attr, message *slack.WebhookMessage) {
for i := range attrs {
attr := attrs[i]
k := attr.Key
v := attr.Value
kind := attr.Value.Kind()
if kind == slog.KindGroup {
attrToSlackMessage(base+k+".", v.Group(), message)
} else {
field := slack.AttachmentField{}
field.Title = base + k
field.Value = slogcommon.ValueToString(v)
message.Attachments[0].Fields = append(message.Attachments[0].Fields, field)
}
}
}
slog-slack-2.7.3/example/ 0000775 0000000 0000000 00000000000 14741030435 0015216 5 ustar 00root root 0000000 0000000 slog-slack-2.7.3/example/example.go 0000664 0000000 0000000 00000001124 14741030435 0017176 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"time"
"log/slog"
slogslack "github.com/samber/slog-slack/v2"
)
func main() {
webhook := "https://hooks.slack.com/services/xxx/yyy/zzz"
channel := "alerts"
logger := slog.New(slogslack.Option{Level: slog.LevelDebug, WebhookURL: webhook, Channel: channel}.NewSlackHandler())
logger = logger.With("release", "v1.0.0")
logger.
With(
slog.Group("user",
slog.String("id", "user-123"),
slog.Time("created_at", time.Now().AddDate(0, 0, -1)),
),
).
With("environment", "dev").
With("error", fmt.Errorf("an error")).
Error("A message")
}
slog-slack-2.7.3/go.mod 0000664 0000000 0000000 00000000564 14741030435 0014676 0 ustar 00root root 0000000 0000000 module github.com/samber/slog-slack/v2
go 1.21
require (
github.com/samber/slog-common v0.18.1
github.com/slack-go/slack v0.15.0
)
require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/samber/lo v1.47.0 // indirect
github.com/stretchr/testify v1.10.0 // indirect
golang.org/x/text v0.16.0 // indirect
)
slog-slack-2.7.3/go.sum 0000664 0000000 0000000 00000004127 14741030435 0014722 0 ustar 00root root 0000000 0000000 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/samber/slog-common v0.18.1 h1:c0EipD/nVY9HG5shgm/XAs67mgpWDMF+MmtptdJNCkQ=
github.com/samber/slog-common v0.18.1/go.mod h1:QNZiNGKakvrfbJ2YglQXLCZauzkI9xZBjOhWFKS3IKk=
github.com/slack-go/slack v0.15.0 h1:LE2lj2y9vqqiOf+qIIy0GvEoxgF1N5yLGZffmEZykt0=
github.com/slack-go/slack v0.15.0/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
slog-slack-2.7.3/handler.go 0000664 0000000 0000000 00000006607 14741030435 0015540 0 ustar 00root root 0000000 0000000 package slogslack
import (
"context"
"time"
"log/slog"
slogcommon "github.com/samber/slog-common"
"github.com/slack-go/slack"
)
type Option struct {
// log level (default: debug)
Level slog.Leveler
// slack webhook url
WebhookURL string
// slack bot token
BotToken string
// slack channel (default: webhook channel)
Channel string
// bot username (default: webhook username)
Username string
// bot emoji (default: webhook emoji)
IconEmoji string
// bot emoji (default: webhook emoji)
IconURL string
// API request timeout (default: 10s)
Timeout time.Duration
// optional: customize Slack message builder
Converter Converter
// optional: see slog.HandlerOptions
AddSource bool
ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
}
func (o Option) NewSlackHandler() slog.Handler {
if o.Level == nil {
o.Level = slog.LevelDebug
}
if o.WebhookURL == "" && o.BotToken == "" {
panic("missing Slack webhook url and bot token")
}
if o.Timeout == 0 {
o.Timeout = 10 * time.Second
}
if o.Converter == nil {
o.Converter = DefaultConverter
}
return &SlackHandler{
option: o,
attrs: []slog.Attr{},
groups: []string{},
}
}
var _ slog.Handler = (*SlackHandler)(nil)
type SlackHandler struct {
option Option
attrs []slog.Attr
groups []string
}
func (h *SlackHandler) Enabled(_ context.Context, level slog.Level) bool {
return level >= h.option.Level.Level()
}
func (h *SlackHandler) Handle(ctx context.Context, record slog.Record) error {
message := h.option.Converter(h.option.AddSource, h.option.ReplaceAttr, h.attrs, h.groups, &record)
if h.option.Channel != "" {
message.Channel = h.option.Channel
}
if h.option.Username != "" {
message.Username = h.option.Username
}
if h.option.IconEmoji != "" {
message.IconEmoji = h.option.IconEmoji
}
if h.option.IconURL != "" {
message.IconURL = h.option.IconURL
}
if ts := contextThreadTimestamp(ctx); ts != "" {
message.ThreadTimestamp = ts
if contextReplyBroadcast(ctx) {
message.ReplyBroadcast = true
}
}
// non-blocking
go func() {
_ = h.postMessage(ctx, message)
}()
return nil
}
func (h *SlackHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
return &SlackHandler{
option: h.option,
attrs: slogcommon.AppendAttrsToGroup(h.groups, h.attrs, attrs...),
groups: h.groups,
}
}
func (h *SlackHandler) WithGroup(name string) slog.Handler {
// https://cs.opensource.google/go/x/exp/+/46b07846:slog/handler.go;l=247
if name == "" {
return h
}
return &SlackHandler{
option: h.option,
attrs: h.attrs,
groups: append(h.groups, name),
}
}
func (h *SlackHandler) postMessage(ctx context.Context, message *slack.WebhookMessage) error {
ctx, cancel := context.WithTimeout(ctx, h.option.Timeout)
defer cancel()
if h.option.WebhookURL != "" {
return slack.PostWebhookContext(ctx, h.option.WebhookURL, message)
}
options := []slack.MsgOption{
slack.MsgOptionText(message.Text, true),
slack.MsgOptionAttachments(message.Attachments...),
slack.MsgOptionUsername(message.Username),
slack.MsgOptionIconURL(message.IconURL),
slack.MsgOptionIconEmoji(message.IconEmoji),
}
if message.ThreadTimestamp != "" {
options = append(options, slack.MsgOptionTS(message.ThreadTimestamp))
}
if message.ReplyBroadcast {
options = append(options, slack.MsgOptionBroadcast())
}
_, _, err := slack.New(h.option.BotToken).PostMessageContext(ctx, message.Channel, options...)
return err
}
slog-slack-2.7.3/screenshot.png 0000664 0000000 0000000 00000056037 14741030435 0016461 0 ustar 00root root 0000000 0000000 PNG
IHDR w q;Ul
iCCPICC Profile HPS{oz$!RBM"@J$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