GithubHelp home page GithubHelp logo

jlog's Introduction

jlog

Installation

go get github.com/pandamy619/jlog

Usage

func Init

func Init(pkg string, location string, consoleLog string) *Jlogs

Create new Logger.

  • pkg: Name package.
  • location: Folder where logs will be saved.
  • consoleLog: Method output to console, simple or json.

example

package main

import (
	"jlog"
)

func main() {
    jlog.Init("SomePackage", "tmp", "simple")
}

func (*Jlogs) Main

func (l *Jlogs) Main(name string) *Jlogs

Usually called at the beginning of a function.

  • name: Function name.

example

package main

import (
	"jlog"
)

func main() {
    j := jlog.Init("SomePackage", "tmp", "simple")
    j.Main("main")
}

func (*Jlogs) Sub

func (l *Jlogs) Sub(status string, message string, time string) *Jlogs
  • status: Status log (info/warning/error/customStatus).
  • message: Message containing information about the log.
  • time: Date and time.
package main

import (
	"jlog"
)

func main() {
    j := jlog.Init("SomePackage", "tmp", "simple")
    jMain := j.Main("main")
    jMain.Sub(
        "info",
        "message fun1",
        time.Now().Format("2006-01-02T15:04:05"),
    ).Info("Info message")
}

func (*Jlogs) SubWithFields

func (l *Jlogs) SubWithFields(status string, message string, time string, field Fields) *Jlogs
  • status: Status log (info/warning/error/customStatus).
  • message: Message containing information about the log.
  • time: Date and time.
  • fields: Fields.

example

package main

import (
	"jlog"
)

func main() {
    j := jlog.Init("SomePackage", "tmp", "simple")
    jMain := j.Main("main")
    lMain.SubWithFields(
        "warning",
        "message subfun1",
        time.Now().Format("2006-01-02T15:04:05"),
        jlog.Fields{
            "fun": "subfun1",
    }).Warning("Warning message")
}

Status

Info/Warning/Error

func (l *Jlogs) Info(message string)
func (l *Jlogs) Warning(message string)
func (l *Jlogs) Error(message string)

Console log

simple log

[INFO] package:some_package func:fun1 detail:Info message
[WARN] package:some_package func:fun1 detail:warning message
[ERROR] package:some_package func:fun1 detail:error message

json log

-------------------------
[INFO] Info message
package:some_package
func:fun1
{
    "message": "message fun1",
    "status": "info",
    "time": "2020-06-17T11:21:59"
}
-------------------------
-------------------------
[WARN] warning message
package:some_package
func:fun1
{
    "message": "message fun1",
    "status": "warning",
    "time": "2020-06-17T11:21:59"
}
-------------------------
-------------------------
[ERROR] error message
package:some_package
func:fun1
{
    "message": "message fun1",
    "status": "error",
    "time": "2020-06-17T11:21:59"
}
-------------------------

File output

format file YYYY-MM-DDTHH:MM:SS.json

{
    "package": "Logging",
    "functions": {
        "fun1": [
            {
                "message": "message fun1",
                "status": "info",
                "time": "2020-06-18T09:06:03"
            },
            {
                "message": "message fun1",
                "status": "warning",
                "time": "2020-06-18T09:06:03"
            },
            {
                "message": "message subfun1",
                "meta": {
                    "fun": "subfun1"
                },
                "status": "warning",
                "time": "2020-06-18T09:06:03"
            }
        ],
        "fun2": [
            {
                "message": "message fun2",
                "status": "info",
                "time": "2020-06-18T09:06:03"
            }
        ],
        "fun3": [
            {
                "message": "message fun3",
                "status": "other",
                "time": "2020-06-18T09:06:03"
            }
        ]
    }
}

jlog's People

Contributors

pandamy619 avatar

Stargazers

 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.