Skip to content

update repo and deps #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*.log
.dockerignore
.git
.gitignore
.idea
LICENSE
README*
README.md
Makefile
tinysyslog-bin
33 changes: 33 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 28 additions & 13 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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
40 changes: 19 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: "2"
formatters:
enable:
- gofumpt
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
FROM golang:1.22.2-alpine3.19 as builder
MAINTAINER Alexandre Ferland <me@alexferl.com>
FROM golang:1.24.2-alpine as builder
LABEL maintainer="Alexandre Ferland <me@alexferl.com>"

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 . .

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"]
73 changes: 43 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -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
47 changes: 20 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
```
Loading
Loading