From 93fdcad71baf07768b62f22df1dafdeb76e82963 Mon Sep 17 00:00:00 2001 From: alexferl Date: Wed, 23 Apr 2025 21:03:52 -0400 Subject: [PATCH] update repo and deps --- .dockerignore | 4 +- .github/workflows/lint.yaml | 33 ++++++++++ .github/workflows/pre-commit.yaml | 24 +++++++ .github/workflows/test.yaml | 41 ++++++++---- .gitignore | 40 ++++++----- .golangci.yml | 4 ++ .pre-commit-config.yaml | 18 +++++ Dockerfile | 14 ++-- Makefile | 73 +++++++++++--------- README.md | 47 ++++++------- cmd/tinysyslogd/main.go | 4 +- config/config.go | 70 +++++--------------- factories/factories.go | 40 ++++------- factories/factories_test.go | 6 +- filters/regex.go | 2 +- go.mod | 45 +++++-------- go.sum | 106 ++++++++++-------------------- mutators/json.go | 2 +- mutators/log.go | 2 +- server/server.go | 8 +-- server/server_test.go | 2 +- sinks/console.go | 6 +- sinks/elasticsearch.go | 94 -------------------------- sinks/interface.go | 5 +- testing/testing.go | 2 +- 25 files changed, 303 insertions(+), 389 deletions(-) create mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/pre-commit.yaml create mode 100644 .golangci.yml create mode 100644 .pre-commit-config.yaml delete mode 100644 sinks/elasticsearch.go diff --git a/.dockerignore b/.dockerignore index f7a70c3..b826e3e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,9 @@ *.log +.dockerignore .git .gitignore .idea LICENSE -README* +README.md +Makefile tinysyslog-bin diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..dd50ee2 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,33 @@ +name: golangci-lint +on: + push: + branches: + - master + - main + pull_request: + +permissions: + # Required: allow read access to the content for analysis. + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + pull-requests: read + # Optional: Allow write access to checks to allow the action to annotate code in the PR. + checks: write + +jobs: + unit: + name: lint + runs-on: ubuntu-latest + steps: + - name: Fetch Repository + uses: actions/checkout@v4 + + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: '1.23.x' + + - name: golangci-lint + uses: golangci/golangci-lint-action@v7 + with: + version: v2.0.2 diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 0000000..742133d --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,24 @@ +name: pre-commit + +on: + push: + branches: + - master + - main + pull_request: + +jobs: + unit: + name: pre-commit + runs-on: ubuntu-latest + steps: + - name: Fetch Repository + uses: actions/checkout@v4 + + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Install pre-commit + uses: pre-commit/action@v3.0.1 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3dca47e..fdf13c3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,20 +1,35 @@ -name: Test and coverage +name: test -on: [push, pull_request] +on: + push: + branches: + - master + - main + pull_request: jobs: - build: - runs-on: ubuntu-latest + unit: + strategy: + matrix: + go-version: [ '1.23.x', '1.24.x' ] + os: [ macos-latest, ubuntu-latest] + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 2 - - uses: actions/setup-go@v5 + - name: Fetch Repository + uses: actions/checkout@v4 + + - name: Install Go + uses: actions/setup-go@v5 with: - go-version: '1.22' - - name: Run coverage - run: go test -race -coverprofile=coverage.out -covermode=atomic ./... - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 + go-version: ${{ matrix.go-version }} + + - name: Test + run: go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=1 -coverprofile=coverage.txt -covermode=atomic -shuffle=on + + - name: Upload coverage reports to Codecov + if: ${{ matrix.os == 'ubuntu-latest' && matrix.go-version == '1.23.x' }} + uses: codecov/codecov-action@v5.4.0 with: token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.txt + flags: unittests diff --git a/.gitignore b/.gitignore index 1ea6428..39f1dc2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,29 +1,27 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a +# 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 -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out +# Test binary, built with `go test -c` +*.test -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* +# Output of the go coverage tool, specifically when used with LiteIDE +*.out -_testmain.go +# Dependency directories (remove the comment below to include it) +# vendor/ -*.exe -*.test -*.prof +# Go workspace file +go.work -*.out -*.log +# GoLand .idea + +# binary tinysyslog-bin diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..b4f8404 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,4 @@ +version: "2" +formatters: + enable: + - gofumpt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4d85789 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-case-conflict + - id: check-json + - id: check-merge-conflict + - id: check-toml + - id: check-yaml + args: ["--allow-multiple-documents"] + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: mixed-line-ending + args: ["--fix=lf"] + - id: pretty-format-json + args: ["--autofix", "--indent=2", "--no-sort-keys"] + files: \.json$ + - id: trailing-whitespace diff --git a/Dockerfile b/Dockerfile index cb87ad2..0322569 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,12 @@ -FROM golang:1.22.2-alpine3.19 as builder -MAINTAINER Alexandre Ferland +FROM golang:1.24.2-alpine as builder +LABEL maintainer="Alexandre Ferland " WORKDIR /build RUN apk add --no-cache git +RUN adduser -D -u 1337 tinysyslog -COPY go.mod . -COPY go.sum . - +COPY go.mod go.sum ./ RUN go mod download COPY . . @@ -15,8 +14,11 @@ COPY . . RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./cmd/tinysyslogd FROM scratch +COPY --from=builder /etc/passwd /etc/passwd COPY --from=builder /build/tinysyslogd /tinysyslogd -EXPOSE 5140 5140/udp +USER tinysyslog + +EXPOSE 5140/tcp 5140/udp ENTRYPOINT ["/tinysyslogd", "--bind-addr", "0.0.0.0:5140"] diff --git a/Makefile b/Makefile index 03e5e04..f6c8836 100644 --- a/Makefile +++ b/Makefile @@ -1,32 +1,38 @@ -.PHONY: dev run test cover cover-html fmt pre-commit docker-build docker-run +.PHONY: dev audit cover cover-html fmt lint pre-commit run test tidy update-deps docker-build docker-run .DEFAULT: help help: @echo "make dev" @echo " setup development environment" - @echo "make run" - @echo " run app" - @echo "make test" - @echo " run go test" + @echo "make audit" + @echo " conduct quality checks" @echo "make cover" - @echo " run go test with -cover" + @echo " generate coverage report" @echo "make cover-html" - @echo " run go test with -cover and show HTML" - @echo "make tidy" - @echo " run go mod tidy" + @echo " generate coverage HTML report" @echo "make fmt" - @echo " run gofumpt" + @echo " fix code format issues" + @echo "make lint" + @echo " run lint checks" @echo "make pre-commit" @echo " run pre-commit hooks" + @echo "make run" + @echo " run application" + @echo "make test" + @echo " execute all tests" + @echo "make tidy" + @echo " clean and tidy dependencies" + @echo "make update-deps" + @echo " update dependencies" @echo "make docker-build" @echo " build docker image" @echo "make docker-run" @echo " run docker image" -check-gofumpt: -ifeq (, $(shell which gofumpt)) - $(error "gofumpt not in $(PATH), gofumpt (https://pkg.go.dev/mvdan.cc/gofumpt) is required") -endif +GOTESTSUM := go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=1 +TESTFLAGS := -shuffle=on +COVERFLAGS := -covermode=atomic +GOLANGCI_LINT := go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2 check-pre-commit: ifeq (, $(shell which pre-commit)) @@ -36,33 +42,40 @@ endif dev: check-pre-commit pre-commit install -run: - go build -o tinysyslog-bin ./cmd/tinysyslogd && ./tinysyslog-bin - -build: - go build -o tinysyslog-bin ./cmd/tinysyslogd - -test: - go test -v ./... +audit: + go mod verify + go run golang.org/x/vuln/cmd/govulncheck@latest ./... cover: - go test -cover -v ./... + $(GOTESTSUM) $(TESTFLAGS) $(COVERFLAGS) cover-html: - go test -v -coverprofile=coverage.out ./... + $(GOTESTSUM) $(TESTFLAGS) $(COVERFLAGS) -coverprofile=coverage.out go tool cover -html=coverage.out -tidy: - go mod tidy +fmt: + $(GOLANGCI_LINT) fmt -fmt: check-gofumpt - gofumpt -l -w . +lint: + $(GOLANGCI_LINT) run pre-commit: check-pre-commit - pre-commit + pre-commit run --all-files + +run: + go build -o tinysyslog-bin ./cmd/tinysyslogd && ./tinysyslog-bin + +test: + $(GOTESTSUM) $(TESTFLAGS) + +tidy: + go mod tidy -v + +update-deps: tidy + go get -u ./... docker-build: docker build -t tinysyslog . docker-run: - docker run -p 5140:5140/udp --rm tinysyslog + docker run --name tinysyslog --rm -p 5140:5140/udp tinysyslog diff --git a/README.md b/README.md index 5dc9e72..22d3f2a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # tinysyslog [![Go Report Card](https://goreportcard.com/badge/github.com/alexferl/tinysyslog)](https://goreportcard.com/report/github.com/alexferl/tinysyslog) [![codecov](https://codecov.io/gh/alexferl/tinysyslog/branch/master/graph/badge.svg)](https://codecov.io/gh/alexferl/tinysyslog) -A tiny and simple syslog server with log rotation. tinysyslog was born out of the need for a tiny, easy to set up and -use syslog server that simply writes every incoming log (in [RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424) format **only**) to a file that is automatically rotated, -to stdout or stderr (mostly for Docker) and or to Elasticsearch. +A tiny and simple syslog server with log rotation. tinysyslog was born out of the need for a tiny, easy to set up and +use syslog server that simply writes every incoming log (in [RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424) format **only**) to a file that is automatically rotated, +to stdout or stderr (mostly for Docker). tinysyslog is based on [go-syslog](https://github.com/mcuadros/go-syslog) and [lumberjack](https://github.com/natefinch/lumberjack). ## Quickstart @@ -32,7 +32,7 @@ Download the image: ```shell docker pull admiralobvious/tinysyslog ``` - + Start the container: ```shell docker run --rm --name tinysyslog -p 5140:5140/udp -d admiralobvious/tinysyslog @@ -85,27 +85,20 @@ You can now send logs from your app(s) to `tinysyslog:5140`. ## Configuration ``` Usage of ./tinysyslogd: - --app-name string The name of the application. (default "tinysyslog") - --bind-addr string IP and port to listen on. (default "127.0.0.1:5140") - --env-name string The environment of the application. Used to load the right configs file. (default "PROD") - --filter string Filter to filter logs with. Valid filters: [regex] - --filter-regex string Regex to filter with. - --log-level string The granularity of log outputs. Valid levels: [PANIC FATAL ERROR WARN INFO DISABLED TRACE DISABLED] (default "INFO") - --log-output string The output to write to. Valid outputs: [stdout stderr] (default "stdout") - --log-writer string The log writer. Valid writers: [console json] (default "console") - --mutator string Mutator type to use. Valid mutators: [text json] (default "text") - --sink-console-output string Console to output to. Valid outputs: [stdout stderr] (default "stdout") - --sink-elasticsearch-addresses strings Elasticsearch server addresses. - --sink-elasticsearch-api-key string Elasticsearch api key. - --sink-elasticsearch-cloud-id string Elasticsearch cloud id. - --sink-elasticsearch-index-name string Elasticsearch index name. (default "tinysyslog") - --sink-elasticsearch-password string Elasticsearch password. - --sink-elasticsearch-service-token string Elasticsearch service token. - --sink-elasticsearch-username string Elasticsearch username. - --sink-filesystem-filename string File path to write incoming logs to. (default "syslog.log") - --sink-filesystem-max-age int Maximum age (in days) before a log is deleted. (default 30) - --sink-filesystem-max-backups int Maximum backups to keep. (default 10) - --sink-filesystem-max-size int Maximum log size (in megabytes) before it's rotated. (default 100) - --sinks strings Sinks to save syslogs to. Valid sinks: [console elasticsearch filesystem] (default [console]) - --socket-type string Type of socket to use, TCP or UDP. If no type is specified, both are used. + --app-name string The name of the application. (default "tinysyslog") + --bind-addr string IP and port to listen on. (default "127.0.0.1:5140") + --env-name string The environment of the application. Used to load the right configs file. (default "PROD") + --filter string Filter to filter logs with. Valid filters: [noop regex] + --filter-regex string Regex to filter with. + --log-level string The granularity of log outputs. Valid levels: [PANIC FATAL ERROR WARN INFO DISABLED TRACE DISABLED] (default "INFO") + --log-output string The output to write to. Valid outputs: [stdout stderr] (default "stdout") + --log-writer string The log writer. Valid writers: [console json] (default "console") + --mutator string Mutator type to use. Valid mutators: [text json] (default "text") + --sink-console-output string Console to output to. Valid outputs: [stdout stderr] (default "stdout") + --sink-filesystem-filename string File path to write incoming logs to. (default "syslog.log") + --sink-filesystem-max-age int Maximum age (in days) before a log is deleted. (default 30) + --sink-filesystem-max-backups int Maximum backups to keep. (default 10) + --sink-filesystem-max-size int Maximum log size (in megabytes) before it's rotated. (default 100) + --sinks strings Sinks to save syslogs to. Valid sinks: [console filesystem] (default [console]) + --socket-type string Type of socket to use, TCP or UDP. If no type is specified, both are used. ``` diff --git a/cmd/tinysyslogd/main.go b/cmd/tinysyslogd/main.go index 8795bf0..3b1f8d9 100644 --- a/cmd/tinysyslogd/main.go +++ b/cmd/tinysyslogd/main.go @@ -3,8 +3,8 @@ package main import ( "github.com/rs/zerolog/log" - "tinysyslog/config" - "tinysyslog/server" + "github.com/alexferl/tinysyslog/config" + "github.com/alexferl/tinysyslog/server" ) func main() { diff --git a/config/config.go b/config/config.go index e5489d1..59ab790 100644 --- a/config/config.go +++ b/config/config.go @@ -8,28 +8,27 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" - "tinysyslog/constants" - "tinysyslog/filters" - "tinysyslog/mutators" - "tinysyslog/sinks" + "github.com/alexferl/tinysyslog/constants" + "github.com/alexferl/tinysyslog/filters" + "github.com/alexferl/tinysyslog/mutators" + "github.com/alexferl/tinysyslog/sinks" ) // Config holds all configuration for our program type Config struct { - Config *libConfig.Config - Logging *libLog.Config - BindAddr string - ConsoleSink ConsoleSink - ElasticSearchSink ElasticSearchSink - FilesystemSink FilesystemSink - FilterType string - LogFile string - LogFormat string - LogLevel string - MutatorType string - RegexFilter RegexFilter - SinkTypes []string - SocketType string + Config *libConfig.Config + Logging *libLog.Config + BindAddr string + ConsoleSink ConsoleSink + FilesystemSink FilesystemSink + FilterType string + LogFile string + LogFormat string + LogLevel string + MutatorType string + RegexFilter RegexFilter + SinkTypes []string + SocketType string } // ConsoleSink holds all configuration for the ConsoleSink sink @@ -37,16 +36,6 @@ type ConsoleSink struct { Output string } -type ElasticSearchSink struct { - Addresses []string - IndexName string - Username string - Password string - CloudID string - APIKey string - ServiceToken string -} - // FilesystemSink holds all configuration for the FilesystemSink sink type FilesystemSink struct { Filename string @@ -73,9 +62,6 @@ func New() *Config { ConsoleSink: ConsoleSink{ Output: constants.ConsoleStdOut, }, - ElasticSearchSink: ElasticSearchSink{ - IndexName: "tinysyslog", - }, FilesystemSink: FilesystemSink{ Filename: "syslog.log", MaxAge: 30, @@ -107,14 +93,6 @@ const ( SinkConsoleOutput = "sink-console-output" - SinkElasticsearchAddresses = "sink-elasticsearch-addresses" - SinkElasticsearchIndexName = "sink-elasticsearch-index-name" - SinkElasticsearchUsername = "sink-elasticsearch-username" - SinkElasticsearchPassword = "sink-elasticsearch-password" - SinkElasticsearchCloudID = "sink-elasticsearch-cloud-id" - SinkElasticsearchAPIKey = "sink-elasticsearch-api-key" - SinkElasticsearchServiceToken = "sink-elasticsearch-service-token" - SinkFilesystemFilename = "sink-filesystem-filename" SinkFilesystemMaxAge = "sink-filesystem-max-age" SinkFilesystemMaxBackups = "sink-filesystem-max-backups" @@ -138,20 +116,6 @@ func (c *Config) addFlags(fs *pflag.FlagSet) { ) fs.StringVar(&c.ConsoleSink.Output, SinkConsoleOutput, c.ConsoleSink.Output, fmt.Sprintf("Console to output to. Valid outputs: %s", constants.ConsoleOutputs)) - fs.StringSliceVar(&c.ElasticSearchSink.Addresses, SinkElasticsearchAddresses, c.ElasticSearchSink.Addresses, - "Elasticsearch server addresses.") - fs.StringVar(&c.ElasticSearchSink.IndexName, SinkElasticsearchIndexName, c.ElasticSearchSink.IndexName, - "Elasticsearch index name.") - fs.StringVar(&c.ElasticSearchSink.Username, SinkElasticsearchUsername, c.ElasticSearchSink.Username, - "Elasticsearch username.") - fs.StringVar(&c.ElasticSearchSink.Password, SinkElasticsearchPassword, c.ElasticSearchSink.Password, - "Elasticsearch password.") - fs.StringVar(&c.ElasticSearchSink.CloudID, SinkElasticsearchCloudID, c.ElasticSearchSink.CloudID, - "Elasticsearch cloud id.") - fs.StringVar(&c.ElasticSearchSink.APIKey, SinkElasticsearchAPIKey, c.ElasticSearchSink.APIKey, - "Elasticsearch api key.") - fs.StringVar(&c.ElasticSearchSink.ServiceToken, SinkElasticsearchServiceToken, c.ElasticSearchSink.ServiceToken, - "Elasticsearch service token.") fs.StringVar(&c.FilesystemSink.Filename, SinkFilesystemFilename, c.FilesystemSink.Filename, "File path to write incoming logs to.") fs.IntVar(&c.FilesystemSink.MaxAge, SinkFilesystemMaxAge, c.FilesystemSink.MaxAge, diff --git a/factories/factories.go b/factories/factories.go index 51891e7..03c5494 100644 --- a/factories/factories.go +++ b/factories/factories.go @@ -2,16 +2,15 @@ package factories import ( "os" - "time" "github.com/rs/zerolog/log" "github.com/spf13/viper" - "tinysyslog/config" - "tinysyslog/constants" - "tinysyslog/filters" - "tinysyslog/mutators" - "tinysyslog/sinks" + "github.com/alexferl/tinysyslog/config" + "github.com/alexferl/tinysyslog/constants" + "github.com/alexferl/tinysyslog/filters" + "github.com/alexferl/tinysyslog/mutators" + "github.com/alexferl/tinysyslog/sinks" ) // Mutator creates a new object with mutators.Mutator interface @@ -54,7 +53,6 @@ func Filter() filters.Filter { // Sinks creates a new slice of objects with sinks.Sink interface func Sinks() []sinks.Sink { sinksSlice := viper.GetStringSlice(config.Sinks) - mutatorType := viper.GetString(config.Mutator) var sinksList []sinks.Sink @@ -64,35 +62,19 @@ func Sinks() []sinks.Sink { cOutput := viper.GetString(config.SinkConsoleOutput) var stdOutput *os.File - if cOutput == constants.ConsoleStdOut { + switch cOutput { + case constants.ConsoleStdOut: stdOutput = os.Stdout - } else if cOutput == constants.ConsoleStdErr { + case constants.ConsoleStdErr: stdOutput = os.Stderr - } else { + default: log.Warn().Msgf("unknown console output '%s', falling back to '%s'", cOutput, constants.ConsoleStdOut) } + log.Debug().Msgf("adding sink '%s'", s) + c := sinks.NewConsole(stdOutput) sinksList = append(sinksList, c) - case sinks.ElasticsearchKind.String(): - if mutatorType != mutators.JSONKind.String() { - log.Panic().Msgf("mutator must be '%s' when using '%s' sink", mutators.JSONKind, sinks.ElasticsearchKind) - } - - cfg := sinks.ElasticsearchConfig{ - IndexName: viper.GetString(config.SinkElasticsearchIndexName), - Timeout: time.Second * 10, - Addresses: viper.GetStringSlice(config.SinkElasticsearchAddresses), - Username: viper.GetString(config.SinkElasticsearchUsername), - Password: viper.GetString(config.SinkElasticsearchPassword), - CloudID: viper.GetString(config.SinkElasticsearchCloudID), - APIKey: viper.GetString(config.SinkElasticsearchAPIKey), - ServiceToken: viper.GetString(config.SinkElasticsearchServiceToken), - } - - log.Debug().Msgf("adding sink '%s'", s) - es := sinks.NewElasticsearch(cfg) - sinksList = append(sinksList, es) case sinks.FilesystemKind.String(): fsFilename := viper.GetString(config.SinkFilesystemFilename) fsMaxAge := viper.GetInt(config.SinkFilesystemMaxAge) diff --git a/factories/factories_test.go b/factories/factories_test.go index a16d17b..3ce93e4 100644 --- a/factories/factories_test.go +++ b/factories/factories_test.go @@ -5,9 +5,9 @@ import ( "github.com/stretchr/testify/assert" - "tinysyslog/filters" - "tinysyslog/mutators" - "tinysyslog/sinks" + "github.com/alexferl/tinysyslog/filters" + "github.com/alexferl/tinysyslog/mutators" + "github.com/alexferl/tinysyslog/sinks" ) func TestMutator(t *testing.T) { diff --git a/filters/regex.go b/filters/regex.go index 3d7ad26..2c1fb7a 100644 --- a/filters/regex.go +++ b/filters/regex.go @@ -22,7 +22,7 @@ func (r *Regex) Filter(data string) (string, error) { if err != nil { return "", err } - if m != true { + if !m { return data, nil } return "", nil diff --git a/go.mod b/go.mod index af5860c..b5f0919 100644 --- a/go.mod +++ b/go.mod @@ -1,45 +1,36 @@ -module tinysyslog +module github.com/alexferl/tinysyslog -go 1.22 +go 1.24 require ( github.com/alexferl/golib/config v0.0.0-20240407014133-fbaf9a3e43f4 github.com/alexferl/golib/log v0.0.0-20240407014133-fbaf9a3e43f4 - github.com/elastic/go-elasticsearch/v8 v8.13.0 - github.com/rs/zerolog v1.32.0 - github.com/spf13/pflag v1.0.5 - github.com/spf13/viper v1.18.2 - github.com/stretchr/testify v1.9.0 + github.com/rs/zerolog v1.34.0 + github.com/spf13/pflag v1.0.6 + github.com/spf13/viper v1.20.1 + github.com/stretchr/testify v1.10.0 gopkg.in/mcuadros/go-syslog.v2 v2.3.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/elastic/elastic-transport-go/v8 v8.5.0 // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect - github.com/go-logr/stdr v1.2.2 // indirect - github.com/hashicorp/hcl v1.0.0 // indirect - github.com/magiconair/properties v1.8.7 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect + github.com/fsnotify/fsnotify v1.9.0 // indirect + github.com/go-viper/mapstructure/v2 v2.2.1 // indirect + github.com/google/go-cmp v0.7.0 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/pelletier/go-toml/v2 v2.2.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/sagikazarmark/locafero v0.4.0 // indirect - github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/rogpeppe/go-internal v1.13.1 // indirect + github.com/sagikazarmark/locafero v0.9.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect - github.com/spf13/afero v1.11.0 // indirect - github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/afero v1.14.0 // indirect + github.com/spf13/cast v1.7.1 // indirect github.com/subosito/gotenv v1.6.0 // indirect - go.opentelemetry.io/otel v1.25.0 // indirect - go.opentelemetry.io/otel/metric v1.25.0 // indirect - go.opentelemetry.io/otel/trace v1.25.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect - golang.org/x/sys v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect - gopkg.in/ini.v1 v1.67.0 // indirect + golang.org/x/sys v0.32.0 // indirect + golang.org/x/text v0.24.0 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 5ed5d3c..852b1d2 100644 --- a/go.sum +++ b/go.sum @@ -3,106 +3,72 @@ github.com/alexferl/golib/config v0.0.0-20240407014133-fbaf9a3e43f4/go.mod h1:Rx github.com/alexferl/golib/log v0.0.0-20240407014133-fbaf9a3e43f4 h1:bnttMKor+XLngfHOZoSXe/Tp4r98cikkXshxuV4720s= github.com/alexferl/golib/log v0.0.0-20240407014133-fbaf9a3e43f4/go.mod h1:hTb0hkHcVR4UXCrqUIPgeQpnxCnKzYeDNuzVOCwxqSU= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/elastic/elastic-transport-go/v8 v8.5.0 h1:v5membAl7lvQgBTexPRDBO/RdnlQX+FM9fUVDyXxvH0= -github.com/elastic/elastic-transport-go/v8 v8.5.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk= -github.com/elastic/go-elasticsearch/v8 v8.13.0 h1:YXPAWpvbYX0mWSNG9tnEpvs4h1stgMy5JUeKZECYYB8= -github.com/elastic/go-elasticsearch/v8 v8.13.0/go.mod h1:DIn7HopJs4oZC/w0WoJR13uMUxtHeq92eI5bqv5CRfI= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= -github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= -github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= +github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= +github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= -github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/pelletier/go-toml/v2 v2.2.0 h1:QLgLl2yMN7N+ruc31VynXs1vhMZa7CeHHejIeBAsoHo= -github.com/pelletier/go-toml/v2 v2.2.0/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= -github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= -github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= -github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= -github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= +github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY= +github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= +github.com/sagikazarmark/locafero v0.9.0 h1:GbgQGNtTrEmddYDSAH9QLRyfAHY12md+8YFTqyMTC9k= +github.com/sagikazarmark/locafero v0.9.0/go.mod h1:UBUyz37V+EdMS3hDF3QWIiVr/2dPrx49OMO0Bn0hJqk= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= -github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= -github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= -github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= -github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= -github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA= +github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo= +github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y= +github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= +github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4= +github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -go.opentelemetry.io/otel v1.25.0 h1:gldB5FfhRl7OJQbUHt/8s0a7cE8fbsPAtdpRaApKy4k= -go.opentelemetry.io/otel v1.25.0/go.mod h1:Wa2ds5NOXEMkCmUou1WA7ZBfLTHWIsp034OVD7AO+Vg= -go.opentelemetry.io/otel/metric v1.25.0 h1:LUKbS7ArpFL/I2jJHdJcqMGxkRdxpPHE0VU/D4NuEwA= -go.opentelemetry.io/otel/metric v1.25.0/go.mod h1:rkDLUSd2lC5lq2dFNrX9LGAbINP5B7WBkC78RXCpH5s= -go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= -go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= -go.opentelemetry.io/otel/trace v1.25.0 h1:tqukZGLwQYRIFtSQM2u2+yfMVTgGVeqRLPUYx1Dq6RM= -go.opentelemetry.io/otel/trace v1.25.0/go.mod h1:hCCs70XM/ljO+BeQkyFnbK28SBIJ/Emuha+ccrCRT7I= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 h1:985EYyeCOxTpcgOTJpflJUwOeEz0CQOdPt73OzpE9F8= -golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= +golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= +golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= -gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/mcuadros/go-syslog.v2 v2.3.0 h1:kcsiS+WsTKyIEPABJBJtoG0KkOS6yzvJ+/eZlhD79kk= gopkg.in/mcuadros/go-syslog.v2 v2.3.0/go.mod h1:l5LPIyOOyIdQquNg+oU6Z3524YwrcqEm0aKH+5zpt2U= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/mutators/json.go b/mutators/json.go index 1c38c0b..d08f6f2 100644 --- a/mutators/json.go +++ b/mutators/json.go @@ -4,7 +4,7 @@ import ( "encoding/json" "time" - "tinysyslog/util" + "github.com/alexferl/tinysyslog/util" ) // JSON represents a JSON mutator diff --git a/mutators/log.go b/mutators/log.go index f2bb00a..097cbe4 100644 --- a/mutators/log.go +++ b/mutators/log.go @@ -67,7 +67,7 @@ func parseStructuredData(s string) map[string]string { if len(kv) < 2 { log.Error().Msgf("failed parsing structured data item: %v", i) } else { - m[kv[0]] = strings.Replace(kv[1], "\"", "", -1) + m[kv[0]] = strings.ReplaceAll(kv[1], "\"", "") } } } diff --git a/server/server.go b/server/server.go index 47fd6e3..cab45bd 100644 --- a/server/server.go +++ b/server/server.go @@ -7,10 +7,10 @@ import ( "github.com/spf13/viper" "gopkg.in/mcuadros/go-syslog.v2" - "tinysyslog/config" - "tinysyslog/factories" - "tinysyslog/mutators" - "tinysyslog/sinks" + "github.com/alexferl/tinysyslog/config" + "github.com/alexferl/tinysyslog/factories" + "github.com/alexferl/tinysyslog/mutators" + "github.com/alexferl/tinysyslog/sinks" ) // Server holds the config diff --git a/server/server_test.go b/server/server_test.go index d4e2794..5d9812e 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - _ "tinysyslog/testing" + _ "github.com/alexferl/tinysyslog/testing" ) func TestNew(t *testing.T) { diff --git a/sinks/console.go b/sinks/console.go index 41dfbf0..7c5c904 100644 --- a/sinks/console.go +++ b/sinks/console.go @@ -22,11 +22,15 @@ func NewConsole(output *os.File) Sink { // Write writes to the specified output func (c *Console) Write(stdOutput []byte) error { w := bufio.NewWriter(c.output) - defer w.Flush() _, err := w.Write(stdOutput) if err != nil { return err } + + if err := w.Flush(); err != nil { + return err + } + return nil } diff --git a/sinks/elasticsearch.go b/sinks/elasticsearch.go deleted file mode 100644 index 46b3f5a..0000000 --- a/sinks/elasticsearch.go +++ /dev/null @@ -1,94 +0,0 @@ -package sinks - -import ( - "bytes" - "context" - "fmt" - "time" - - "github.com/elastic/go-elasticsearch/v8" - "github.com/rs/zerolog/log" -) - -type Elasticsearch struct { - client *elasticsearch.TypedClient - config ElasticsearchConfig - kind Kind -} - -type ElasticsearchConfig struct { - IndexName string - Timeout time.Duration - Addresses []string - Username string - Password string - CloudID string - APIKey string - ServiceToken string -} - -func NewElasticsearch(conf ElasticsearchConfig) Sink { - client, err := elasticsearch.NewTypedClient(elasticsearch.Config{ - Addresses: conf.Addresses, - Username: conf.Username, - Password: conf.Password, - CloudID: conf.CloudID, - APIKey: conf.APIKey, - ServiceToken: conf.ServiceToken, - }) - if err != nil { - log.Panic().Err(err).Msgf("failed creating elasticsearch client") - } - - es := &Elasticsearch{ - client: client, - config: conf, - kind: ElasticsearchKind, - } - idx := es.config.IndexName - - ctx := context.Background() - cctx, cancel := context.WithTimeout(ctx, es.config.Timeout) - defer cancel() - - exists, err := client.Indices.ExistsIndexTemplate(idx).Do(cctx) - if err != nil { - log.Panic().Err(err).Msgf("failed checking if index template exists") - } - - if !exists { - pattern := fmt.Sprintf("%s-*", idx) - resp, err := client.Indices.PutTemplate(idx).IndexPatterns(pattern).Do(cctx) - if err != nil { - log.Panic().Err(err).Msgf("failed creating index template '%s'", idx) - } - if !resp.Acknowledged { - log.Panic().Err(err).Msgf("failed acknowledging index template '%s'", idx) - } - } - - return Sink(es) -} - -func (es *Elasticsearch) Write(output []byte) error { - ctx, cancel := context.WithTimeout(context.Background(), es.config.Timeout) - defer cancel() - - resp, err := es.client.Index(es.getCurrentDayIndex()).Raw(bytes.NewReader(output)).Do(ctx) - if err != nil { - return err - } - - log.Debug().Msgf("elasticsearch indexed log '%s' to index '%s'", resp.Id_, resp.Index_) - - return nil -} - -func (es *Elasticsearch) GetKind() Kind { - return es.kind -} - -func (es *Elasticsearch) getCurrentDayIndex() string { - t := time.Now() - return fmt.Sprintf("%s-%s", es.config.IndexName, t.Format("2006-01-02")) -} diff --git a/sinks/interface.go b/sinks/interface.go index dfbd23e..ec77d21 100644 --- a/sinks/interface.go +++ b/sinks/interface.go @@ -4,15 +4,14 @@ type Kind int8 const ( ConsoleKind Kind = iota + 1 - ElasticsearchKind FilesystemKind ) func (k Kind) String() string { - return [...]string{"console", "elasticsearch", "filesystem"}[k-1] + return [...]string{"console", "filesystem"}[k-1] } -var Kinds = []string{ConsoleKind.String(), ElasticsearchKind.String(), FilesystemKind.String()} +var Kinds = []string{ConsoleKind.String(), FilesystemKind.String()} // Sink a common interface for all sinks type Sink interface { diff --git a/testing/testing.go b/testing/testing.go index d2532cd..bb91c7b 100644 --- a/testing/testing.go +++ b/testing/testing.go @@ -1,7 +1,7 @@ package testing import ( - "tinysyslog/config" + "github.com/alexferl/tinysyslog/config" ) func init() {