alog

package module
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2016 License: Apache-2.0 Imports: 5 Imported by: 17

README

ALog

基于Golang的异步日志包

Installation and usage

$ go get github.com/antlinker/alog

API documentation

Configuration file

{
	# 控制台输出配置
	console: {
		# 输出日志级别(1表示Debug,2表示Info,3表示Warn,4表示Error,5表示Fatal)
  		# 1表示输出Debug及以上所有级别的日志
		level: 1,
		# 日志项模板
		item: {
				# 项模板
		    # 模板字段说明:
		    # ID 唯一标识
		    # Time 日志发生时间
		    # Level 级别
		    # Tag 标签
		    # Message 日志明细
		    # FileName 文件名
		    # ShortName 短文件名
		    # FileFuncName 函数名
		    # FileLine 文件行
			tmpl: "[{{.Time}}|{{.Level}}|{{.Tag}}]{{.ShortName}}:{{.FileLine}}:{{.Message}}",
			# 时间模板
		    # 模板字段说明:
		    # Year 年份
		    # Month 月份
		    # Day 天数
		    # Hour 小时
		    # Minute 分钟
		    # Second 秒
		    # MilliSecond 毫秒
			time: "{{.Hour}}:{{.Minute}}"
		}
	},
	# 全局配置
	global: {
		# IsEnabled 是否启用日志
		# 参数说明:
		# 1表示启用
		# 2表示不启用
		# 默认值为1
		enabled: 1,
		# 是否打印到控制台
	  	# 1表示打印
	  	# 2表示不打印
	  	# 默认为不打印
	  	print: 1,
	  	# 日志输出规则
	  	# 参数说明:
	  	# 0表示所有配置输出
	  	# 1表示指定Global配置输出
	  	# 2表示指定Tag配置输出
	  	# 3表示指定Level配置输出
	  	# 默认为所有配置输出(0)
	  	rule: 0,
	  	# 日志级别
			level: 1,
	  	# 输出文件信息
	  	# 1表示输出
	  	# 2表示不输出
	  	# 默认为输出(1)
	  	showfile: 1,
	  	# 文件信息调用层级
	  	# 默认为6(当前调用)
	  	caller: 6,
	  	# 读取缓冲区时间间隔(以秒为单位)
	  	interval: 1,
	  	# 目标存储
	  	# 指向store中定义的存储配置
	  	# target: "file_global",
	  	# 缓冲区存储
	  	# buffer: {
	  		# 存储引擎
		    # 1表示内存存储
		    # 2表示redis存储
		    # engine: 1,
		    # 指向store中定义的存储配置
		    # target: "redis_buffer"
	  	# }
	},
	# 标签配置
	tags: [{
		# 标签名
  		names: ["ALOG","TEST"],
  		# 配置
  		config: {
  			# 是否打印到控制台
		    # 1表示打印
	  		# 2表示不打印
		    print: 2,
		    # 日志级别
		    level: 1,
		    # 目标存储
		    # 指向store中定义的存储配置
		    target: ""
  		}
	}],
	# 级别配置
	levels: [{
		# 标签名
  		values: [4,5],
  		# 配置
  		config: {
  			# 是否打印到控制台
		    # 1表示打印
	  		# 2表示不打印
		    print: 2,
		    # 目标存储
		    # 指向store中定义的存储配置
		    target: ""
  		}
	}],
	# 持久化存储配置
	store: {
		# redis 存储
		redis: {
			# 唯一标识键
			redis_buffer: {
				# host:port
				addr: "192.168.33.70:6379",
				# db
      			db: 0,
      			# poolsize
      			# Default is 10 connections.
      			poolsize: 10
			}
		},
		# 文件存储
		file: {
			# 唯一标识键
			file_global: {
			  # 文件存储路径
		      filepath: "logs",
		      # 文件名格式模板
		      # 模板字段说明:
		      # Year 年份
		      # Month 月份
		      # Day 天数
		      # Level 日志级别
		      # Tag 标签
		      filename: "{{.Year}}{{.Month}}{{.Day}}.log",
		      # 单个文件大小(单位KB)
		      filesize: 2048,
		      item: {
		      	# 项模板
        		# 字段说明同上
        		tmpl: '{{.ID}} {{.Time}} {{.Level}} {{.Tag}} "{{.FileName}} {{.FileFuncName}} {{.FileLine}}" {{.Message}}',
        		# 时间模板
		        # 字段说明同上
		        time: "{{.Year}}-{{.Month}}-{{.Day}} {{.Hour}}:{{.Minute}}:{{.Second}}.{{.MilliSecond}}"
		      }
			}
		},
		# elasticsearch存储
		elastic: {
			elastic_global: {
				# 指定ElasticSearch的请求节点
				# 默认值为http://127.0.0.1:9200
				url: "http://127.0.0.1:9200",
				# 索引模板
				# 模板字段说明:
				# Year 年份
				# Month 月份
				# Day 天数
				# Level 日志级别
				# Tag 标签
				# 默认值为{{.Year}}.{{.Month}}.{{.Day}}
				index: "{{.Year}}.{{.Month}}.{{.Day}}",
				# 文档类型模板
				# 模板字段说明:
				# Year 年份
				# Month 月份
				# Day 天数
				# Level 日志级别
				# Tag 标签
				# 默认值为ALogs
				type: "ALogs"
			}
		},
		# MongoDB存储
		mongo: {
			mongo_global: {
				# 指定MongoDB的链接地址
				# 默认值为mongodb://127.0.0.1:27017
				url: "mongodb://127.0.0.1:27017",
				# 存储数据库名称模板
				# 模板字段说明:
				# Year 年份
				# Month 月份
				# Day 天数
				# Level 日志级别
				# Tag 标签
				# 默认值为alog
				db: "alog",
				# 存储集合名称模板
				# 模板字段说明:
				# Year 年份
				# Month 月份
				# Day 天数
				# Level 日志级别
				# Tag 标签
				# 默认值为{{.Year}}{{.Month}}{{.Day}}
				collection: "{{.Year}}{{.Month}}{{.Day}}"
			}
		}
	}
}

