Giter Site home page Giter Site logo

gologlite's Introduction

A lightweight logging interface for Go

Feature highlights

  • Minimal, non-opinionated interface
  • Bring Your Own Backend

Usage

Add the module as a dependency to your project

go get github.com/siliconbrain/gologlite

As gologlite contains only a minimal API for logging, it's recommended to create your own custom log package in your project and:

  • use alises to re-publish necessary types and functions of gologlite and any other modules/packages extending functionality herein
  • implement your own helpers and utilities to best adapt to the needs of your project

The rest of your project should import this custom log package.

Example

package log

import (
    "fmt"
    "io"
    "time"

    "github.com/siliconbrain/gologlite/log"
)

type Fields = log.FieldMap
var Event = log.Event

// V is for verbosity
type V int

func (v V) ForEachField(fn func(name string, value interface{}) (stop bool)) {
    fn("verbosity", int(v))
}

func (v V) LookupFieldByName(name string) (value interface{}, found bool) {
    if name == "verbosity" {
        return int(v), true
    }
    return nil, false
}

type WriterTarget struct {
    Out io.Writer
}

func (t WriterTarget) Record(message string, fields log.FieldSet) {
    fmt.Fprintf(t.Out, "%s %s %#v", time.Now().Format(time.RFC3339), message, log.CollapseFieldSets(fields))
}
package myproject

import (
    "os"

    "local.dev/myproject/log"
)

func main() {
    logger := log.WriterTarget{Out: os.Stdout}
    // ...
    log.Event(logger, "computation finished", log.V(1), log.Fields{"answer": 42})
}

gologlite's People

Contributors

siliconbrain avatar

Watchers

 avatar James Cloos 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.