go_vector_logger

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 8 Imported by: 0

README

Go-Vector-Logger

An easy way to use Vector for logs in Go.

Usage

package main

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

var log VectorLogger

func main() {
  log := go_vector_logger.New("test-app", "INFO", "127.0.0.1", 10100)

  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)
}

Also, you can pass in aditional 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
}

[...]
log := go_vector_logger.New(
  "test-app",
  "INFO",
  "127.0.0.1",
  10100,
  Options{
    AlsoPrintMessages: true,
  },
)

Documentation

Overview

Package go_vector_logger provides a logger that can write logs to stdout and send them to a remote Vector instance.

Index

Constants

View Source
const (
	DEBUG string = "DEBUG"
	INFO         = "INFO"
	WARN         = "WARN"
	ERROR        = "ERROR"
	FATAL        = "FATAL"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Timestamp   string `json:"timestamp"`   // Log timestamp.
	Application string `json:"application"` // Application name.
	Level       string `json:"level"`       // Log level.
	Message     string `json:"message"`     // Log message.
}

Message represents a log message.

type Options added in v0.5.0

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, also log any messages to stdout
}

Options list different options you can optionally pass into New

type VectorLogger

type VectorLogger struct {
	Application string // Application name.
	Level       string // Log level.
	VectorHost  string // Vector host.
	VectorPort  int64  // Vector port.
	Options     Options
}

VectorLogger represents a logger instance.

func New added in v0.5.0

func New(application string, level string, vectorHost string, vectorPort int64, options ...Options) (*VectorLogger, error)

func (*VectorLogger) Debug

func (l *VectorLogger) Debug(message string)

Debug logs a debug message.

func (*VectorLogger) Debugf added in v0.3.0

func (l *VectorLogger) Debugf(format string, v ...interface{})

Debugf logs a debug message with a formatted string.

func (*VectorLogger) Error

func (l *VectorLogger) Error(message string)

Error logs an error message.

func (*VectorLogger) Errorf added in v0.3.0

func (l *VectorLogger) Errorf(format string, v ...interface{})

Errorf logs an error message with a formatted string.

func (*VectorLogger) Fatal added in v0.6.0

func (l *VectorLogger) Fatal(message string)

Fatal logs an error message.

func (*VectorLogger) FatalError added in v0.6.0

func (l *VectorLogger) FatalError(message error)

Fatal logs an error message.

func (*VectorLogger) Fatalf added in v0.6.0

func (l *VectorLogger) Fatalf(format string, v ...interface{})

Errorf logs an error message with a formatted string.

func (*VectorLogger) Info

func (l *VectorLogger) Info(message string)

Info logs an info message.

func (*VectorLogger) Infof added in v0.3.0

func (l *VectorLogger) Infof(format string, v ...interface{})

Infof logs an info message with a formatted string.

func (*VectorLogger) Init

func (l *VectorLogger) Init(application string, level string, vectorHost string, vectorPort int64)

Init initializes the logger instance. This method is deprecated; use New() with a Options struct for more flexibility.

func (*VectorLogger) Warn added in v0.4.0

func (l *VectorLogger) Warn(message string)

Warn logs an warning message.

func (*VectorLogger) Warnf added in v0.4.0

func (l *VectorLogger) Warnf(format string, v ...interface{})

Warnf logs an warning message with a formatted string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL