Skip to content

tarantool/go-tlog

Repository files navigation

Actions Status Telegram EN Telegram RU

Table of contents

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

go get github.com/tarantool/go-tlog@latest

Then import:

import "github.com/tarantool/go-tlog"

Quick start

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

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:

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

make test

License

BSD 2-Clause License — see LICENSE

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published