Giter Site home page Giter Site logo

iamando / logaro Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 61 KB

Logaro is a lightweight Go package for JSON-based logging. It provides a simple and flexible logging solution with support for log levels, log entry customization, and hierarchical loggers.

Home Page: https://pkg.go.dev/github.com/iamando/logaro

License: MIT License

Go 100.00%
go json json-logger lightweight logger process versatile

logaro's Introduction

Logaro

build license Go version GoDoc

Logaro is a lightweight Go package for JSON-based logging. It provides a simple and flexible logging solution with support for log levels, log entry customization, and hierarchical loggers.

Features

  • JSON-based logging format for easy log consumption and analysis.
  • Configurable log levels to control the verbosity of the log output.
  • Ability to customize log entries with additional fields.
  • Hierarchical loggers to organize and inherit log settings.
  • Support for serializers to transform log message and field values.

Installation

To use Logaro in your Go project, you need to have Go installed and set up. Then, run the following command to install the package:

go get github.com/iamando/logaro

Usage

Here's a basic example of how to use Logaro:

package main

import "github.com/iamando/logaro"


func main() {
 // Create a logger
 logger := logaro.GenerateLogger()

 // Log a message
 logger.Log("info", "Hello, Logaro!", nil)

 // Log a message with additional fields
 logger.Log("error", "An error occurred", map[string]interface{}{
  "error_code": 500,
  "error_msg":  "Internal Server Error",
 })

 // Create a child logger with additional fields
 childLogger := logger.WithFields(map[string]interface{}{
  "component": "subsystemA",
 })

 // Log from the child logger
 childLogger.Log("debug", "Debug message from subsystemA", nil)
}

For more detailed examples and advanced usage, please refer to the examples directory.

Output

Using Logaro, the log entries can be output in a JSON format. Here's an example of how the log entries would appear when logged to the standard output:

{"timestamp":"2023-05-10T10:30:45Z","message":"This is an informational message","level":"info","fields":null}
{"timestamp":"2023-05-10T10:30:45Z","message":"This is a warning message","level":"warn","fields":null}
{"timestamp":"2023-05-10T10:30:45Z","message":"This is an error message","level":"error","fields":null}
{"timestamp":"2023-05-10T10:30:45Z","message":"Debugging information","level":"debug","fields":{"user_id":123,"request_id":"abc123"}}
{"timestamp":"2023-05-10T10:30:45Z","message":"Child logger message","level":"info","fields":{"component":"subsystemA"}}
{"timestamp":"2023-05-10T10:30:45Z","message":"Custom serialization example","level":"info","fields":{"field":"Value"}}

The log entries are represented as JSON objects, where each object contains the timestamp, message, level, and fields properties. The fields property contains additional key-value pairs associated with the log entry.

Please note that the actual log output may vary based on the specific log messages, log levels, and fields provided in your application.

Feel free to customize and expand upon this output example section based on your specific package functionality and desired log format.

API

type Logger

Represents a logger instance that can be used to log messages at different levels.

Methods

  • Log(level string, message string, fields map[string]interface{}) Logs a message at the specified log level. Additional fields can be provided as a map of key-value pairs.

  • Child(fields map[string]interface{}) *Logger Creates a child logger with the specified additional fields. The child logger inherits the log settings and fields from its parent. ssss

  • WithFields(fields map[string]interface{}) *Logger Creates a child logger with the specified additional fields. The child logger inherits the log settings and fields from its parent.

  • WithSerializers(serializers map[string]func(interface{}) interface{}) *Logger Creates a child logger with custom serializers for transforming log message and field values. The serializers argument should be a map where the keys represent the fields to be serialized and the values are functions that perform the serialization.

type LogEntry

Represents a log entry containing the log message, log level, and additional fields.

Fields

  • Timestamp string The timestamp of the log entry in RFC3339 format.

  • Message string The log message.

  • Level string The log level.

  • Fields map[string]interface{} Additional fields associated with the log entry.

func NewLogger() *Logger

Creates a new instance of the Logger with default settings.

This API section provides an overview of the available types, methods, and functions in the Logaro package. Please refer to the code documentation and examples for more details on how to use the API effectively.

Feel free to customize and expand upon this API section based on your specific package functionality and features.

Documentation

For detailed documentation and API reference, please refer to the GoDoc page.

Support

Logaro is an MIT-licensed open source project. It can grow thanks to the sponsors and support.

License

Logaro is MIT licensed.

logaro's People

Contributors

iamando avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.