Sample

package main

import (
	"time"

	"github.com/antlinker/alog"
)

func main() {
	alog.RegisterAlog()
	alog.SetLogTag("Sample")
	alog.Debug("Debug info...")
	alog.DebugC("Debug console info...")
	alog.Info("Info info...")
	alog.InfoC("Info console info...")
	alog.Warn("Warn info...")
	alog.WarnC("Warn console info...")
	alog.Error("Error info...")
	alog.ErrorC("Error console info...")
	alog.Fatal("Fatal info...")
	alog.FatalC("Fatal console info...")
	time.Sleep(2 * time.Second)
}
Console Output:
[13:36:58|Debug|Sample]main.go:13:Debug console info...
[13:36:58|Info|Sample]main.go:15:Info console info...
[13:36:58|Warn|Sample]main.go:17:Warn console info...
[13:36:58|Error|Sample]main.go:19:Error console info...
[13:36:58|Fatal|Sample]main.go:21:Fatal console info...
File Output:
2016-01-18 13:38:09.721 Debug Sample "main.go main.main 12" Debug info...
2016-01-18 13:38:09.721 Info Sample "main.go main.main 14" Info info...
2016-01-18 13:38:09.721 Warn Sample "main.go main.main 16" Warn info...
2016-01-18 13:38:09.721 Error Sample "main.go main.main 18" Error info...
2016-01-18 13:38:09.721 Fatal Sample "main.go main.main 20" Fatal info...

License

Copyright 2015.All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Debug Debug 消息

func DebugC

func DebugC(v ...interface{})

Debug Debug 控制台消息

func DebugCf

func DebugCf(format string, v ...interface{})

Debug Debug 控制台格式化消息

func DebugT

func DebugT(tag string, v ...interface{})

Debug Debug 标签消息

func DebugTC

func DebugTC(tag string, v ...interface{})

Debug Debug 控制台标签消息

func DebugTCf

func DebugTCf(tag string, format string, v ...interface{})

Debug Debug 控制台标签格式化消息

func DebugTf

func DebugTf(tag string, format string, v ...interface{})

Debug Debug 标签格式化消息

func Debugf

func Debugf(format string, v ...interface{})

Debug Debug 格式化消息

func Error

func Error(v ...interface{})

Error Error 消息

func ErrorC

func ErrorC(v ...interface{})

Error Error 控制台消息

func ErrorCf

func ErrorCf(format string, v ...interface{})

Error Error 控制台格式化消息

func ErrorT

func ErrorT(tag string, v ...interface{})

Error Error 标签消息

func ErrorTC

func ErrorTC(tag string, v ...interface{})

