log

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Index = &ctx.Context{Name: "log", Help: "日志中心",
	Caches: map[string]*ctx.Cache{
		"nlog": &ctx.Cache{Name: "nlog", Value: "0", Help: "日志屏蔽类型"},
	},
	Configs: map[string]*ctx.Config{
		"silent": &ctx.Config{Name: "silent", Value: map[string]interface{}{"cb": true, "find": true}, Help: "日志屏蔽类型"},
		"module": &ctx.Config{Name: "module", Value: map[string]interface{}{
			"log":     map[string]interface{}{"cmd": true},
			"lex":     map[string]interface{}{"cmd": true, "debug": true},
			"yac":     map[string]interface{}{"cmd": true, "debug": true},
			"matrix1": map[string]interface{}{"cmd": true, "debug": true},
		}, Help: "日志屏蔽模块"},
		"color": &ctx.Config{Name: "color", Value: map[string]interface{}{
			"debug": 0, "error": 31, "check": 31,
			"cmd": 32, "conf": 33,
			"search": 35, "find": 35, "cb": 35, "lock": 35,
			"begin": 36, "start": 36, "close": 36,
		}, Help: "日志输出颜色"},
		"log_name": &ctx.Config{Name: "log_name", Value: "dump", Help: "日志屏蔽类型"},
	},
	Commands: map[string]*ctx.Command{
		"open": &ctx.Command{Name: "open file", Help: "打开日志文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
		}},
		"log": &ctx.Command{Name: "log level string...", Help: "输出日志, level: 日志类型, string: 日志内容", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
			if log, ok := m.Target().Server.(*LOG); m.Assert(ok) && log.out != nil {
				if m.Confs("silent", arg[0]) {
					return
				}
				msg, ok := m.Optionv("msg").(*ctx.Message)
				if !ok {
					msg = m
				}
				if m.Confs("module", fmt.Sprintf("%s.%s", msg.Target().Name, arg[0])) {
					return
				}
				color := 0
				if m.Confs("flag_color") && m.Confs("color", arg[0]) {
					color = m.Confi("color", arg[0])
				}
				date := time.Now().Format(m.Conf("flag_time"))
				action := fmt.Sprintf("%d %s(%s->%s)", msg.Code(), arg[0], msg.Source().Name, msg.Target().Name)
				cmd := strings.Join(arg[1:], "")
				if color > 0 {
					log.out.WriteString(fmt.Sprintf("%s\033[%dm%s %s\033[0m\n", date, color, action, cmd))
				} else {
					log.out.WriteString(fmt.Sprintf("%s%s %s\n", date, action, cmd))
				}
			}
		}},
		"pwd": &ctx.Command{Name: "pwd", Help: "打开日志文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
			m.Echo("nice")
		}},
	},
}
View Source
var Pulse *ctx.Message

Functions

This section is empty.

Types

type LOG

type LOG struct {
	*ctx.Context
	// contains filtered or unexported fields
}

func (*LOG) Begin

func (log *LOG) Begin(m *ctx.Message, arg ...string) ctx.Server

func (*LOG) Close

func (log *LOG) Close(m *ctx.Message, arg ...string) bool

func (*LOG) Spawn

func (log *LOG) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server

func (*LOG) Start

func (log *LOG) Start(m *ctx.Message, arg ...string) bool

Jump to

Keyboard shortcuts

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