logger

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: MIT Imports: 7 Imported by: 0

README

logger

Go Reference Go Report Card Issues License Release

A minimalisitic logger module for basic logging, written in Go.

Table of Contents

Example

Client
package main

import (
    "github.com/pravinba9495/logger"
)

func main() {
    // Initialize logger
    opts := &logger.LoggerOptions{
	LogLevel:    logger.LevelTrace,
	LogFilePath: "logfile.txt",
    }
    close, err := logger.Init(opts)
    if err != nil {
        panic(err)
    }
    defer close()

    logger.Trace("This is just a trace");            // Prints on stdout with a cyan colored text
    logger.Print("This is just a simple log");       // Prints on stdout with a white colored text
    logger.Warn("This is just a warning log");       // Prints on stdout with a yellow colored text
    logger.Success("This is just a success log");    // Prints on stdout with a green colored text
    logger.Error("This is just an error log");       // Prints on stdout with a red colored text
}

Documentation

Logger documentation is hosted at Read the docs.

Development

Logger is still under development. Contributions are always welcome!

Maintainers

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(s string)

Error prints logs of type "ERROR"

func GetFileSize added in v0.0.4

func GetFileSize() (int64, error)

GetFileSize returns the log file size

func GetLogLevel

func GetLogLevel() int

GetLogLevel returns the current log level

func Init

func Init(opts *LoggerOptions) (func(), error)

Init initializes a logger

func Print

func Print(s string)

Print prints logs of type "LOG"

func Success

func Success(s string)

Success prints logs of type "SUCCESS"

func Trace

func Trace(s string)

Trace prints logs of type "TRACE"

func Warn

func Warn(s string)

Warn prints logs of type "WARN"

Types

type LogLevel

type LogLevel string

LogLevel defines the log level of the logger instance

const (
	LevelTrace LogLevel = "TRACE"
	LevelLog   LogLevel = "LOG"
	LevelWarn  LogLevel = "WARN"
	LevelError LogLevel = "ERROR"
)

Log levels

type LoggerOptions

type LoggerOptions struct {
	LogLevel       LogLevel
	LogFilePath    string
	LogFileMaxSize int64
}

LoggerOptions to pass to the logger instance

Jump to

Keyboard shortcuts

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