Thanks to visit codestin.com
Credit goes to github.com

Skip to content

scor2k/go-vector-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go-Vector-Logger

An easy way to use Vector for logs in Go.

See Changelog.md for release history.

Usage

package main

import (
  "github.com/scor2k/go-vector-logger"
)

func main() {
  log, err := go_vector_logger.New("test-app", "INFO", "127.0.0.1", 10100)
  if err != nil {
    panic(err)
  }

  log.Debug("test debug message")
  log.Info("test info message")
  log.Warn("test warning message")
  log.Error("test error message")
  log.Errorf("test error message with %s", "formatting")
  log.Fatal("test error message")
  log.Fatalf("test error message with %s", "formatting")
  log.FatalError(err)
}

Options

You can pass additional options to New():

type Options struct {
  Writer            io.Writer     // Instead of over the network, write the log messages just to this writer
  AlsoPrintMessages bool          // In addition to the specific network/writer, also log any messages to stdout
  TCPTimeout        time.Duration // Timeout for TCP connection and write. If zero, defaults to 1 second.
}

Example with options:

log, err := go_vector_logger.New(
  "test-app",
  "INFO",
  "127.0.0.1",
  10100,
  go_vector_logger.Options{
    AlsoPrintMessages: true,
  },
)
if err != nil {
  panic(err)
}

Local testing

If you want to test or use this package locally before merging, follow these steps:

  1. Clone the repository (if you haven't already):

    git clone https://github.com/scor2k/go-vector-logger.git
    cd go-vector-logger
  2. Start Vector with TCP logger

./run-vector.sh
  1. Run your example or tests from the repo root For example:
    go run ./example/basic_usage.go

Check that the logs are being sent to Vector and displayed in the console.

About

Simple way to send logs to Loki

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •