mylogger

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 7 Imported by: 0

README

mylogger

mylogger is a simple logging utility for Go projects. Using go's slog but with separated outputs for stdout and stderr.

Installation

You can install mylogger using go get:

go get github.com/juparave/mylogger

Usage

package main

import (
	"github.com/juparave/mylogger"
)

func main() {
	// Create a new logger
	logger := mylogger.NewLogger()

	// Log some messages
	logger.Info("This is an informational message")
	logger.Warn("This is a warning message")
	logger.Error("This is an error message")
	logger.Debug("This is a debug message")
}

You can also create a logger with custom output buffers for testing purposes using NewLoggerBuffers:

package main

import (
	"bytes"
	"github.com/juparave/mylogger"
)

func main() {
	// Create buffers for capturing log output
	var stdOut, errOut bytes.Buffer

	// Create a logger with custom output buffers
	logger := mylogger.NewLoggerBuffers(&stdOut, &errOut)

	// Log some messages
	logger.Info("This is an informational message")
	logger.Warn("This is a warning message")
	logger.Error("This is an error message")
	logger.Debug("This is a debug message")

	// Check the output captured in buffers
	println("Standard output:", stdOut.String())
	println("Error output:", errOut.String())
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Overview

Package mylog provides a simple logging utility for Go projects.

Example
package main

import (
	"github.com/juparave/mylogger"
)

func main() {
	// Create a new logger
	logger := mylogger.NewLogger()

	// Log some messages
	logger.Info("This is an informational message")
	logger.Warn("This is a warning message")
	logger.Error("This is an error message")

}
Output:

This is an informational message
This is a warning message
This is an error message

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MyLogger

type MyLogger struct {
	// contains filtered or unexported fields
}

MyLogger represents a customized logger with separate streams for standard output and errors.

func NewLogger

func NewLogger() *MyLogger

NewLogger creates a new instance of MyLogger.

func NewLoggerBuffers

func NewLoggerBuffers(stdOut, errOut *bytes.Buffer) *MyLogger

NewLoggerBuffers creates a new instance of MyLogger with the specified output buffers. This function is useful for testing purposes.

func (*MyLogger) Debug

func (l *MyLogger) Debug(msg string, keyvals ...interface{})

Debug logs a debug message.

func (*MyLogger) Error

func (l *MyLogger) Error(msg string, keyvals ...interface{})

Error logs an error message.

func (*MyLogger) Info

func (l *MyLogger) Info(msg string, keyvals ...interface{})

Info logs an informational message.

func (*MyLogger) Warn

func (l *MyLogger) Warn(msg string, keyvals ...interface{})

Warn logs a warning message.

Jump to

Keyboard shortcuts

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