Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Index = &ctx.Context{Name: "log", Help: "日志中心", Caches: map[string]*ctx.Cache{}, Configs: map[string]*ctx.Config{}, Commands: map[string]*ctx.Command{ "silent": &ctx.Command{Name: "silent [[module] level state]", Help: "查看或设置日志开关, module: 模块名, level: 日志类型, state(true/false): 是否打印日志", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { if log, ok := m.Target().Server.(*LOG); m.Assert(ok) { switch len(arg) { case 2: if len(arg) > 1 { log.silent[arg[0]] = ctx.Right(arg[1]) } case 3: if log.module[arg[0]] == nil { log.module[arg[0]] = map[string]bool{} } log.module[arg[0]][arg[1]] = ctx.Right(arg[2]) } for k, v := range log.silent { m.Echo("%s: %t\n", k, v) } for k, v := range log.module { for i, x := range v { m.Echo("%s(%s): %t\n", k, i, x) } } } }}, "color": &ctx.Command{Name: "color [level color]", Help: "查看或设置日志颜色, level: 日志类型, color: 文字颜色", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { if log, ok := m.Target().Server.(*LOG); m.Assert(ok) { if len(arg) > 1 { c, e := strconv.Atoi(arg[1]) m.Assert(e) log.color[arg[0]] = c } for k, v := range log.color { m.Echo("\033[%dm%s: %d\033[0m\n", v, k, v) } } }}, "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) { if s, ok := log.silent[arg[0]]; ok && s == true { return } msg := m.Message() if x, ok := m.Data["msg"]; ok { if msg, ok = x.(*ctx.Message); !ok { msg = m.Message() } } if s, ok := log.module[msg.Target().Name]; ok { if x, ok := s[arg[0]]; ok && x { return } } date := "" if m.Confs("flag_date") { date += time.Now().Format("2006/01/02 ") } if m.Confs("flag_time") { date += time.Now().Format("15:04:05 ") } color := 0 if m.Confs("flag_color") { if c, ok := log.color[arg[0]]; ok { color = c } } code := "" if m.Confs("flag_code") { code = fmt.Sprintf("%d ", msg.Code()) } action := "" if m.Confs("flag_action") { action = fmt.Sprintf("%s", arg[0]) if m.Confs("flag_name") { action = fmt.Sprintf("%s(%s->%s)", action, msg.Source().Name, msg.Target().Name) } } cmd := strings.Join(arg[1:], "") if log.nfs != nil { if color > 0 { m.Spawn(log.nfs.Target()).Cmd("write", fmt.Sprintf("%s\033[%dm%s%s %s\033[0m\n", date, color, code, action, cmd)) } else { m.Spawn(log.nfs.Target()).Cmd("write", fmt.Sprintf("%s%s%s %s\n", date, code, action, cmd)) } } } }}, }, Index: map[string]*ctx.Context{ "void": &ctx.Context{Name: "void", Help: "void", Configs: map[string]*ctx.Config{ "flag_code": &ctx.Config{}, "flag_action": &ctx.Config{}, "flag_name": &ctx.Config{}, "flag_color": &ctx.Config{}, "flag_time": &ctx.Config{}, "flag_date": &ctx.Config{}, }, Commands: map[string]*ctx.Command{"log": &ctx.Command{}}, }, }, }
View Source
var Pulse *ctx.Message
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.