logger

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 4 Imported by: 0

README

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Go Logger Interface

A simple and colourful logger interface wrapper on-top of the standard library Log for printing formatted lines to the console.
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

This project was made to address the need for myself in having a colourful, standardised output similar to LoggerInterface solutions available in other languages.

In short, this module is a wrapper on top of the standard library Log to output formatted logs to the terminal for a given service in the following format:

Example output

(back to top)

Built With

  • Go

(back to top)

Getting Started

Prerequisites

It is assumed that you already have Go installed on your machine.

  • go
    https://go.dev/doc/install # Follow the instructions to install Go
    

Installation

  1. Import the module to your project.
    go get github.com/jamestkelly/go-logger-interface
    

(back to top)

Usage

To utilise the package after installing the module, simply create a logger interface at the top of your given file and use it like so:

// example.go
import (
    github.com/jamestkelly/go-logger-interface
)

var (
    exampleLogger = logger.LoggerInterface{Prefix: "ExampleLoggerInterface"}
)

// main
// Example main function to log a bunch of statements using LoggerInterface
func main() {
	exampleLogger.LogMessage(
		"This is a 'DEBUG' message.",
		"DEBUG",
	)

	exampleLogger.LogMessage(
		"This is an 'INFO' message.",
		"INFO",
	)

	exampleLogger.LogMessage(
		fmt.Sprintf("This is a %s 'INFO' message.", "formatted"),
		"INFO",
	)

	exampleLogger.LogMessage(
		"This is a 'WARN' message.",
		"WARN",
	)

	exampleLogger.LogMessage(
		"This is an 'ERROR' message.",
		"ERROR",
	)

	exampleLogger.LogMessage(
		"This is a 'FATAL' message.",
		"FATAL",
	)
}

For more examples, please refer to the Examples

(back to top)

Roadmap

  • Create the package and make it available publically.

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Jim Kelly - jimkelly.t@outlook.com

Project Link: https://github.com/jamestkelly/go-logger-interface

(back to top)

Acknowledgments

(back to top)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoggerInterface

type LoggerInterface struct {
	Prefix string
}

LoggerInterface A structure containing the Prefix or name of the service that logs are written for.

func (*LoggerInterface) LogMessage

func (l *LoggerInterface) LogMessage(message, severity string)

LogMessage Structure method to print a log message provided both a message and severity.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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