]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
log替换
authorqydysky <qydysky@foxmail.com>
Mon, 28 Dec 2020 15:34:42 +0000 (23:34 +0800)
committerqydysky <qydysky@foxmail.com>
Mon, 28 Dec 2020 15:34:42 +0000 (23:34 +0800)
CV/Const.go
CV/Var.go
F/api.go
Reply/F.go
Reply/Heartbeat.go
Reply/Msg.go
Reply/Reply.go
bili_danmu.go
demo/go.mod
demo/go.sum

index 3aab07232964167383de3a3b4b894d501585ada7..f1770091de4a68673e445cb8c765a64ac61dd2e0 100644 (file)
@@ -1,9 +1,5 @@
 package cv
 
-const (
-       LogLevel  = 1
-)
-
 //from source/player-loader-2.0.11.min.js
 const (
        WS_OP_HEARTBEAT = 2
index 7985468b9fb3b0ecfca63a1db849fb4d2ad6190b..f8b6226e13968c80615f6a4eab82ff291dd04b01 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -3,6 +3,7 @@ package cv
 import (
        "time"
        mq "github.com/qydysky/part/msgq"
+       log "github.com/qydysky/part/log"
 )
 
 
@@ -30,6 +31,18 @@ type Danmu_Main_mq_item struct {
 }
 var Danmu_Main_mq = mq.New(10)
 
+//日志
+var Log = log.New(log.Config{
+       File:`danmu.log`,
+       Stdout:true,
+       Prefix_string:map[string]struct{}{
+               `T: `:log.On,
+               `I: `:log.On,
+               `N: `:log.On,
+               `E: `:log.On,
+       },
+})
+
 //from player-loader-2.0.11.min.js
 /*
        customAuthParam
index e88b66fa2c8f18a9c5c5f7b6e3bcec8497e888fd..5d8e1943b3c6d9f68b3392d3e410ee6c3f2a377e 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -25,14 +25,11 @@ type api struct {
        Token string
 }
 
-var apilog = p.Logf().New().Base(-1, "api.go").Level(2)
+var apilog = c.Log.Base(`api`)
 var api_limit = p.Limit(1,2000,15000)//频率限制1次/2s,最大等待时间15s
 
 func New_api(Roomid int) (o *api) {
-       apilog.Base(-1, "新建")
-       defer apilog.Base(0)
-
-       apilog.T("ok")
+       apilog.Base_add(`新建`).L(`T: `,"ok")
        o = new(api)
        o.Roomid = Roomid
        o.Get_info()
@@ -42,11 +39,12 @@ func New_api(Roomid int) (o *api) {
 
 func (i *api) Get_info() (o *api) {
        o = i
-       apilog.Base(-1, "获取房号")
-       defer apilog.Base(0)
+       apilog := apilog.Base_add(`获取房号`)
+       defer apilog.L(`T: `,"ok")
+       
 
        if o.Roomid == 0 {
-               apilog.E("还未New_api")
+               apilog.L(`E: `,"还未New_api")
                return
        }
        if api_limit.TO() {return}//超额请求阻塞,超时将取消
@@ -58,9 +56,9 @@ func (i *api) Get_info() (o *api) {
        })
        //uid
        if tmp := r.S(`"uid":`, `,`, 0, 0);tmp.Err != nil {
-               // apilog.E("uid", tmp.Err)
+               // apilog.L(`E: `,"uid", tmp.Err)
        } else if i,err := strconv.Atoi(tmp.RS[0]); err != nil{
-               apilog.E("uid", err)
+               apilog.L(`E: `,"uid", err)
        } else {
                o.Uid = i
        }
@@ -78,11 +76,10 @@ func (i *api) Get_info() (o *api) {
        }
        //roomid
        if tmp := r.S(`"room_id":`, `,`, 0, 0);tmp.Err != nil {
-               // apilog.E("room_id", tmp.Err)
+               // apilog.L(`E: `,"room_id", tmp.Err)
        } else if i,err := strconv.Atoi(tmp.RS[0]); err != nil{
-               apilog.E("room_id", err)
+               apilog.L(`E: `,"room_id", err)
        } else {
-               apilog.T("ok")
                o.Roomid = i
        }
 
@@ -99,12 +96,12 @@ func (i *api) Get_info() (o *api) {
                        Timeout:10,
                        Retry:2,
                });err != nil {
-                       apilog.E(err)
+                       apilog.L(`E: `,err)
                        return
                }
                res := string(req.Respon)
                if code := p.Json().GetValFrom(res, "code");code == nil || code.(float64) != 0 {
-                       apilog.E("code", code, p.Json().GetValFrom(res, "message"))
+                       apilog.L(`E: `,"code", code, p.Json().GetValFrom(res, "message"))
                        return
                }
                //主播id
@@ -116,31 +113,29 @@ func (i *api) Get_info() (o *api) {
                        c.Note = rank_desc
                }
                if Uid := p.Json().GetValFrom(res, "data.room_info.uid");Uid == nil {
-                       apilog.E("data.room_info.uid", Uid)
+                       apilog.L(`E: `,"data.room_info.uid", Uid)
                        return
                } else {
                        o.Uid = int(Uid.(float64))
                }
 
                if room_id := p.Json().GetValFrom(res, "data.room_info.room_id");room_id == nil {
-                       apilog.E("data.room_info.room_id", room_id)
+                       apilog.L(`E: `,"data.room_info.room_id", room_id)
                        return
                } else {
-                       apilog.T("ok")
                        o.Roomid = int(room_id.(float64))
                }
                if title := p.Json().GetValFrom(res, "data.room_info.title");title == nil {
-                       apilog.E("data.room_info.title", title)
+                       apilog.L(`E: `,"data.room_info.title", title)
                        return
                } else {
-                       apilog.T("ok")
                        c.Title = title.(string)
                }
                if is_locked := p.Json().GetValFrom(res, "data.room_info.lock_status");is_locked == nil {
-                       apilog.E("data.room_info.is_locked", is_locked)
+                       apilog.L(`E: `,"data.room_info.is_locked", is_locked)
                        return
                } else if is_locked.(float64) == 1 {
-                       apilog.W("直播间封禁中")
+                       apilog.L(`W: `,"直播间封禁中")
                        o.Locked = true
                        return
                }
@@ -150,8 +145,11 @@ func (i *api) Get_info() (o *api) {
 
 func (i *api) Get_live(qn ...string) (o *api) {
        o = i
+       apilog := apilog.Base_add(`获取直播流`)
+       defer apilog.L(`T: `,"ok")
+
        if o.Roomid == 0 {
-               apilog.E("还未New_api")
+               apilog.L(`E: `,"还未New_api")
                return
        }
        if api_limit.TO() {return}//超额请求阻塞,超时将取消
@@ -176,7 +174,7 @@ func (i *api) Get_live(qn ...string) (o *api) {
                })
                if e := r.S(`"durl":[`, `]`, 0, 0).Err;e == nil {
                        if urls := p.Json().GetArrayFrom("[" + r.RS[0] + "]", "url");urls != nil {
-                               apilog.W("直播中")
+                               apilog.L(`W: `,"直播中")
                                c.Liveing = true
                                o.Live_status = 1
                                for _,v := range urls {
@@ -202,41 +200,41 @@ func (i *api) Get_live(qn ...string) (o *api) {
                        Timeout:10,
                        Retry:2,
                });err != nil {
-                       apilog.E(err)
+                       apilog.L(`E: `,err)
                        return
                }
                res := string(req.Respon)
                if code := p.Json().GetValFromS(res, "code");code == nil || code.(float64) != 0 {
-                       apilog.E("code", code)
+                       apilog.L(`E: `,"code", code)
                        return
                }
                if is_locked := p.Json().GetValFrom(res, "data.is_locked");is_locked == nil {
-                       apilog.E("data.is_locked", is_locked)
+                       apilog.L(`E: `,"data.is_locked", is_locked)
                        return
                } else if is_locked.(bool) {
-                       apilog.W("直播间封禁中")
+                       apilog.L(`W: `,"直播间封禁中")
                        o.Locked = true
                        return
                }
                if live_status := p.Json().GetValFrom(res, "data.live_status");live_status == nil {
-                       apilog.E("data.live_status", live_status)
+                       apilog.L(`E: `,"data.live_status", live_status)
                        return
                } else {
                        o.Live_status = live_status.(float64)
                        switch live_status.(float64) {
                        case 2:
                                c.Liveing = false
-                               apilog.W("轮播中")
+                               apilog.L(`W: `,"轮播中")
                                return
                        case 0: //未直播
                                c.Liveing = false
-                               apilog.W("未在直播")
+                               apilog.L(`W: `,"未在直播")
                                return
                        case 1:
                                c.Liveing = true
-                               apilog.W("直播中")
+                               apilog.L(`W: `,"直播中")
                        default:
-                               apilog.W("live_status:", live_status)
+                               apilog.L(`W: `,"live_status:", live_status)
                        }
                }
                if codec0 := p.Json().GetValFrom(res, "data.playurl_info.playurl.stream.[0].format.[0].codec.[0]");codec0 != nil {//直播流链接
@@ -251,7 +249,7 @@ func (i *api) Get_live(qn ...string) (o *api) {
                                o.Live = append(o.Live, host.(string) + base_url.(string) + extra.(string))
                        }
                }
-               if len(o.Live) == 0 {apilog.E("live url is nil");return}
+               if len(o.Live) == 0 {apilog.L(`E: `,"live url is nil");return}
 
                if i := p.Json().GetValFrom(res, "data.playurl_info.playurl.stream.[0].format.[0].codec.[0].current_qn"); i != nil {
                        cu_qn = strconv.Itoa(int(i.(float64)))
@@ -266,18 +264,18 @@ func (i *api) Get_live(qn ...string) (o *api) {
                                tmp_qn int
                                e error
                        )
-                       if tmp_qn,e = strconv.Atoi(qn[0]);e != nil {apilog.E(`qn error`,e);return}
+                       if tmp_qn,e = strconv.Atoi(qn[0]);e != nil {apilog.L(`E: `,`qn error`,e);return}
                        if i,ok := p.Json().GetValFrom(res, "data.playurl_info.playurl.stream.[0].format.[0].codec.[0].accept_qn").([]interface{}); ok && len(i) != 0 {
                                for _,v := range i {
                                        if o,ok := v.(float64);ok && int(o) == tmp_qn {accept_qn_request = true}
                                }
                        }
                        if !accept_qn_request {
-                               apilog.E(`qn不在accept_qn中`);
+                               apilog.L(`E: `,`qn不在accept_qn中`);
                                return
                        }
                        if _,ok := c.Default_qn[qn[0]];!ok{
-                               apilog.W("清晰度未找到", qn[0], ",使用默认")
+                               apilog.L(`W: `,"清晰度未找到", qn[0], ",使用默认")
                                return
                        }
                        if err := req.Reqf(p.Rval{
@@ -289,7 +287,7 @@ func (i *api) Get_live(qn ...string) (o *api) {
                                Timeout:10,
                                Retry:2,
                        });err != nil {
-                               apilog.E(err)
+                               apilog.L(`E: `,err)
                                return
                        }
                        res = string(req.Respon)
@@ -305,7 +303,7 @@ func (i *api) Get_live(qn ...string) (o *api) {
                                        o.Live = append(o.Live, host.(string) + base_url.(string) + extra.(string))
                                }
                        }
-                       if len(o.Live) == 0 {apilog.E("live url is nil");return}
+                       if len(o.Live) == 0 {apilog.L(`E: `,"live url is nil");return}
        
                        if i := p.Json().GetValFrom(res, "data.playurl_info.playurl.stream.[0].format.[0].codec.[0].current_qn"); i != nil {
                                cu_qn = strconv.Itoa(int(i.(float64)))
@@ -314,18 +312,17 @@ func (i *api) Get_live(qn ...string) (o *api) {
        }
 
        if v,ok := c.Default_qn[cu_qn];ok {
-               apilog.W("当前清晰度:", v)
+               apilog.L(`W: `,"当前清晰度:", v)
        }
        return
 }
 
 func (i *api) Get_host_Token() (o *api) {
        o = i
-       apilog.Base(-1, "获取host key")
-       defer apilog.Base(0)
+       apilog := apilog.Base_add(`获取Token`)
 
        if o.Roomid == 0 {
-               apilog.E("还未New_api")
+               apilog.L(`E: `,"还未New_api")
                return
        }
        Roomid := strconv.Itoa(o.Roomid)
@@ -342,35 +339,35 @@ func (i *api) Get_host_Token() (o *api) {
                Timeout:10,
                Retry:2,
        });err != nil {
-               apilog.E(err)
+               apilog.L(`E: `,err)
                return
        }
        res := string(req.Respon)
        if msg := p.Json().GetValFromS(res, "message");msg == nil || msg != "0" {
-               apilog.E("message", msg)
+               apilog.L(`E: `,"message", msg)
                return
        }
 
        _Token := p.Json().GetValFromS(res, "data.token")
        if _Token == nil {
-               apilog.E("data.token", _Token, res)
+               apilog.L(`E: `,"data.token", _Token, res)
                return
        }
        o.Token = _Token.(string)
 
        if host_list := p.Json().GetValFromS(res, "data.host_list");host_list == nil {
-               apilog.E("data.host_list", host_list)
+               apilog.L(`E: `,"data.host_list", host_list)
                return
        } else {
                for k, v := range host_list.([]interface{}) {
                        if _host := p.Json().GetValFrom(v, "host");_host == nil {
-                               apilog.E("data.host_list[", k, "].host", _host)
+                               apilog.L(`E: `,"data.host_list[", k, "].host", _host)
                                continue
                        } else {
                                o.Url = append(o.Url, "wss://" + _host.(string) + "/sub")
                        }                       
                }
-               apilog.T("ok")
+               apilog.L(`T: `,"ok")
        }
 
        return
@@ -379,6 +376,7 @@ func (i *api) Get_host_Token() (o *api) {
 func Get_face_src(uid string) (string) {
        if uid == "" {return ""}
        if api_limit.TO() {return ""}//超额请求阻塞,超时将取消
+       apilog := apilog.Base_add(`获取头像`)
 
        req := p.Req()
        if err := req.Reqf(p.Rval{
@@ -390,18 +388,18 @@ func Get_face_src(uid string) (string) {
                Timeout:10,
                Retry:2,
        });err != nil {
-               apilog.Base(1, "获取face").E(err)
+               apilog.L(`E: `,err)
                return ""
        }
        res := string(req.Respon)
        if msg := p.Json().GetValFromS(res, "message");msg == nil || msg != "0" {
-               apilog.Base(1, "获取face").E("message", msg)
+               apilog.L(`E: `,"message", msg)
                return ""
        }
 
        rface := p.Json().GetValFromS(res, "data.rface")
        if rface == nil {
-               apilog.Base(1, "获取face").E("data.rface", rface)
+               apilog.L(`E: `,"data.rface", rface)
                return ""
        }
        return rface.(string) + `@58w_58h`
@@ -409,16 +407,16 @@ func Get_face_src(uid string) (string) {
 
 func (i *api) Get_OnlineGoldRank() {
        if i.Uid == 0 || c.Roomid == 0 {
-               apilog.Base(1, "Get_OnlineGoldRank").E("i.Uid == 0 || c.Roomid == 0")
+               apilog.Base_add("Get_OnlineGoldRank").L(`E: `,"i.Uid == 0 || c.Roomid == 0")
                return
        }
        if api_limit.TO() {return}//超额请求阻塞,超时将取消
+       apilog := apilog.Base_add(`获取贡献榜`)
 
        var session_roomid = c.Roomid
        var self_loop func(page int)
        self_loop = func(page int){
                if page <= 0 || session_roomid != c.Roomid{return}
-               // apilog.Base(1, "self_loop").E(page)
 
                req := p.Req()
                if err := req.Reqf(p.Rval{
@@ -439,21 +437,20 @@ func (i *api) Get_OnlineGoldRank() {
                        Timeout:3,
                        Retry:2,
                });err != nil {
-                       apilog.Base(1, "获取OnlineGoldRank").E(err)
+                       apilog.L(`E: `,err)
                        return
                }
                res := string(req.Respon)
                if msg := p.Json().GetValFromS(res, "message");msg == nil || msg != "0" {
-                       apilog.Base(1, "获取OnlineGoldRank").E("message", msg)
+                       apilog.L(`E: `,"message", msg)
                        return
                }
                if onlineNum := p.Json().GetValFromS(res, "data.onlineNum");onlineNum == nil {
-                       apilog.Base(1, "获取onlineNum").E("onlineNum", onlineNum)
+                       apilog.L(`E: `,"onlineNum", onlineNum)
                        return
                } else {
                        tmp_onlineNum := onlineNum.(float64)
                        if tmp_onlineNum == 0 {
-                               // apilog.Base(1, "获取tmp_onlineNum").E("tmp_onlineNum", tmp_onlineNum)
                                return
                        }
 
@@ -467,24 +464,21 @@ func (i *api) Get_OnlineGoldRank() {
                        c.Danmu_Main_mq.Push_tag(`c.Rev_add`,score)
 
                        if rank_list := p.Json().GetArrayFrom(p.Json().GetValFromS(res, "data.OnlineRankItem"), "userRank");rank_list == nil {
-                               apilog.Base(1, "获取 rank_list").E("rank_list", len(rank_list))
+                               apilog.L(`E: `,"rank_list", len(rank_list))
                                return
                        } else if len(rank_list) == 0 {
-                               // apilog.Base(1, "获取 rank_list").E("rank_list == tmp_onlineNum")
+                               // apilog.L(`E: `,"rank_list == tmp_onlineNum")
                                return
                        } else {
                                p.Sys().Timeoutf(1)
-                               // apilog.Base(1, "获取page").E(page, score)
                                self_loop(page+1)
                                return
                        }
                }
        }
-       // apilog.Base(1, "Get_OnlineGoldRank").E("start")
 
-       // apilog.Base(1, "获取score").E("score", self_loop(1))
        self_loop(1)
-       apilog.Base(1, "获取score").W("以往营收获取成功", fmt.Sprintf("%.2f", c.Rev))
+       apilog.Base("获取score").L(`W: `,"以往营收获取成功", fmt.Sprintf("%.2f", c.Rev))
        // c.Danmu_Main_mq.Push(c.Danmu_Main_mq_item{//传入消息队列
        //      Class:`c.Rev_add`,
        //      Data:self_loop(1),
@@ -494,10 +488,12 @@ func (i *api) Get_OnlineGoldRank() {
 
 func (i *api) Get_guardNum() {
        if i.Uid == 0 || c.Roomid == 0 {
-               apilog.Base(1, "Get_guardNum").E("i.Uid == 0 || c.Roomid == 0")
+               apilog.Base_add("Get_guardNum").L(`E: `,"i.Uid == 0 || c.Roomid == 0")
                return
        }
        if api_limit.TO() {return}//超额请求阻塞,超时将取消
+       apilog := apilog.Base_add(`获取舰长数`)
+       defer apilog.L(`T: `,"ok")
 
        req := p.Req()
        if err := req.Reqf(p.Rval{
@@ -518,20 +514,20 @@ func (i *api) Get_guardNum() {
                Timeout:3,
                Retry:2,
        });err != nil {
-               apilog.Base(1, "获取guardNum").E(err)
+               apilog.L(`E: `,err)
                return
        }
        res := string(req.Respon)
        if msg := p.Json().GetValFromS(res, "message");msg == nil || msg != "0" {
-               apilog.Base(1, "获取guardNum").E("message", msg)
+               apilog.L(`E: `,"message", msg)
                return
        }
        if num := p.Json().GetValFromS(res, "data.info.num");num == nil {
-               apilog.Base(1, "获取num").E("num", num)
+               apilog.L(`E: `,"num", num)
                return
        } else {
                c.GuardNum = int(num.(float64))
-               apilog.Base(1, "获取guardNum").W("舰长数获取成功", c.GuardNum)
+               apilog.L(`W: `,"舰长数获取成功", c.GuardNum)
        }
        return
 }
@@ -539,6 +535,8 @@ func (i *api) Get_guardNum() {
 func (i *api) Get_Version() {
        Roomid := strconv.Itoa(i.Roomid)
        if api_limit.TO() {return}//超额请求阻塞,超时将取消
+       apilog := apilog.Base_add(`获取客户版本`)
+       defer apilog.L(`T: `,"ok")
 
        var player_js_url string
        {//获取player_js_url
@@ -547,13 +545,13 @@ func (i *api) Get_Version() {
                })
 
                if r.Err != nil {
-                       apilog.Base(1, "Get_Version").E(r.Err)
+                       apilog.L(`E: `,r.Err)
                        return
                }
 
                r.S2(`<script src=`,`.js`)
                if r.Err != nil {
-                       apilog.Base(1, "Get_Version").E(r.Err)
+                       apilog.L(`E: `,r.Err)
                        return
                }
 
@@ -567,7 +565,7 @@ func (i *api) Get_Version() {
                        }
                }
                if player_js_url == `` {
-                       apilog.Base(1, "Get_Version").E(`no found player-loader js`)
+                       apilog.L(`E: `,`no found player-loader js`)
                        return
                }
        }
@@ -578,22 +576,24 @@ func (i *api) Get_Version() {
                })
 
                if r.Err != nil {
-                       apilog.Base(1, "Get_Version").E(r.Err)
+                       apilog.L(`E: `,r.Err)
                        return
                }
 
                r.S(`version={html5:{web:"`,`"`,0,0)
                if r.Err != nil {
-                       apilog.Base(1, "Get_Version").E(r.Err)
+                       apilog.L(`E: `,r.Err)
                        return
                }
                c.VERSION = r.RS[0]
-               apilog.W("api version", c.VERSION)
+               apilog.L(`W: `,"api version", c.VERSION)
        }
 }
 
 func Get_cookie() {
        if api_limit.TO() {return}//超额请求阻塞,超时将取消
+       apilog := apilog.Base_add(`获取Cookie`)
+       defer apilog.L(`T: `,"ok")
 
        var img_url string
        var oauth string
@@ -604,12 +604,12 @@ func Get_cookie() {
                        Timeout:10,
                        Retry:2,
                });e != nil {
-                       apilog.Base(1,`Get_cookie`).E(e)
+                       apilog.L(`E: `,e)
                        return
                }
                res := string(r.Respon)
                if v,ok := p.Json().GetValFromS(res, "status").(bool);!ok || !v {
-                       apilog.Base(1,`Get_cookie`).E(`getLoginUrl status failed!`)
+                       apilog.L(`E: `,`getLoginUrl status failed!`)
                        return
                } else {
                        if v,ok := p.Json().GetValFromS(res, "data.url").(string);ok {
@@ -620,19 +620,19 @@ func Get_cookie() {
                        }
                }
                if img_url == `` || oauth == `` {
-                       apilog.Base(1,`Get_cookie`).E(`img_url:`,img_url,` oauth:`,oauth)
+                       apilog.L(`E: `,`img_url:`,img_url,` oauth:`,oauth)
                        return
                }
        }
        var server *http.Server
        {//生成二维码
                if p.Checkfile().IsExist(`qr.png`) {
-                       apilog.Base(1,`Get_cookie`).E(`qr.png已存在`)
+                       apilog.L(`E: `,`qr.png已存在`)
                        return
                }
                qr.WriteFile(img_url,qr.Medium,256,`qr.png`)
                if !p.Checkfile().IsExist(`qr.png`) {
-                       apilog.Base(1,`Get_cookie`).E(`qr error`)
+                       apilog.L(`E: `,`qr error`)
                        return
                }
                go func(){//启动web
@@ -648,7 +648,7 @@ func Get_cookie() {
                                WriteTimeout: time.Second * 10,
                                Handler:      web,
                        }
-                       apilog.Base(1,`Get_cookie`).W(`打开链接扫码登录:`,`http://`+server.Addr+`/qr.png`)
+                       apilog.L(`W: `,`打开链接扫码登录:`,`http://`+server.Addr+`/qr.png`)
                        server.ListenAndServe()
                }()
        }
@@ -670,34 +670,34 @@ func Get_cookie() {
                                Timeout:10,
                                Retry:2,        
                        });e != nil {
-                               apilog.Base(1,`Get_cookie`).E(e)
+                               apilog.L(`E: `,e)
                                return
                        }
                        res := string(r.Respon)
                        if v,ok := p.Json().GetValFromS(res, "status").(bool);!ok {
-                               apilog.Base(1,`Get_cookie`).E(`getLoginInfo status false`)
+                               apilog.L(`E: `,`getLoginInfo status false`)
                                return
                        } else if !v {
                                if v,ok := p.Json().GetValFromS(res, "message").(string);ok {
-                                       apilog.Base(1,`Get_cookie`).W(`登录中`,v)
+                                       apilog.L(`W: `,`登录中`,v)
                                }
                                continue
                        } else {
-                               apilog.Base(1,`Get_cookie`).W(`登录,并保存了cookie`)
+                               apilog.L(`W: `,`登录,并保存了cookie`)
                                if v := r.Response.Cookies();len(v) == 0 {
-                                       apilog.Base(1,`Get_cookie`).E(`getLoginInfo cookies len == 0`)
+                                       apilog.L(`E: `,`getLoginInfo cookies len == 0`)
                                        return
                                } else {
                                        cookie = p.Map_2_Cookies_String(p.Cookies_List_2_Map(v))//cookie to string
                                }
                                if cookie == `` {
-                                       apilog.Base(1,`Get_cookie`).E(`getLoginInfo cookies ""`)
+                                       apilog.L(`E: `,`getLoginInfo cookies ""`)
                                        return
                                } else {break}
                        }
                }
                if max_try <= 0 {
-                       apilog.Base(1,`Get_cookie`).W(`登录取消`)
+                       apilog.L(`W: `,`登录取消`)
                        return
                }
        }
@@ -713,7 +713,7 @@ func Get_cookie() {
        }
        {//关闭web
                if err := server.Shutdown(context.Background()); err != nil {
-                       apilog.Base(1,`Get_cookie`).E("HTTP server Shutdown:", err.Error())
+                       apilog.L(`E: `,"HTTP server Shutdown:", err.Error())
                }
                if p.Checkfile().IsExist(`qr.png`) {
                        os.RemoveAll(`qr.png`)
@@ -725,6 +725,8 @@ func Get_cookie() {
 func (i *api) Switch_FansMedal() {
        if c.Cookie == `` {return}
        if api_limit.TO() {return}//超额请求阻塞,超时将取消
+       apilog := apilog.Base_add(`切换粉丝牌`)
+       defer apilog.L(`T: `,"ok")
 
        {//验证是否本直播间牌子
                r := p.Req()
@@ -736,7 +738,7 @@ func (i *api) Switch_FansMedal() {
                        Timeout:10,
                        Retry:2,
                });e != nil {
-                       apilog.Base(1,`Switch_FansMedal`).E(e)
+                       apilog.L(`E: `,e)
                        return
                }
                res := string(r.Respon)
@@ -755,12 +757,12 @@ func (i *api) Switch_FansMedal() {
                        Timeout:10,
                        Retry:2,
                });e != nil {
-                       apilog.Base(1,`Switch_FansMedal`).E(e)
+                       apilog.L(`E: `,e)
                        return
                }
                res := string(r.Respon)
                if v,ok := p.Json().GetValFromS(res, "code").(float64);!ok || v != 0 {
-                       apilog.Base(1,`Switch_FansMedal`).E(`Get_FansMedal get_list_in_room code`, v)
+                       apilog.L(`E: `,`Get_FansMedal get_list_in_room code`, v)
                        return
                } else {
                        if v,ok := p.Json().GetValFromS(res, "data").([]interface{});ok{
@@ -769,7 +771,7 @@ func (i *api) Switch_FansMedal() {
                                                continue
                                        } else {
                                                if tmp_medal_id,ok := p.Json().GetValFrom(item, "medal_id").(float64);!ok {
-                                                       apilog.Base(1,`Switch_FansMedal`).E(`medal_id error`)
+                                                       apilog.L(`E: `,`medal_id error`)
                                                        return
                                                } else {
                                                        medal_id = int(tmp_medal_id)
@@ -778,7 +780,7 @@ func (i *api) Switch_FansMedal() {
                                        }
                                }
                        } else {
-                               apilog.Base(1,`Switch_FansMedal`).E(`data error`)
+                               apilog.L(`E: `,`data error`)
                                return
                        }
                }
@@ -790,7 +792,7 @@ func (i *api) Switch_FansMedal() {
        {//生成佩戴信息
                var csrf string
                if i := strings.Index(c.Cookie, "bili_jct="); i == -1 {
-                       apilog.Base(1,`Switch_FansMedal`).E("Cookie错误,无bili_jct=")
+                       apilog.L(`E: `,"Cookie错误,无bili_jct=")
                        return
                } else {
                        if d := strings.Index(c.Cookie[i + 9:], ";"); d == -1 {
@@ -820,18 +822,18 @@ func (i *api) Switch_FansMedal() {
                        Timeout:10,
                        Retry:2,
                });e != nil {
-                       apilog.Base(1,`Switch_FansMedal`).E(e)
+                       apilog.L(`E: `,e)
                        return
                }
                res := string(r.Respon)
                if v,ok := p.Json().GetValFromS(res, "code").(float64);ok && v == 0 {
-                       apilog.Base(1,`Switch_FansMedal`).W(`自动切换粉丝牌`)
+                       apilog.L(`W: `,`自动切换粉丝牌`)
                        return
                }
                if v,ok := p.Json().GetValFromS(res, "message").(string);ok {
-                       apilog.Base(1,`Switch_FansMedal`).E(`Get_FansMedal wear message`, v)
+                       apilog.L(`E: `,`Get_FansMedal wear message`, v)
                } else {
-                       apilog.Base(1,`Switch_FansMedal`).E(`Get_FansMedal wear message nil`)
+                       apilog.L(`E: `,`Get_FansMedal wear message nil`)
                }
        }
 }
\ No newline at end of file
index b2674eb8ea9850d2f71b8099efb0a5834a0c2b45..641a53775d1467f30dbb86760c891ec9c7ff3b94 100644 (file)
@@ -116,12 +116,12 @@ var (
 func ShowRevf(){
        if!IsOn("ShowRev") {return}
        if ShowRev_start {
-               p.Logf().New().Open("danmu.log").Base(1, "Rev").I(fmt.Sprintf("营收 ¥%.2f",c.Rev))
+               c.Log.Base(`功能`).L(`I: `, fmt.Sprintf("营收 ¥%.2f",c.Rev))
                return
        }
        ShowRev_start = true
        for {
-               p.Logf().New().Open("danmu.log").Base(1, "Rev").I(fmt.Sprintf("营收 ¥%.2f",c.Rev))
+               c.Log.Base(`功能`).L(`I: `, fmt.Sprintf("营收 ¥%.2f",c.Rev))
                for c.Rev == ShowRev_old {p.Sys().Timeoutf(60)}
                ShowRev_old = c.Rev
        }
index fb215c344155562f23a17e990f3826bb54e3a72a..e4dde349d2b1e707e2903115f270ccf1647f50f1 100644 (file)
@@ -1,7 +1,6 @@
 package reply
 
 import (
-       p "github.com/qydysky/part"
        F "github.com/qydysky/bili_danmu/F"
 )
 
@@ -9,9 +8,6 @@ import (
        HeartBeat数据分派
 */
 
-var heartlog = p.Logf().New().Base(-1, "Heart.go").Open("danmu.log").Fileonly(true)
-
-//HeartBeat类型处理方法map
 var Heart_map = map[string]func(replyF, int) {
        "heartbeat":replyF.heartbeat,//人气
 }
index 52b24d3a722a55c266c77d84c7cb6c895aafbb99..f9bb7d4b7808e834680809c5c6d8ec4a38c2adc0 100644 (file)
@@ -2,6 +2,7 @@ package reply
 
 import (
        p "github.com/qydysky/part"
+       c "github.com/qydysky/bili_danmu/CV"
        s "github.com/qydysky/part/buf"
 )
 
@@ -9,7 +10,7 @@ import (
        数据为WS_OP_MESSAGE类型的数据分派
 */
 
-var msglog = p.Logf().New().Base(-1, "Msg.go").Open("danmu.log").Level(1)
+var msglog = c.Log.Base(`Msg`)
 
 //Msg类型数据处理方法map
 var Msg_map = map[string]func(replyF, string) {
@@ -94,7 +95,7 @@ func init(){
 func Msg(b []byte) {
        s := string(b)
        if cmd := p.Json().GetValFromS(s, "cmd");cmd == nil {
-               msglog.E("cmd", s)
+               msglog.L(`E: `,"cmd", s)
                return
        } else {
                var f replyF
index b520a8dfdf7d819ba9ae18c88f5ebe6fc10b309e..c91f6e317847da3b8bc229ad6de1598c71f5dacb 100644 (file)
@@ -14,37 +14,36 @@ import (
        c "github.com/qydysky/bili_danmu/CV"
 )
 
-var replylog = p.Logf().New().Open("danmu.log").Base(-1, "Reply.go")
+var reply_log = c.Log.Base(`Reply`)
 
 //返回数据分派
 //传入接受到的ws数据
 //判断进行解压,并对每个json对象进行分派
 func Reply(b []byte) {
-       replylog.Base(-1, "返回分派")
-       defer replylog.Base(0)
+       reply_log := reply_log.Base_add(`返回分派`)
 
        head := F.HeadChe(b[:c.WS_PACKAGE_HEADER_TOTAL_LENGTH])
-       if int(head.PackL) > len(b) {replylog.E("包缺损");return}
+       if int(head.PackL) > len(b) {reply_log.L(`E: `,"包缺损");return}
 
        if head.BodyV == c.WS_BODY_PROTOCOL_VERSION_DEFLATE {
                readc, err := zlib.NewReader(bytes.NewReader(b[16:]))
-               if err != nil {replylog.E("解压错误");return}
+               if err != nil {reply_log.L(`E: `,"解压错误");return}
                defer readc.Close()
                
                buf := bytes.NewBuffer(nil)
-               if _, err := buf.ReadFrom(readc);err != nil {replylog.E("解压错误");return}
+               if _, err := buf.ReadFrom(readc);err != nil {reply_log.L(`E: `,"解压错误");return}
                b = buf.Bytes()
        }
 
        for len(b) != 0 {
                head := F.HeadChe(b[:c.WS_PACKAGE_HEADER_TOTAL_LENGTH])
-               if int(head.PackL) > len(b) {replylog.E("包缺损");return}
+               if int(head.PackL) > len(b) {reply_log.L(`E: `,"包缺损");return}
                
                contain := b[c.WS_PACKAGE_HEADER_TOTAL_LENGTH:head.PackL]
                switch head.OpeaT {
                case c.WS_OP_MESSAGE:Msg(contain)
                case c.WS_OP_HEARTBEAT_REPLY:Heart(contain)
-               default :replylog.W("unknow reply", contain)
+               default :reply_log.L(`W: `,"unknow reply", contain)
                }
 
                b = b[head.PackL:]
@@ -57,7 +56,7 @@ type replyF struct {}
 
 //默认未识别Msg
 func (replyF) defaultMsg(s string){
-       msglog.Base(1, "Unknow").E(s)
+       msglog.Base_add("Unknow").L(`E: `, s)
 }
 
 //msg-直播间进入信息,此处用来提示关注
@@ -73,7 +72,7 @@ func (replyF) interact_word(s string){
                        })
                }
                Gui_show(v + `关注了直播间`,`0follow`)
-               msglog.Base(1, "房").Fileonly(true).I(v + `关注了直播间`).Fileonly(false)
+               msglog.Base_add("房").Log_show_control(false).L(`I`, v + `关注了直播间`)
        }
 }
 
@@ -91,7 +90,7 @@ func (replyF) anchor_lot_start(s string){
        fmt.Println(sh...)
        Gui_show(Itos(sh),`0tianxuan`)
 
-       msglog.Base(1, "房").Fileonly(true).I(sh...).Fileonly(false)
+       msglog.Base_add("房").Log_show_control(false).L(`I`, sh...)
 }
 
 //Msg-天选之人结束
@@ -124,7 +123,7 @@ func (replyF) anchor_lot_award(s string){
        fmt.Println(sh...)
        Gui_show(Itos(sh),`0tianxuan`)
 
-       msglog.Base(1, "房").Fileonly(true).I(sh...).Fileonly(false)
+       msglog.Base_add("房").Log_show_control(false).L(`I`, sh...)
 }
 
 //msg-通常是大航海购买续费
@@ -152,7 +151,7 @@ func (replyF) user_toast_msg(s string){
                case 3:
                        sh = append(sh, "自动续费了")
                default:
-                       msglog.W(s)
+                       msglog.L(`W`, s)
                        sh = append(sh, op_type)
                }
        }
@@ -187,32 +186,27 @@ func (replyF) user_toast_msg(s string){
        Gui_show(Itos(sh), "0buyguide")
        // Gui_show("====\n")
 
-       msglog.Base(1, "礼").Fileonly(true).I(sh_log...).Fileonly(false)
+       msglog.Base_add("礼").Log_show_control(false).L(`I: `,sh_log...)
 }
 
 //HeartBeat-心跳用来传递人气值
 func (replyF) heartbeat(s int){
        c.Danmu_Main_mq.Push_tag(`c.Renqi`,s)//使用连续付费的新舰长无法区分,刷新舰长数
        if s == 1 {return}//人气为1,不输出
-       heartlog.I("当前人气", s)
+       reply_log.Base_add(`人气`).L(`I: `,"当前人气", s)
 }
 
 //Msg-房间特殊活动
 func (replyF) win_activity(s string){
-       msglog.Fileonly(true)
-       defer msglog.Fileonly(false)
-
        title := p.Json().GetValFromS(s, "data.title");
 
        fmt.Println("活动", title, "已开启")
-       msglog.Base(1, "房").I("活动", title, "已开启")
+       msglog.Base_add("房").Log_show_control(false).L(`I: `,"活动", title, "已开启")
 }
 
 //Msg-特殊礼物,当前仅观察到节奏风暴
 func (replyF) special_gift(s string){
-       msglog.Fileonly(true)
-       defer msglog.Fileonly(false)
-
+       
        content := p.Json().GetValFromS(s, "data.39.content");
        action := p.Json().GetValFromS(s, "data.39.action");
 
@@ -235,7 +229,7 @@ func (replyF) special_gift(s string){
        Gui_show(Itos(sh), "0jiezou")
        // Gui_show("====\n")
 
-       msglog.Base(1, "礼").I(sh...)
+       msglog.Base_add("礼").Log_show_control(false).L(`I:`, sh...)
 
 }
 
@@ -263,7 +257,7 @@ func (replyF) guard_buy(s string){
        fmt.Println("\n====")
        fmt.Println(sh...)
        fmt.Print("====\n\n")
-       msglog.Base(1, "礼").Fileonly(true).I(sh_log...).Fileonly(false)
+       msglog.Base_add("礼").Log_show_control(false).L(`I:`, sh_log...)
 
 }
 
@@ -283,7 +277,7 @@ func (replyF) room_change(s string){
        }
        Gui_show(Itos(sh), "0room")
 
-       msglog.Base(1, "房").I(sh...)
+       msglog.Base_add("房").L(`I:`, sh...)
 }
 
 //Msg-大航海欢迎信息
@@ -316,7 +310,7 @@ func (replyF) welcome_guard(s string){
        fmt.Println(sh...)
        Gui_show(Itos(append([]interface{}{">>> "}, sh...)), img)
 
-       msglog.Base(1, "房").Fileonly(true).I(sh...).Fileonly(false)
+       msglog.Base_add("房").Log_show_control(false).L(`I:`, sh...)
 }
 
 //Msg-礼物处理,对于小于30人民币的礼物不显示
@@ -353,10 +347,11 @@ func (replyF) send_gift(s string){
        }
 
        if len(sh) == 0 {return}
-       msglog.Base(1, "礼").Fileonly(true).I(sh_log...).Fileonly(false)
+       msglog := msglog.Base_add("礼")
+       msglog.Log_show_control(false).L(`I:`, sh_log...)
 
        //小于3万金瓜子
-       if allprice < 30 {msglog.T(sh...);return}
+       if allprice < 30 {msglog.L(`T:`, sh...);return}
        {//语言tts
                c.Danmu_Main_mq.Push_tag(`tts`,Danmu_mq_t{//传入消息队列
                        uid:`0gift`,
@@ -377,25 +372,22 @@ func (replyF) send_gift(s string){
 
 //Msg-房间封禁信息
 func (replyF) room_block_msg(s string) {
-       msglog.Fileonly(true)
-       defer msglog.Fileonly(false)
-
        if uname := p.Json().GetValFromS(s, "uname");uname == nil {
-               msglog.E("uname", uname)
+               msglog.L(`E:`, "uname", uname)
                return
        } else {
                Gui_show(Itos([]interface{}{"用户", uname, "已被封禁"}), "0room")
                fmt.Println("用户", uname, "已被封禁")
-               msglog.Base(1, "封").I("用户", uname, "已被封禁")
+               msglog.Base_add("封").Log_show_control(false).L(`I:`, "用户", uname, "已被封禁")
        }
 }
 
 //Msg-房间准备信息,通常出现在下播而不出现在开播
 func (replyF) preparing(s string) {
-       msglog.Base(1, "房")
+       msglog := msglog.Base_add("房")
 
        if roomid := p.Json().GetValFromS(s, "roomid");roomid == nil {
-               msglog.E("roomid", roomid)
+               msglog.L(`E:`, "roomid", roomid)
                return
        } else {
                {//附加功能 obs结束 saveflv结束
@@ -407,20 +399,20 @@ func (replyF) preparing(s string) {
                }
                if p.Sys().Type(roomid) == "float64" {
                        Gui_show(Itos([]interface{}{"房间", roomid, "下播了"}), "0room")
-                       msglog.I("房间", int(roomid.(float64)), "下播了")
+                       msglog.L(`I:`, "房间", int(roomid.(float64)), "下播了")
                        return
                }
                Gui_show(Itos([]interface{}{"房间", roomid, "下播了"}), "0room")
-               msglog.I("房间", roomid, "下播了")
+               msglog.L(`I:`, "房间", roomid, "下播了")
        }
 }
 
 //Msg-房间开播信息
 func (replyF) live(s string) {
-       msglog.Base(1, "房")
+       msglog := msglog.Base_add("房")
 
        if roomid := p.Json().GetValFromS(s, "roomid");roomid == nil {
-               msglog.E("roomid", roomid)
+               msglog.L(`E:`, "roomid", roomid)
                return
        } else {
                {//附加功能 obs录播
@@ -435,11 +427,11 @@ func (replyF) live(s string) {
                }
                if p.Sys().Type(roomid) == "float64" {
                        Gui_show(Itos([]interface{}{"房间", roomid, "开播了"}), "0room")
-                       msglog.I("房间", int(roomid.(float64)), "开播了")
+                       msglog.L(`I:`, "房间", int(roomid.(float64)), "开播了")
                        return
                }
                Gui_show(Itos([]interface{}{"房间", roomid, "开播了"}), "0room")
-               msglog.I("房间", roomid, "开播了")
+               msglog.L(`I:`, "房间", roomid, "开播了")
        }
 }
 
@@ -498,34 +490,32 @@ func (replyF) super_chat_message(s string){
                // Gui_show("====\n")
                Gui_show(Itos(sh), "0superchat")
        }
-       msglog.Base(1, "礼").Fileonly(true).I(logg...).Fileonly(false)
+       msglog.Base_add("礼").Log_show_control(false).L(`I:`, logg...)
 }
 
 //Msg-分区排行
 func (replyF) panel(s string){
-       msglog.Fileonly(true).Base(1, "房")
-       defer msglog.Fileonly(false)
+       msglog := msglog.Base_add("房").Log_show_control(false)
 
        if note := p.Json().GetValFromS(s, "data.note");note == nil {
-               msglog.E("note", note)
+               msglog.L(`E:`, "note", note)
                return
        } else {
                if v,ok := note.(string);ok{c.Note = v}
                fmt.Println("排行", note)
-               msglog.I("排行", note)
+               msglog.L(`I:`, "排行", note)
        }
 }
 
 //Msg-进入特效,大多为大航海进入,信息少,使用welcome_guard替代
 func (replyF) entry_effect(s string){
-       msglog.Fileonly(true).Base(-1, "房")
-       defer msglog.Base(0).Fileonly(false)
+       msglog := msglog.Base_add("房").Log_show_control(false)
 
        if copy_writing := p.Json().GetValFromS(s, "data.copy_writing");copy_writing == nil {
-               msglog.E("copy_writing", copy_writing)
+               msglog.L(`E:`, "copy_writing", copy_writing)
                return
        } else {
-               msglog.I(copy_writing)
+               msglog.L(`I:`, copy_writing)
                fmt.Println(copy_writing)
        }
 
@@ -533,14 +523,14 @@ func (replyF) entry_effect(s string){
 
 //Msg-房间禁言
 func (replyF) roomsilent(s string){
-       msglog.Base(1, "房")
+       msglog := msglog.Base_add("房")
 
        if level := p.Json().GetValFromS(s, "data.level");level == nil {
-               msglog.E("level", level)
+               msglog.L(`E:`, "level", level)
                return
        } else {
-               if level.(float64) == 0 {msglog.I("主播关闭了禁言")}
-               msglog.I("主播开启了等级禁言:", level)
+               if level.(float64) == 0 {msglog.L(`I:`, "主播关闭了禁言")}
+               msglog.L(`I:`, "主播开启了等级禁言:", level)
        }
 }
 
@@ -558,13 +548,13 @@ func (replyF) roominfo(s string){
                sh = append(sh, "粉丝团人数:", fans_club)
        }
 
-       if len(sh) != 0 {msglog.Base(1, "粉").I(sh...)}
+       if len(sh) != 0 {msglog.Base_add("粉").L(`I:`, sh...)}
 }
 
 //Msg-弹幕处理
 func (replyF) danmu(s string) {
        if info := p.Json().GetValFromS(s, "info");info == nil {
-               msglog.E("info", info)
+               msglog.L(`E:`, "info", info)
                return
        } else {
                infob := info.([]interface{})
@@ -572,19 +562,18 @@ func (replyF) danmu(s string) {
                auth := infob[2].([]interface{})[1]
                uid := strconv.Itoa(int(infob[2].([]interface{})[0].(float64)))
 
-               msglog.Fileonly(true)
-               defer msglog.Fileonly(false)
+               msglog := msglog.Log_show_control(false)
 
                {//附加功能 弹幕机 封禁 弹幕合并
                        Danmujif(msg)
                        if Autobanf(msg) {
                                Gui_show(Itos([]interface{}{"风险", auth, ":", msg}))
                                fmt.Println("风险", auth, ":", msg)
-                               msglog.Base(1, "风险").I(auth, ":", msg)
+                               msglog.Base_add("风险").L(`I:`, auth, ":", msg)
                                return
                        }
                        if i := Autoskipf(msg, 50, 15); i > 0 {
-                               msglog.I(auth, ":", msg)
+                               msglog.L(`I:`, auth, ":", msg)
                                return
                        }
                }
@@ -597,7 +586,7 @@ func (replyF) danmu(s string) {
 //需要cookie
 func Msg_senddanmu(msg string){
        if c.Cookie == "" || c.Roomid == 0 {
-               msglog.I(`c.Cookie == "" || c.Roomid == 0`)
+               msglog.L(`I:`, `c.Cookie == "" || c.Roomid == 0`)
                return
        }
        S.Danmu_s(msg, c.Cookie, c.Roomid)
@@ -609,11 +598,11 @@ func Msg_showdanmu(auth interface{}, m ...string) {
        msg := m[0]
        {//附加功能 更少弹幕
                if Lessdanmuf(msg, 20) > 0.7 {//与前20条弹幕重复的字数占比度>0.7的屏蔽
-                       if auth != nil {msglog.I(auth, ":", msg)}
+                       if auth != nil {msglog.L(`I:`, auth, ":", msg)}
                        return
                }
                if _msg := Shortdanmuf(msg); _msg == "" {
-                       if auth != nil {msglog.I(auth, ":", msg)}
+                       if auth != nil {msglog.L(`I:`, auth, ":", msg)}
                        return
                } else {msg = _msg}
                Assf(msg)//ass
@@ -632,7 +621,7 @@ func Msg_showdanmu(auth interface{}, m ...string) {
                }
        }
        fmt.Println(msg)
-       if auth != nil {msglog.I(auth, ":", msg)}
+       if auth != nil {msglog.L(`I:`, auth, ":", msg)}
 }
 
 type Danmu_mq_t struct {
index f5ca8d4b377c53ab8bf2000a1d530de0ac34b168..139d28460322c2a5fdf5da02af44e1ecf288d3b2 100644 (file)
@@ -17,12 +17,8 @@ import (
        F "github.com/qydysky/bili_danmu/F"
 )
 
-var danmulog = p.Logf().New().Open("danmu.log").Base(-1, "bili_danmu.go").Level(c.LogLevel)
-
 func Demo(roomid ...int) {
-
-       danmulog.Base(-1, "测试")
-       defer danmulog.Base(0)
+       var danmulog = c.Log.Base(`bilidanmu Demo`)
        
        //ctrl+c退出
        interrupt := make(chan os.Signal, 1)
@@ -48,7 +44,7 @@ func Demo(roomid ...int) {
                                fmt.Printf("输入房间号: ")
                                _, err := fmt.Scanln(&room)
                                if err != nil {
-                                       danmulog.E("输入错误", err)
+                                       danmulog.L(`E: `, "输入错误", err)
                                        return
                                }
                        } else {
@@ -100,14 +96,14 @@ func Demo(roomid ...int) {
                                        if tmp_uid,e := g.SS(f,`DedeUserID=`,`;`,0,0);e == nil {
                                                if v,e := strconv.Atoi(tmp_uid);e == nil {
                                                        c.Uid = v
-                                               } else {danmulog.E(e)}
-                                       } else {danmulog.E(e)}
+                                               } else {danmulog.L(`E: `, e)}
+                                       } else {danmulog.L(`E: `, e)}
                                } else {
-                                       danmulog.I("未检测到cookie.txt,如果需要登录请在本机打开以下网址扫码登录,不需要请忽略")
+                                       danmulog.L(`I: `, "未检测到cookie.txt,如果需要登录请在本机打开以下网址扫码登录,不需要请忽略")
                                        go func(){//获取cookie
                                                F.Get_cookie()
                                                if c.Cookie != `` {
-                                                       danmulog.I("你已登录,刷新房间!")
+                                                       danmulog.L(`I: `,"你已登录,刷新房间!")
                                                        //刷新
                                                        c.Danmu_Main_mq.Push_tag(`change_room`,nil)
                                                }
@@ -125,10 +121,10 @@ func Demo(roomid ...int) {
                        //切换粉丝牌,只在cookie存在时启用
                        api.Switch_FansMedal()
                        if len(api.Url) == 0 || api.Roomid == 0 || api.Token == "" || api.Uid == 0 || api.Locked {
-                               danmulog.E("some err")
+                               danmulog.L(`E: `,"some err")
                                return
                        }
-                       danmulog.I("连接到房间", c.Roomid)
+                       danmulog.L(`I: `,"连接到房间", c.Roomid)
 
                        //对每个弹幕服务器尝试
                        for _, v := range api.Url {
@@ -137,8 +133,8 @@ func Demo(roomid ...int) {
                                ws_c := ws.New_client(ws.Client{
                                        Url:v,
                                        TO:35 * 1000,
-                                       Func_abort_close:func(){danmulog.I(`服务器连接中断`)},
-                                       Func_normal_close:func(){danmulog.I(`服务器连接关闭`)},
+                                       Func_abort_close:func(){danmulog.L(`I: `,`服务器连接中断`)},
+                                       Func_normal_close:func(){danmulog.L(`I: `,`服务器连接关闭`)},
                                        Header: map[string]string{
                                                `Cookie`:c.Cookie,
                                                `Host`: u.Hostname(),
@@ -151,30 +147,30 @@ func Demo(roomid ...int) {
                                        },
                                }).Handle()
                                if ws_c.Isclose() {
-                                       danmulog.E("连接错误", ws_c.Error())
+                                       danmulog.L(`E: `,"连接错误", ws_c.Error())
                                        continue
                                }
 
                                //SendChan 传入发送[]byte
                                //RecvChan 接收[]byte
-                               danmulog.I("连接", v)
+                               danmulog.L(`I: `,"连接", v)
                                ws_c.SendChan <- F.HelloGen(c.Roomid, api.Token)
                                if F.HelloChe(<- ws_c.RecvChan) {
-                                       danmulog.I("已连接到房间", c.Uname, `(`, c.Roomid, `)`)
+                                       danmulog.L(`I: `,"已连接到房间", c.Uname, `(`, c.Roomid, `)`)
                                        reply.Gui_show(`进入直播间: `+c.Uname+` (`+strconv.Itoa(c.Roomid)+`)`, `0room`)
                                        if c.Title != `` {
-                                               danmulog.I(c.Title)
+                                               danmulog.L(`I: `,c.Title)
                                                reply.Gui_show(`房间标题: `+c.Title, `0room`)
                                        }
                                        //30s获取一次人气
                                        go func(){
                                                p.Sys().MTimeoutf(500)//500ms
-                                               danmulog.I("获取人气")
+                                               danmulog.L(`I: `,"获取人气")
                                                go func(){
                                                        heartbeatmsg, heartinterval := F.Heartbeat()
                                                        for !ws_c.Isclose() {
                                                                ws_c.SendChan <- heartbeatmsg
-                                                               time.Sleep(time.Millisecond*time.Duration(heartinterval))
+                                                               time.Sleep(time.Millisecond*time.Duration(heartinterval*1000))
                                                        }
                                                }()
 
@@ -218,12 +214,12 @@ func Demo(roomid ...int) {
                                                }
                                        case <- interrupt:
                                                ws_c.Close()
-                                               danmulog.I("停止,等待服务器断开连接")
+                                               danmulog.L(`I: `,"停止,等待服务器断开连接")
                                                break_sign = true
                                                exit_sign = true
                                        case <- change_room_chan:
                                                ws_c.Close()
-                                               danmulog.I("停止,等待服务器断开连接")
+                                               danmulog.L(`I: `,"停止,等待服务器断开连接")
                                                break_sign = true
                                        }
 
@@ -239,7 +235,7 @@ func Demo(roomid ...int) {
                {//附加功能 直播流
                        reply.Saveflv_wait()
                }
-               danmulog.I("结束退出")
+               danmulog.L(`I: `,"结束退出")
        }
 }
 
index b26931289f3718c6c6e96c1d7db70bf4dac61df1..ddf1b9903a6d3679d6957b3160c759c07b48791d 100644 (file)
@@ -10,7 +10,7 @@ require (
        github.com/miekg/dns v1.1.35 // indirect
        github.com/mitchellh/mapstructure v1.4.0 // indirect
        github.com/qydysky/bili_danmu v0.5.4
-       github.com/qydysky/part v0.3.5-0.20201222123333-27d31033ffec // indirect
+       github.com/qydysky/part v0.3.5-0.20201225142344-1a031040ceff // indirect
        github.com/shirou/gopsutil v3.20.11+incompatible // indirect
        github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
        golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 // indirect
index 87ce0a7eb12be138f1fee2f89c39f3eaea2c977c..97d2bf629d77a8592547bd67d575164102bec9e0 100644 (file)
@@ -80,6 +80,12 @@ github.com/qydysky/part v0.3.5-0.20201222075205-70243aca6682 h1:k7YM2PUXxW96cIAl
 github.com/qydysky/part v0.3.5-0.20201222075205-70243aca6682/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0=
 github.com/qydysky/part v0.3.5-0.20201222123333-27d31033ffec h1:Mwrebha+zOcwYRxroUJhWBMgopVoqIyfOEYOeq6idtA=
 github.com/qydysky/part v0.3.5-0.20201222123333-27d31033ffec/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0=
+github.com/qydysky/part v0.3.5-0.20201225033911-e62acc74534d h1:72xlB994UoGTCcKksUlZlez67SVRfOhB9DiNfBld6dE=
+github.com/qydysky/part v0.3.5-0.20201225033911-e62acc74534d/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0=
+github.com/qydysky/part v0.3.5-0.20201225074608-a39a85b8977d h1:AzdeFwLFNkfgQ/3ZJfpJSWgn6Eru1qlltOj3zLtmKJs=
+github.com/qydysky/part v0.3.5-0.20201225074608-a39a85b8977d/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0=
+github.com/qydysky/part v0.3.5-0.20201225142344-1a031040ceff h1:KB3WnVkhUMg3WONvUkt/MjRywHRWGORt9i0E2wrGJtE=
+github.com/qydysky/part v0.3.5-0.20201225142344-1a031040ceff/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0=
 github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad h1:Jtzf509lQrkUMGTV0Sc6IDCAiR1VrBcHrIban7hpye4=
 github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad/go.mod h1:w32TkJNVtTJd4LOS09cq+4uYG6itcN2vsqw+slp44Rg=
 github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba h1:1ew9dRpc0Rux0WkWeT/4AE15ynYWmL2D7onJEJIFOB8=