mirror of
https://shylinux.com/x/icebergs
synced 2025-04-29 10:39:21 +08:00
opt traceid
This commit is contained in:
parent
dc9dd86bba
commit
29c1a023e3
@ -80,14 +80,20 @@ const (
|
|||||||
VIEW = "view"
|
VIEW = "view"
|
||||||
SHOW = "show"
|
SHOW = "show"
|
||||||
)
|
)
|
||||||
|
const (
|
||||||
|
BENCH_LOG = "bench.log"
|
||||||
|
DEBUG_LOG = "debug.log"
|
||||||
|
ERROR_LOG = "error.log"
|
||||||
|
WATCH_LOG = "watch.log"
|
||||||
|
)
|
||||||
const LOG = "log"
|
const LOG = "log"
|
||||||
|
|
||||||
var Index = &ice.Context{Name: LOG, Help: "日志模块", Configs: ice.Configs{
|
var Index = &ice.Context{Name: LOG, Help: "日志模块", Configs: ice.Configs{
|
||||||
FILE: {Name: FILE, Help: "日志文件", Value: kit.Dict(
|
FILE: {Name: FILE, Help: "日志文件", Value: kit.Dict(
|
||||||
BENCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "bench.log"), mdb.LIST, []string{}),
|
BENCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, BENCH_LOG), mdb.LIST, []string{}),
|
||||||
DEBUG, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "debug.log"), mdb.LIST, []string{ice.LOG_DEBUG}),
|
DEBUG, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, DEBUG_LOG), mdb.LIST, []string{ice.LOG_DEBUG}),
|
||||||
ERROR, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "error.log"), mdb.LIST, []string{ice.LOG_WARN, ice.LOG_ERROR}),
|
ERROR, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, ERROR_LOG), mdb.LIST, []string{ice.LOG_WARN, ice.LOG_ERROR}),
|
||||||
WATCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "watch.log"), mdb.LIST, []string{mdb.CREATE, mdb.REMOVE, mdb.INSERT, mdb.DELETE, mdb.MODIFY, mdb.EXPORT, mdb.IMPORT}),
|
WATCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, WATCH_LOG), mdb.LIST, []string{mdb.CREATE, mdb.REMOVE, mdb.INSERT, mdb.DELETE, mdb.MODIFY, mdb.EXPORT, mdb.IMPORT}),
|
||||||
)},
|
)},
|
||||||
VIEW: {Name: VIEW, Help: "日志格式", Value: kit.Dict(
|
VIEW: {Name: VIEW, Help: "日志格式", Value: kit.Dict(
|
||||||
GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", mdb.LIST, []string{ice.CTX_START, ice.LOG_CMDS}),
|
GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", mdb.LIST, []string{ice.CTX_START, ice.LOG_CMDS}),
|
||||||
@ -105,23 +111,34 @@ var Index = &ice.Context{Name: LOG, Help: "日志模块", Configs: ice.Configs{
|
|||||||
kit.For(value[mdb.LIST], func(index int, k string) { m.Conf(SHOW, kit.Keys(k, VIEW), key) })
|
kit.For(value[mdb.LIST], func(index int, k string) { m.Conf(SHOW, kit.Keys(k, VIEW), key) })
|
||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { ice.Info.Save(m, TAIL) }},
|
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
ice.Info.Save(m, TAIL)
|
||||||
|
}},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
func init() { ice.Index.Register(Index, &Frame{}, TAIL) }
|
func init() { ice.Index.Register(Index, &Frame{}, TAIL) }
|
||||||
|
|
||||||
func init() { ice.Info.Traceid = "short"; ice.Pulse.Option(ice.LOG_TRACEID, Traceid()) }
|
func init() {
|
||||||
|
ice.Info.Traceid = "short"
|
||||||
|
ice.Pulse.Option("work.id", "0")
|
||||||
|
ice.Pulse.Option("task.id", "0")
|
||||||
|
ice.Pulse.Option(ice.LOG_TRACEID, Traceid(ice.Pulse))
|
||||||
|
}
|
||||||
|
|
||||||
var _trace_count int64
|
var _trace_count int64
|
||||||
|
|
||||||
func Traceid() (traceid string) {
|
func Traceid(m *ice.Message) (traceid string) {
|
||||||
ls := []string{}
|
ls := []string{}
|
||||||
kit.For(kit.Split(ice.Info.Traceid), func(key string) {
|
kit.For(kit.Split(ice.Info.Traceid), func(key string) {
|
||||||
switch key {
|
switch key {
|
||||||
case "short":
|
case "short":
|
||||||
ls = append(ls, kit.Hashs(mdb.UNIQ)[:6])
|
if len(ls) == 0 {
|
||||||
|
ls = append(ls, kit.Hashs(mdb.UNIQ)[:6])
|
||||||
|
}
|
||||||
case "long":
|
case "long":
|
||||||
ls = append(ls, kit.Hashs(mdb.UNIQ))
|
if len(ls) == 0 {
|
||||||
|
ls = append(ls, kit.Hashs(mdb.UNIQ))
|
||||||
|
}
|
||||||
case "node":
|
case "node":
|
||||||
ls = append(ls, ice.Info.NodeName)
|
ls = append(ls, ice.Info.NodeName)
|
||||||
case "hide":
|
case "hide":
|
||||||
|
@ -96,7 +96,7 @@ func (f *Frame) parse(m *ice.Message, h, line string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
msg := m.Spawn(f.target)
|
msg := m.Spawn(f.target)
|
||||||
kit.If(h == STDIO, func() { msg.Option(ice.LOG_TRACEID, log.Traceid()) })
|
kit.If(h == STDIO, func() { msg.Option(ice.LOG_TRACEID, log.Traceid(m)) })
|
||||||
if msg.Cmdy(ls); h == STDIO && msg.IsErrNotFound() {
|
if msg.Cmdy(ls); h == STDIO && msg.IsErrNotFound() {
|
||||||
msg.SetResult().Cmdy(cli.SYSTEM, ls)
|
msg.SetResult().Cmdy(cli.SYSTEM, ls)
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
|||||||
r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, nfs.DF)[0])
|
r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, nfs.DF)[0])
|
||||||
}
|
}
|
||||||
if !kit.HasPrefix(r.URL.String(), nfs.VOLCANOS, nfs.REQUIRE_MODULES, nfs.INTSHELL) {
|
if !kit.HasPrefix(r.URL.String(), nfs.VOLCANOS, nfs.REQUIRE_MODULES, nfs.INTSHELL) {
|
||||||
r.Header.Set(ice.LOG_TRACEID, log.Traceid())
|
r.Header.Set(ice.LOG_TRACEID, log.Traceid(m))
|
||||||
m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String(), logs.TraceidMeta(r.Header.Get(ice.LOG_TRACEID)))
|
m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String(), logs.TraceidMeta(r.Header.Get(ice.LOG_TRACEID)))
|
||||||
}
|
}
|
||||||
if path.Join(r.URL.Path) == nfs.PS && strings.HasPrefix(r.UserAgent(), html.Mozilla) {
|
if path.Join(r.URL.Path) == nfs.PS && strings.HasPrefix(r.UserAgent(), html.Mozilla) {
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"shylinux.com/x/icebergs/base/ctx"
|
"shylinux.com/x/icebergs/base/ctx"
|
||||||
"shylinux.com/x/icebergs/base/gdb"
|
"shylinux.com/x/icebergs/base/gdb"
|
||||||
"shylinux.com/x/icebergs/base/lex"
|
"shylinux.com/x/icebergs/base/lex"
|
||||||
"shylinux.com/x/icebergs/base/log"
|
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
"shylinux.com/x/icebergs/base/ssh"
|
"shylinux.com/x/icebergs/base/ssh"
|
||||||
@ -97,8 +96,7 @@ func _space_fork(m *ice.Message) {
|
|||||||
}
|
}
|
||||||
args := kit.Simple(mdb.TYPE, m.Option(mdb.TYPE), mdb.NAME, name, mdb.TEXT, text, m.OptionSimple(mdb.TIME, nfs.MODULE, nfs.VERSION, cli.DAEMON))
|
args := kit.Simple(mdb.TYPE, m.Option(mdb.TYPE), mdb.NAME, name, mdb.TEXT, text, m.OptionSimple(mdb.TIME, nfs.MODULE, nfs.VERSION, cli.DAEMON))
|
||||||
args = append(args, aaa.USERNICK, m.Option(ice.MSG_USERNICK), aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE))
|
args = append(args, aaa.USERNICK, m.Option(ice.MSG_USERNICK), aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE))
|
||||||
args = append(args, aaa.UA, m.Option(ice.MSG_USERUA), aaa.IP, m.Option(ice.MSG_USERIP))
|
args = append(args, ParseUA(m)...)
|
||||||
args = _space_agent(m, args...)
|
|
||||||
if c, e := websocket.Upgrade(m.W, m.R); !m.Warn(e) {
|
if c, e := websocket.Upgrade(m.W, m.R); !m.Warn(e) {
|
||||||
gdb.Go(m, func() {
|
gdb.Go(m, func() {
|
||||||
defer mdb.HashCreateDeferRemove(m, args, kit.Dict(mdb.TARGET, c))()
|
defer mdb.HashCreateDeferRemove(m, args, kit.Dict(mdb.TARGET, c))()
|
||||||
@ -147,7 +145,7 @@ func _space_handle(m *ice.Message, safe bool, name string, c *websocket.Conn) {
|
|||||||
source, target := kit.Simple(msg.Optionv(ice.MSG_SOURCE), name), kit.Simple(msg.Optionv(ice.MSG_TARGET))
|
source, target := kit.Simple(msg.Optionv(ice.MSG_SOURCE), name), kit.Simple(msg.Optionv(ice.MSG_TARGET))
|
||||||
msg.Log(tcp.RECV, "%v->%v %v %v", source, target, msg.Detailv(), msg.FormatsMeta(nil))
|
msg.Log(tcp.RECV, "%v->%v %v %v", source, target, msg.Detailv(), msg.FormatsMeta(nil))
|
||||||
if next := msg.Option(ice.MSG_TARGET); next == "" || len(target) == 0 {
|
if next := msg.Option(ice.MSG_TARGET); next == "" || len(target) == 0 {
|
||||||
m.Go(func() {
|
msg.Go(func() {
|
||||||
if k := kit.Keys(msg.Option(ice.MSG_USERPOD), "_token"); msg.Option(k) != "" {
|
if k := kit.Keys(msg.Option(ice.MSG_USERPOD), "_token"); msg.Option(k) != "" {
|
||||||
aaa.SessCheck(msg, msg.Option(k))
|
aaa.SessCheck(msg, msg.Option(k))
|
||||||
}
|
}
|
||||||
@ -160,7 +158,7 @@ func _space_handle(m *ice.Message, safe bool, name string, c *websocket.Conn) {
|
|||||||
case (*websocket.Conn): // 转发报文
|
case (*websocket.Conn): // 转发报文
|
||||||
_space_echo(msg, source, target, c)
|
_space_echo(msg, source, target, c)
|
||||||
case ice.Handler: // 接收响应
|
case ice.Handler: // 接收响应
|
||||||
m.Go(func() { c(msg) })
|
msg.Go(func() { c(msg) })
|
||||||
}
|
}
|
||||||
}), ice.ErrNotFound, next)
|
}), ice.ErrNotFound, next)
|
||||||
}
|
}
|
||||||
@ -200,7 +198,7 @@ func _space_exec(m *ice.Message, name string, source, target []string, c *websoc
|
|||||||
kit.If(m.Optionv(ice.MSG_ARGS) != nil, func() { m.Options(ice.MSG_ARGS, kit.Simple(m.Optionv(ice.MSG_ARGS))) })
|
kit.If(m.Optionv(ice.MSG_ARGS) != nil, func() { m.Options(ice.MSG_ARGS, kit.Simple(m.Optionv(ice.MSG_ARGS))) })
|
||||||
}
|
}
|
||||||
defer m.Cost(kit.Format("%v->%v %v %v", source, target, m.Detailv(), m.FormatSize()))
|
defer m.Cost(kit.Format("%v->%v %v %v", source, target, m.Detailv(), m.FormatSize()))
|
||||||
_space_echo(m.Set(ice.MSG_OPTS).Options(log.DEBUG, m.Option(log.DEBUG)), []string{}, kit.Reverse(kit.Simple(source)), c)
|
_space_echo(m.Set(ice.MSG_OPTS).Options(m.OptionSimple(ice.LOG_DEBUG, ice.LOG_TRACEID)), []string{}, kit.Reverse(kit.Simple(source)), c)
|
||||||
}
|
}
|
||||||
func _space_echo(m *ice.Message, source, target []string, c *websocket.Conn) {
|
func _space_echo(m *ice.Message, source, target []string, c *websocket.Conn) {
|
||||||
defer func() { m.Warn(recover()) }()
|
defer func() { m.Warn(recover()) }()
|
||||||
|
@ -114,7 +114,9 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func FavorAction() ice.Actions { return gdb.EventsAction(FAVOR_INPUTS, FAVOR_TABLES, FAVOR_ACTION) }
|
func FavorAction() ice.Actions {
|
||||||
|
return gdb.EventsAction(FAVOR_INPUTS, FAVOR_TABLES, FAVOR_ACTION)
|
||||||
|
}
|
||||||
func FavorPreview(m *ice.Message, arg ...string) {
|
func FavorPreview(m *ice.Message, arg ...string) {
|
||||||
if kit.HasPrefixList(arg, ctx.RUN) {
|
if kit.HasPrefixList(arg, ctx.RUN) {
|
||||||
if pod := arg[1]; pod != "" {
|
if pod := arg[1]; pod != "" {
|
||||||
|
@ -77,9 +77,9 @@ func init() {
|
|||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
if mdb.IsSearchPreview(m, arg) {
|
if mdb.IsSearchPreview(m, arg) || kit.HasPrefixList(arg, SHELL) {
|
||||||
kit.For([]string{shell, "/bin/ish"}, func(p string) {
|
kit.For([]string{shell, "/bin/ish"}, func(p string) {
|
||||||
m.PushSearch(mdb.TYPE, ssh.SHELL, mdb.NAME, path.Base(p), mdb.TEXT, p)
|
m.PushSearch(mdb.TYPE, SHELL, mdb.NAME, path.Base(p), mdb.TEXT, p)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
@ -88,8 +88,8 @@ func init() {
|
|||||||
case mdb.HASH:
|
case mdb.HASH:
|
||||||
fallthrough
|
fallthrough
|
||||||
case mdb.TYPE:
|
case mdb.TYPE:
|
||||||
m.Cmd(mdb.SEARCH, mdb.FOREACH, "", "", func(value ice.Maps) {
|
m.Cmd(mdb.SEARCH, SHELL, "", "", func(value ice.Maps) {
|
||||||
kit.If(value[mdb.TYPE] == ssh.SHELL, func() { m.Push(arg[0], value[mdb.TEXT]) })
|
kit.If(value[mdb.TYPE] == SHELL, func() { m.Push(arg[0], value[mdb.TEXT]) })
|
||||||
})
|
})
|
||||||
case mdb.NAME:
|
case mdb.NAME:
|
||||||
m.Push(arg[0], path.Base(m.Option(mdb.TYPE)), ice.Info.Hostname)
|
m.Push(arg[0], path.Base(m.Option(mdb.TYPE)), ice.Info.Hostname)
|
||||||
|
8
exec.go
8
exec.go
@ -67,7 +67,13 @@ func (m *Message) Go(cb func(), arg ...Any) *Message {
|
|||||||
meta := m.FormatTaskMeta()
|
meta := m.FormatTaskMeta()
|
||||||
meta.FileLine = kit.FileLine(2, 3)
|
meta.FileLine = kit.FileLine(2, 3)
|
||||||
kit.If(len(arg) > 0, func() { meta.FileLine = kit.Format(arg[0]) })
|
kit.If(len(arg) > 0, func() { meta.FileLine = kit.Format(arg[0]) })
|
||||||
task.Put(meta, nil, func(task *task.Task) { m.TryCatch(true, func(m *Message) { cb() }) })
|
task.Put(meta, nil, func(task *task.Task) {
|
||||||
|
m.TryCatch(true, func(m *Message) {
|
||||||
|
m.Option("task.id", kit.Format(task.TaskId()))
|
||||||
|
m.Option("work.id", kit.Format(task.WorkId()))
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
})
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) GoWait(cb func(func()), arg ...Any) *Message {
|
func (m *Message) GoWait(cb func(func()), arg ...Any) *Message {
|
||||||
|
3
info.go
3
info.go
@ -318,13 +318,10 @@ func (m *Message) FileURI(dir string) string {
|
|||||||
} else if kit.HasPrefix(dir, PS, HTTP) {
|
} else if kit.HasPrefix(dir, PS, HTTP) {
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
m.Debug("what %v", m.Option(MSG_USERPOD))
|
|
||||||
if strings.HasPrefix(dir, USR_VOLCANOS) {
|
if strings.HasPrefix(dir, USR_VOLCANOS) {
|
||||||
return strings.TrimPrefix(dir, USR)
|
return strings.TrimPrefix(dir, USR)
|
||||||
} else {
|
} else {
|
||||||
m.Debug("what %v", m.Option(MSG_USERPOD))
|
|
||||||
what := kit.MergeURL(path.Join(PS, REQUIRE, dir), POD, m.Option(MSG_USERPOD))
|
what := kit.MergeURL(path.Join(PS, REQUIRE, dir), POD, m.Option(MSG_USERPOD))
|
||||||
m.Debug("what %v", what)
|
|
||||||
return what
|
return what
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
logs.go
5
logs.go
@ -186,7 +186,10 @@ func (m *Message) FormatPrefix(traceid ...string) string {
|
|||||||
}
|
}
|
||||||
func (m *Message) FormatShip(traceid ...string) string {
|
func (m *Message) FormatShip(traceid ...string) string {
|
||||||
_traceid := ""
|
_traceid := ""
|
||||||
kit.If(kit.Select(m.Option(LOG_TRACEID), traceid, 0), func(traceid string) { _traceid = kit.Format("%s: %s ", logs.TRACEID, traceid) })
|
kit.If(kit.Select(m.Option(LOG_TRACEID), traceid, 0), func(traceid string) {
|
||||||
|
// _traceid = kit.Format("%s: %s ", logs.TRACEID, traceid+"-"+m.Option("task.id")+"-"+m.Option("work.id"))
|
||||||
|
_traceid = kit.Format("%s: %s ", logs.TRACEID, traceid)
|
||||||
|
})
|
||||||
return kit.Format("%s%02d %4s->%-4s", _traceid, m.code, m.source.Name, m.target.Name)
|
return kit.Format("%s%02d %4s->%-4s", _traceid, m.code, m.source.Name, m.target.Name)
|
||||||
}
|
}
|
||||||
func (m *Message) FormatSize() string {
|
func (m *Message) FormatSize() string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user