Error Error 控制台标签消息

func ErrorTCf

func ErrorTCf(tag string, format string, v ...interface{})

Error Error 控制台标签格式化消息

func ErrorTf

func ErrorTf(tag string, format string, v ...interface{})

Error Error 标签格式化消息

func Errorf

func Errorf(format string, v ...interface{})

Error Error 格式化消息

func Fatal

func Fatal(v ...interface{})

Fatal Fatal 消息

func FatalC

func FatalC(v ...interface{})

Fatal Fatal 控制台消息

func FatalCf

func FatalCf(format string, v ...interface{})

Fatal Fatal 控制台格式化消息

func FatalT

func FatalT(tag string, v ...interface{})

Fatal Fatal 标签消息

func FatalTC

func FatalTC(tag string, v ...interface{})

Fatal Fatal 控制台标签消息

func FatalTCf

func FatalTCf(tag string, format string, v ...interface{})

Fatal Fatal 控制台标签格式化消息

func FatalTf

func FatalTf(tag string, format string, v ...interface{})

Fatal Fatal 标签格式化消息

func Fatalf

func Fatalf(format string, v ...interface{})

Fatal Fatal 格式化消息

func Info

func Info(v ...interface{})

Info Info 消息

func InfoC

func InfoC(v ...interface{})

Info Info 控制台消息

func InfoCf

func InfoCf(format string, v ...interface{})

Info Info 控制台格式化消息

func InfoT

func InfoT(tag string, v ...interface{})

Info Info 标签消息

func InfoTC

func InfoTC(tag string, v ...interface{})

Info Info 控制台标签消息

func InfoTCf

func InfoTCf(tag string, format string, v ...interface{})

Info Info 控制台标签格式化消息

func InfoTf

func InfoTf(tag string, format string, v ...interface{})

Info Info 标签格式化消息

func Infof

func Infof(format string, v ...interface{})

Info Info 格式化消息

func RegisterAlog

func RegisterAlog(configs ...string)

RegisterAlog 注册并初始化ALog configs 配置信息: 配置文件方式,包含yaml,json两种方式

func SetEnabled

func SetEnabled(enabled bool)

SetEnabled 设置是否启用日志

func SetLogTag

func SetLogTag(tag string)

SetLogTag 设置日志标签

func Warn

func Warn(v ...interface{})

Warn Warn 消息

func WarnC

func WarnC(v ...interface{})

Warn Warn 控制台消息

func WarnCf

func WarnCf(format string, v ...interface{})

Warn Warn 控制台格式化消息

func WarnT

func WarnT(tag string, v ...interface{})

Warn Warn 标签消息

func WarnTC

func WarnTC(tag string, v ...interface{})

Warn Warn 控制台标签消息

func WarnTCf

func WarnTCf(tag string, format string, v ...interface{})

Warn Warn 控制台标签格式化消息

func WarnTf

func WarnTf(tag string, format string, v ...interface{})

Warn Warn 标签格式化消息

func Warnf

func Warnf(format string, v ...interface{})

Warn Warn 格式化消息

Types

type ALog

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

ALog 提供ALog日志模块的输出管理

var (
	// 提供全局的ALog
	GALog *ALog
)

func NewALog

func NewALog(configs ...string) *ALog

NewALog 获取ALog实例 configs 配置文件路径

func (*ALog) Debug

func (a *ALog) Debug(v ...interface{})

func (*ALog) DebugC

func (a *ALog) DebugC(v ...interface{})

func (*ALog) DebugCf

func (a *ALog) DebugCf(format string, v ...interface{})

func (*ALog) DebugT

func (a *ALog) DebugT(tag string, v ...interface{})

func (*ALog) DebugTC

func (a *ALog) DebugTC(tag string, v ...interface{})

func (*ALog) DebugTCf

func (a *ALog) DebugTCf(tag string, format string, v ...interface{})

func (*ALog) DebugTf

func (a *ALog) DebugTf(tag string, format string, v ...interface{})

func (*ALog) Debugf

func (a *ALog) Debugf(format string, v ...interface{})

func (*ALog) Error

func (a *ALog) Error(v ...interface{})

func (*ALog) ErrorC

func (a *ALog) ErrorC(v ...interface{})

func (*ALog) ErrorCf

func (a *ALog) ErrorCf(format string, v ...interface{})

func (*ALog) ErrorT

