Giter VIP home page Giter VIP logo

slog's Introduction

slog

golang log with file split by day and logLevel controll

usage

import slog

slog.Debug("test", "hello %s", "sails")
slog.Info("test", "hello %s", "sails")
slog.Warn("test", "hello %s", "sails")
slog.Error("test", "hello %s", "sails")

日志的第一个参数是日志名,第二个参数是格式化字符串,后面的参数是对应的值

slog 默认会在当前目录下创建一个log目录用于保存日志文件,比如:

slog.Debug("test", "hello %s", "sails")

将在当前目录创建test.log,把所有的内容输出到文件中

configure

slog可以通过指定一个json的配置文件进行配置,有几个选项可提供配置:

  • Out,用于指定输出的类型,有两个值"file,console",可以同时指定.默认是FILE。
  • Level, 用于指定输入的级别,有1,2,3,4分别对应debug,info, warn,error;默认是debug。
  • FileSplit, 当Out指定了FILE类型时,用于表明文件的拆分形式,分三种:不拆分,按天,按月;默认是不拆分。
  • FileDir,用于指定输入的目录,默认是当前目录。
  • LogLevels,它是一个json结构,用于单独指定日志配置,有以下几个配置:
    • LogName,要单独配置的日志名
    • Level,单独配置的输出级别
    • FileSplit,单独的文件拆分形式
    • FileName,日志对应的文件名,默认文件名也文件名对应

example, config.json:

{
    "Out":"console, file",
    "Level":2,
    "FileSplit":2,
    "FileDir":"./log/",
    "LogLevels":[
		{"LogName":"test","Level":2, "FileSplit":2, "FileName":"test"}
    ]
}
slog.SetLogConfigFile("./config.json")

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.