-
Notifications
You must be signed in to change notification settings - Fork 0
feat: initial implementation of go-tlog with examples, CI and README #1
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
Open
vakhov
wants to merge
8
commits into
master
Choose a base branch
from
vakhov/initial-version
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6e31ef2
feat: initial implementation of go-tlog with examples, CI and README
vakhov e72fbb6
ci, docs: rename CI workflow and update badges in README
vakhov 21269a5
docs, tests: replace runnable examples with testable example and upda…
vakhov d39ae0e
docs: initial CHANGELOG
vakhov 502d39f
Update CHANGELOG.md
vakhov 2ea515d
Update .github/workflows/testing.yml
vakhov 5341e34
Update Makefile
vakhov c67ec38
review fixes: GoDoc comments + CI updates
vakhov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| name: testing | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ master ] | ||
| pull_request: | ||
| branches: [ '**' ] | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Go tests | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.24.x' | ||
| check-latest: true | ||
|
|
||
| - name: Download deps | ||
| run: go mod download | ||
|
|
||
| - name: Run tests | ||
| run: make test | ||
vakhov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # IDE | ||
| .idea | ||
|
|
||
| coverage.out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| run: | ||
| timeout: 5m | ||
| modules-download-mode: readonly | ||
|
|
||
| issues: | ||
| exclude-use-default: false | ||
| max-same-issues: 0 | ||
| max-issues-per-linter: 0 | ||
|
|
||
| linters: | ||
| enable: | ||
| - govet | ||
| - staticcheck | ||
| - revive | ||
| - errcheck | ||
| - gosimple | ||
| - ineffassign | ||
| - unused | ||
| - typecheck | ||
| - gofmt | ||
| - goimports | ||
| - misspell | ||
| - gocritic | ||
|
|
||
| linters-settings: | ||
| revive: | ||
| severity: warning | ||
| rules: | ||
| - name: unused-parameter | ||
| - name: unreachable-code | ||
| - name: indent-error-flow | ||
| - name: exported | ||
| - name: blank-imports | ||
| - name: var-declaration | ||
| - name: if-return | ||
|
|
||
| misspell: | ||
| locale: US | ||
|
|
||
| goimports: | ||
| local-prefixes: github.com/tarantool/go-tlog | ||
|
|
||
| # Skip linters on example files and any generated code | ||
| exclude-rules: | ||
| - path: ^_examples/ | ||
| linters: [revive, staticcheck, govet, gocritic] | ||
| - path: \.pb\.go$|_gen\.go$ | ||
| linters: [all] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes to this project will be documented in this file. | ||
|
|
||
| The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
| and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
|
||
| ## [Unreleased] | ||
|
|
||
| ### Added | ||
| - Core structured logging library for Go | ||
| - Support for log levels: Trace, Debug, Info, Warn, Error | ||
| - Text and JSON output formats | ||
| - Multiple output destinations: stdout, stderr, file paths, multi-target | ||
| - Automatic timestamp, source file and line number | ||
| - Stacktrace collection for error-level messages | ||
| - Test suite for core functionality | ||
| - Idiomatic Go examples (testable examples) | ||
| - Makefile, GitHub Actions CI workflow, README, LICENSE, lint configuration | ||
vakhov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Changed | ||
|
|
||
| ### Fixed | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| BSD 2-Clause License | ||
|
|
||
| Copyright (c) 2025, Tarantool AUTHORS | ||
| All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are met: | ||
|
|
||
| * Redistributions of source code must retain the above copyright notice, this | ||
| list of conditions and the following disclaimer. | ||
|
|
||
| * Redistributions in binary form must reproduce the above copyright notice, | ||
| this list of conditions and the following disclaimer in the documentation | ||
| and/or other materials provided with the distribution. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||||||||||
| # Default Go toolchain | ||||||||||||||
| GO ?= go | ||||||||||||||
| GOLANGCI_LINT ?= golangci-lint | ||||||||||||||
| PKG := github.com/tarantool/go-tlog | ||||||||||||||
|
|
||||||||||||||
| .PHONY: all test test-race test-coverage lint fmt tidy examples help | ||||||||||||||
|
|
||||||||||||||
| all: test | ||||||||||||||
|
|
||||||||||||||
| ## Run tests | ||||||||||||||
| test: | ||||||||||||||
| $(GO) test ./... | ||||||||||||||
|
|
||||||||||||||
| ## Run tests with race detector | ||||||||||||||
| test-race: | ||||||||||||||
| $(GO) test -race ./... | ||||||||||||||
|
|
||||||||||||||
| ## Run tests with coverage | ||||||||||||||
| test-coverage: | ||||||||||||||
| $(GO) test -covermode=atomic -coverprofile=coverage.out ./... | ||||||||||||||
|
|
||||||||||||||
| ## Run golangci-lint | ||||||||||||||
| lint: | ||||||||||||||
| $(GOLANGCI_LINT) run ./... | ||||||||||||||
|
|
||||||||||||||
| ## Format source code | ||||||||||||||
| fmt: | ||||||||||||||
| $(GO) fmt ./... | ||||||||||||||
|
|
||||||||||||||
| ## Tidy go.mod / go.sum | ||||||||||||||
| tidy: | ||||||||||||||
| $(GO) mod tidy | ||||||||||||||
|
|
||||||||||||||
| ## Run all _examples to ensure they compile and run without panic | ||||||||||||||
| examples: | ||||||||||||||
| $(GO) run ./_examples/stdout | ||||||||||||||
| $(GO) run ./_examples/stderr >/dev/null 2>&1 || true | ||||||||||||||
| $(GO) run ./_examples/file | ||||||||||||||
| $(GO) run ./_examples/multi | ||||||||||||||
|
||||||||||||||
| ## Run all _examples to ensure they compile and run without panic | |
| examples: | |
| $(GO) run ./_examples/stdout | |
| $(GO) run ./_examples/stderr >/dev/null 2>&1 || true | |
| $(GO) run ./_examples/file | |
| $(GO) run ./_examples/multi |
vakhov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
vakhov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,179 @@ | ||
| <a href="http://tarantool.org"> | ||
| <img src="https://avatars2.githubusercontent.com/u/2344919?v=2&s=250" align="right"> | ||
| </a> | ||
|
|
||
| [![Actions Status][actions-badge]][actions-url] | ||
| [![Telegram EN][telegram-badge]][telegram-en-url] | ||
| [![Telegram RU][telegram-badge]][telegram-ru-url] | ||
|
|
||
| ## Table of contents | ||
|
|
||
| - [go-tlog](#go-tlog) | ||
| - [Features](#features) | ||
| - [Installation](#installation) | ||
| - [Quick start](#quick-start) | ||
| - [Configuration](#configuration) | ||
| - [type Opts](#type-opts) | ||
| - [Main API](#main-api) | ||
| - [Log levels](#log-levels) | ||
| - [Output formats](#output-formats) | ||
| - [Output destinations](#output-destinations) | ||
| - [Examples](#examples) | ||
| - [Testing](#testing) | ||
| - [License](#license) | ||
|
|
||
| # go-tlog | ||
|
|
||
| `go-tlog` is a lightweight and configurable logging library for Go applications. | ||
| It provides structured logging with multiple output destinations, flexible formatting, | ||
| and fine-grained log-level control. | ||
|
|
||
| --- | ||
|
|
||
| ## Features | ||
|
|
||
| - Simple setup via configuration struct | ||
| - Text or JSON output formats | ||
| - Multiple output targets: **stdout**, **stderr**, **files** | ||
| - Log levels: `Trace`, `Debug`, `Info`, `Warn`, `Error` | ||
| - Automatic timestamp, source file, and line number | ||
| - Stacktrace for errors | ||
|
|
||
| --- | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| go get github.com/tarantool/go-tlog@latest | ||
| ``` | ||
|
|
||
| Then import: | ||
|
|
||
| ```go | ||
| import "github.com/tarantool/go-tlog" | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Quick start | ||
|
|
||
| ```go | ||
| package main | ||
|
|
||
| import "github.com/tarantool/go-tlog" | ||
|
|
||
| func main() { | ||
| log, err := tlog.New(tlog.Opts{ | ||
| Level: tlog.LevelInfo, | ||
| Format: tlog.FormatText, | ||
| Path: "stdout", | ||
| }) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer log.Close() | ||
|
|
||
| logger := log.Logger().With(tlog.String("component", "demo")) | ||
| logger.Info("service started", "port", 8080) | ||
| logger.Error("failed to connect", "err", "timeout") | ||
| } | ||
| ``` | ||
|
|
||
| Output: | ||
|
|
||
| ``` | ||
| 2025-11-10T13:30:01+05:00 INFO service started component=demo port=8080 | ||
| 2025-11-10T13:30:01+05:00 ERROR failed to connect err=timeout component=demo stacktrace="..." | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### `type Opts` | ||
|
|
||
| ```go | ||
| type Opts struct { | ||
| Level Level // minimal log level | ||
| Format Format // FormatText or FormatJSON | ||
| Path string // comma-separated outputs: "stdout,/var/log/app.log" | ||
| } | ||
| ``` | ||
|
|
||
| ### Main API | ||
|
|
||
| | Function | Description | | ||
| |------------------|------------------------------------------| | ||
| | `tlog.New(opts)` | Create a new logger | | ||
| | `Logger()` | Return the underlying logger for use | | ||
| | `Close()` | Flush buffers and close file descriptors | | ||
|
|
||
| --- | ||
|
|
||
| ## Log levels | ||
|
|
||
| | Level | When to use | | ||
| |---------|---------------------------------------------| | ||
| | `Trace` | Low-level tracing | | ||
| | `Debug` | Debugging information | | ||
| | `Info` | Normal operational messages | | ||
| | `Warn` | Non-fatal warnings | | ||
| | `Error` | Errors and exceptions (includes stacktrace) | | ||
|
|
||
| --- | ||
|
|
||
| ## Output formats | ||
|
|
||
| | Format | Example | | ||
| |--------------|---------------------------------------------------------------| | ||
| | `FormatText` | `2025-11-10T13:31:45+05:00 INFO message key=value` | | ||
| | `FormatJSON` | `{"time":"...","level":"INFO","msg":"message","key":"value"}` | | ||
|
|
||
| --- | ||
|
|
||
| ## Output destinations | ||
|
|
||
| You can specify multiple targets separated by commas: | ||
|
|
||
| ```go | ||
| Path: "stdout,/tmp/app.log" | ||
| ``` | ||
|
|
||
| Supported targets: | ||
|
|
||
| - `stdout` | ||
| - `stderr` | ||
| - File paths (created automatically if not present) | ||
|
|
||
| --- | ||
|
|
||
| ## Examples | ||
|
|
||
| Included examples: | ||
|
|
||
| - **ExampleNew_text** — basic text logger writing to stdout | ||
| - **ExampleNew_json** — JSON logging | ||
| - **ExampleNew_multi** — logging to multiple destinations (`stdout,/tmp/...`) | ||
|
|
||
| Each example demonstrates different combinations of Path, Format, and Level, | ||
| including how to log to multiple outputs at the same time. | ||
|
|
||
| --- | ||
|
|
||
| ## Testing | ||
|
|
||
| ```bash | ||
| make test | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## License | ||
|
|
||
| BSD 2-Clause License — see [LICENSE](LICENSE) | ||
|
|
||
| [actions-badge]: https://github.com/tarantool/go-tlog/actions/workflows/testing.yml/badge.svg | ||
| [actions-url]: https://github.com/tarantool/go-tlog/actions/workflows/testing.yml | ||
| [telegram-badge]: https://img.shields.io/badge/Telegram-join%20chat-blue.svg | ||
| [telegram-en-url]: http://telegram.me/tarantool | ||
| [telegram-ru-url]: http://telegram.me/tarantoolru |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a linter job too. See go-discovery/go-storage/go-tarantool etc.