func (a *ALog) ErrorT(tag string, v ...interface{})

func (*ALog) ErrorTC

func (a *ALog) ErrorTC(tag string, v ...interface{})

func (*ALog) ErrorTCf

func (a *ALog) ErrorTCf(tag string, format string, v ...interface{})

func (*ALog) ErrorTf

func (a *ALog) ErrorTf(tag string, format string, v ...interface{})

func (*ALog) Errorf

func (a *ALog) Errorf(format string, v ...interface{})

func (*ALog) Fatal

func (a *ALog) Fatal(v ...interface{})

func (*ALog) FatalC

func (a *ALog) FatalC(v ...interface{})

func (*ALog) FatalCf

func (a *ALog) FatalCf(format string, v ...interface{})

func (*ALog) FatalT

func (a *ALog) FatalT(tag string, v ...interface{})

func (*ALog) FatalTC

func (a *ALog) FatalTC(tag string, v ...interface{})

func (*ALog) FatalTCf

func (a *ALog) FatalTCf(tag string, format string, v ...interface{})

func (*ALog) FatalTf

func (a *ALog) FatalTf(tag string, format string, v ...interface{})

func (*ALog) Fatalf

func (a *ALog) Fatalf(format string, v ...interface{})

func (*ALog) GetConfig

func (a *ALog) GetConfig() *log.LogConfig

GetConfig 获取配置文件信息

func (*ALog) GetWriteNum

func (a *ALog) GetWriteNum() int64

GetWriteNum 获取写入持久化日志条数

func (*ALog) Info

func (a *ALog) Info(v ...interface{})

func (*ALog) InfoC

func (a *ALog) InfoC(v ...interface{})

func (*ALog) InfoCf

func (a *ALog) InfoCf(format string, v ...interface{})

func (*ALog) InfoT

func (a *ALog) InfoT(tag string, v ...interface{})

func (*ALog) InfoTC

func (a *ALog) InfoTC(tag string, v ...interface{})

func (*ALog) InfoTCf

func (a *ALog) InfoTCf(tag string, format string, v ...interface{})

func (*ALog) InfoTf

func (a *ALog) InfoTf(tag string, format string, v ...interface{})

func (*ALog) Infof

func (a *ALog) Infof(format string, v ...interface{})

func (*ALog) ReloadConfig

func (a *ALog) ReloadConfig(cfg string) error

ReloadConfig 重置加载配置文件

func (*ALog) SetEnabled

func (a *ALog) SetEnabled(enabled bool)

SetEnabled 设置是否启用日志

func (*ALog) SetFileCaller

func (a *ALog) SetFileCaller(caller int)

SetFileCaller 设置文件调用层次

func (*ALog) SetLogLevel

func (a *ALog) SetLogLevel(level log.LogLevel)

SetLogLevel 设置日志输出级别

func (*ALog) SetLogTag

func (a *ALog) SetLogTag(tag string)

SetLogTag 设置LogTag

func (*ALog) SetPrint

func (a *ALog) SetPrint(v bool)

SetPrint 设置控制台输出日志

func (*ALog) SetRule

func (a *ALog) SetRule(rule log.LogRule)

SetRule 设置输出规则

func (*ALog) SetShowFile

func (a *ALog) SetShowFile(v bool)

SetShowFile 设置输出文件信息

func (*ALog) Warn

func (a *ALog) Warn(v ...interface{})

func (*ALog) WarnC

func (a *ALog) WarnC(v ...interface{})

func (*ALog) WarnCf

func (a *ALog) WarnCf(format string, v ...interface{})

func (*ALog) WarnT

func (a *ALog) WarnT(tag string, v ...interface{})

func (*ALog) WarnTC

func (a *ALog) WarnTC(tag string, v ...interface{})

func (*ALog) WarnTCf

func (a *ALog) WarnTCf(tag string, format string, v ...interface{})

func (*ALog) WarnTf

func (a *ALog) WarnTf(tag string, format string, v ...interface{})

func (*ALog) Warnf

func (a *ALog) Warnf(format string, v ...interface{})

func (*ALog) Write

func (a *ALog) Write(onlyConsole bool, level log.LogLevel, tag string, v ...interface{})

Write 输出消息

func (*ALog) Writef

func (a *ALog) Writef(onlyConsole bool, level log.LogLevel, tag string, format string, v ...interface{})

Writef 输出格式化消息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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