How to use push method of log Package

Best K6 code snippet using log.push

push.go

Source:push.go Github

copy

Full Screen

...7 "github.com/json-iterator/go"8 "go-common/app/service/bbq/notice-service/api/v1"9 "go-common/app/service/bbq/notice-service/internal/conf"10 "go-common/app/service/bbq/notice-service/internal/model"11 push "go-common/app/service/bbq/push/api/grpc/v1"12 "go-common/library/log"13 "go-common/library/net/trace"14)15func (s *Service) needPush(c context.Context, notice *v1.NoticeBase) bool {16 // TODO: 获取粉丝数量17 F, err := s.dao.FetchUserFansNum(c, notice.Mid)18 if err != nil {19 log.Errorv(c, log.KV("log", "FetchUserFansNum error"), log.KV("error", err))20 }21 var strategyMap *map[string]*conf.PushStrategy22 if F <= 1000 {23 strategyMap = &s.c.L1PushStrategy24 } else {25 strategyMap = &s.c.L2PushStrategy26 }27 var strategy *conf.PushStrategy28 switch notice.NoticeType {29 case model.NoticeTypeLike:30 strategy = (*strategyMap)["like"]31 case model.NoticeTypeComment:32 strategy = (*strategyMap)["comment"]33 case model.NoticeTypeFan:34 strategy = (*strategyMap)["follow"]35 case model.NoticeTypeSysMsg:36 strategy = (*strategyMap)["sysmsg"]37 }38 // A = -1 and B = -1 无限制39 if strategy.A == -1 && strategy.B == -1 {40 return true41 }42 // A = -1 触发无限制43 if strategy.A != -1 {44 count, err := s.dao.IncrHourPushAction(c, notice.Mid, notice.NoticeType, strategy.T)45 if count < strategy.A || err != nil {46 return false47 }48 }49 // B = -1 全天无限制50 if strategy.B != -1 {51 count, err := s.dao.IncrDailyPushCount(c, notice.Mid)52 if count > strategy.B || err != nil {53 return false54 }55 }56 // 推送触发条件:T小时内触发A次且当日推送次数小于等于B57 return true58}59func (s *Service) pushNotification(c context.Context, nid int64, notice *v1.NoticeBase) (err error) {60 // redis push action_mid61 err = s.dao.SetPushActionMid(c, notice.Mid, notice.ActionMid, notice.NoticeType)62 if err != nil {63 log.Errorv(c, log.KV("log", "SetPushActionMid error"), log.KV("error", err))64 return65 }66 if !s.needPush(c, notice) {67 return68 }69 var title, content string70 switch notice.NoticeType {71 case model.NoticeTypeLike:72 if notice.BizType == model.NoticeBizTypeSv {73 // 视频点赞74 content = model.PushMsgVideoLike75 } else if notice.BizType == model.NoticeBizTypeComment {76 // 评论点赞77 content = model.PushMsgCommentLike78 }79 case model.NoticeTypeComment:80 if notice.BizType == model.NoticeBizTypeSv {81 // 视频评论82 content = model.PushMsgVideoComment83 } else if notice.BizType == model.NoticeBizTypeComment {84 // 评论回复85 content = model.PushMsgCommentReply86 }87 case model.NoticeTypeFan:88 // 关注89 content = model.PushMsgFollow90 case model.NoticeTypeSysMsg:91 // 系统消息92 // return s.pushMessage(c, nid, notice)93 if notice.BizType == model.NoticeBizTypeCmsReview {94 // 审核类通知不推送95 return96 }97 content = notice.Text98 }99 // 填写内容详情100 midList, err := s.dao.GetPushActionMid(c, notice.Mid, notice.NoticeType)101 if err != nil || len(midList) == 0 {102 log.Errorv(c, log.KV("log", "GetPushActionMid error"), log.KV("error", err))103 return104 }105 nameList, err := s.dao.GetUserName(c, midList, 2)106 if err != nil {107 log.Errorv(c, log.KV("log", "GetUserName error"), log.KV("error", err))108 return109 }110 unreadInfo, err := s.dao.GetUnreadInfo(c, notice.Mid)111 if err != nil {112 log.Errorv(c, log.KV("log", "GetUnreadInfo error"), log.KV("error", err))113 return114 }115 if len(nameList) > 1 {116 tmp := fmt.Sprintf("等%d人", unreadInfo[int(notice.NoticeType)-1].UnreadNum)117 content = fmt.Sprintf(content, strings.Join(nameList, ","), tmp)118 } else {119 content = fmt.Sprintf(content, strings.Join(nameList, ","), "")120 }121 schema := fmt.Sprintf(model.PushSchemaNotice, notice.NoticeType)122 ext := make(map[string]string)123 ext["scheme"] = schema124 extStr, _ := jsoniter.Marshal(ext)125 dev, err := s.dao.FetchPushDev(c, notice.Mid)126 if err != nil {127 log.Errorv(c, log.KV("log", "FetchPushDev error"), log.KV("error", err))128 return129 }130 dev.SendNo = nid131 devs := []*push.Device{dev}132 body := &push.NotificationBody{133 Title: title,134 Content: content,135 Extra: string(extStr),136 }137 req := &push.NotificationRequest{138 Dev: devs,139 Body: body,140 }141 result, err := s.dao.PushNotice(c, req)142 if err != nil {143 log.Errorv(c, log.KV("log", "PushNotice error"), log.KV("error", err), log.KV("result", result))144 return145 }146 err = s.dao.ClearHourPushAction(c, notice.Mid, notice.NoticeType)147 if err != nil {148 log.Errorv(c, log.KV("log", "hour push action clear error"), log.KV("error", err), log.KV("notice_type", notice.NoticeType))149 }150 // 埋点151 tracer, _ := trace.FromContext(c)152 s.Infoc.Info(tracer, notice.Mid, notice.Buvid, nid, notice.NoticeType, notice.BizId, notice.BizType, time.Now().Unix(), result)153 return154}155// func (s *Service) pushMessage(c context.Context, nid int64, notice *v1.NoticeBase) (err error) {156// dev, err := s.dao.FetchPushDev(c, notice.Mid)157// if err != nil {158// return159// }160// dev.SendNo = nid161// devs := []*push.Device{dev}162// schema := fmt.Sprintf(model.PushSchemaNotice, notice.NoticeType)163// ext := make(map[string]string)164// ext["shcema"] = schema165// extStr, _ := jsoniter.Marshal(ext)166// body := &push.MessageBody{167// Title: notice.Title,168// Content: notice.Text,169// ContentType: "text",170// Extra: string(extStr),171// }172// req := &push.MessageRequest{173// Dev: devs,174// Body: body,175// }176// result, err := s.dao.PushMessage(c, req)177// if err != nil {178// log.Errorv(c, log.KV("log", "PushMessage error"), log.KV("error", err), log.KV("result", result))179// return180// }181// err = s.dao.ClearHourPushAction(c, notice.Mid, notice.NoticeType)182// if err != nil {183// log.Errorv(c, log.KV("log", "hour push action clear error"), log.KV("error", err), log.KV("notice_type", notice.NoticeType))184// }185// // 埋点186// tracer, _ := trace.FromContext(c)187// s.Infoc.Info(tracer, notice.Mid, notice.Buvid, nid, notice.NoticeType, notice.BizId, notice.BizType, time.Now().Unix(), result)188// return189// }...

Full Screen

Full Screen

logger_test.go

Source:logger_test.go Github

copy

Full Screen

...31 defer SetWriter(oldW)32 SetWriter(w)33 w.expected = "info 1\n"34 l.Info("info 1")35 l.PushPrefix("this is push 1. ")36 w.expected = "this is push 1. info 1\n"37 l.Info("info 1")38 l.PushPrefix("this is push 2")39 w.expected = "this is push 1. this is push 2 info 2 info 2.1\n"40 l.Info("info 2 ", "info 2.1")41 l.PopPrefix()42 w.expected = "this is push 1. info 3\n"43 l.Info("info 3")44 l.PopPrefix()45 w.expected = "info 4\n"46 l.Info("info 4")47}48func TestLogger_PushPrefixGo(t *testing.T) {49 l := NewLogger()50 w := &writerForTest{51 expected: "",52 t: t,53 }54 oldW := Writer()55 defer SetWriter(oldW)56 SetWriter(w)57 l.PushPrefix("this is push 1. ")58 w.expected = "this is push 1. info 1\n"59 l.Info("info 1")60 l.PushPrefix("this is push 2")61 w.expected = "this is push 1. this is push 2 info 2 info 2.1\n"62 l.Info("info 2 ", "info 2.1")63 ch := make(chan int)64 go func() {65 l := l.Child()66 l.PopPrefix()67 l.PushPrefix("this is push go")68 w.expected = "this is push 1. this is push 2 this is push go info 2.go info 2.1\n"69 l.Info("info 2.go ", "info 2.1")70 l.PopPrefix()71 l.PopPrefix()72 l.PopPrefix()73 w.expected = "this is push 1. this is push 2 info 2.go info 2.1\n"74 l.Info("info 2.go ", "info 2.1")75 l.PushPrefix("this is push go")76 w.expected = "this is push 1. this is push 2 this is push go info 2.go1 info 2.1\n"77 l.Info("info 2.go1 ", "info 2.1")78 close(ch)79 }()80 <-ch81 l.PopPrefix()82 w.expected = "this is push 1. info 3\n"83 l.Info("info 3")84 l.PopPrefix()85 w.expected = "info 4\n"86 l.Info("info 4")87}...

Full Screen

Full Screen

push

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := os.OpenFile("test.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)4 if err != nil {5 log.Fatalf("error opening file: %v", err)6 }7 defer f.Close()8 log.SetOutput(f)9 log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)10 log.Println("This is a test log entry")11 log.Printf("This is a test log entry")12}13import (14func main() {15 f, err := os.OpenFile("test.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)16 if err != nil {17 log.Fatalf("error opening file:

Full Screen

Full Screen

push

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := os.OpenFile("log.txt", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)4 if err != nil {5 log.Fatalf("error opening file: %v", err)6 }7 defer f.Close()8 log.SetOutput(f)9 log.Println("This is a test log entry")10}11import (12func main() {13 f, err := os.OpenFile("log.txt", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)14 if err != nil {15 log.Fatalf("error opening file: %v", err)16 }17 defer f.Close()18 log.SetOutput(f)19 log.Print("This is a test log entry")20}21import (22func main() {23 f, err := os.OpenFile("log.txt", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)24 if err != nil {25 log.Fatalf("error opening file: %v", err)26 }27 defer f.Close()28 log.SetOutput(f)29 log.Println("This is a test log entry")30}31import (32func main() {33 f, err := os.OpenFile("log.txt", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)34 if err != nil {35 log.Fatalf("error opening file: %v", err)36 }37 defer f.Close()38 log.SetOutput(f)39 log.Printf("This is a test log entry")40}41import (42func main() {43 f, err := os.OpenFile("log.txt", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)44 if err != nil {45 log.Fatalf("error opening file: %v", err)46 }

Full Screen

Full Screen

push

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 file, err := os.OpenFile("test.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)4 if err != nil {5 log.Fatalln("Failed to open log file", ":", err)6 }7 logger := log.New(file, "logger: ", log.Lshortfile)8 logger.Println("This is a regular message.")9 logger.Fatalln("This is a fatal error.")10}11import (12func main() {13 file, err := os.OpenFile("test.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)14 if err != nil {15 log.Fatalln("Failed to open log file", ":", err)16 }17 logger := log.New(file, "logger: ", log.Lshortfile)18 logger.Print("This is a regular message.")19 logger.Fatal("This is a fatal error.")20}21import (22func main() {23 file, err := os.OpenFile("test.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)24 if err != nil {25 log.Fatalln("Failed to open log file", ":", err)26 }27 logger := log.New(file, "logger: ", log.Lshortfile)28 logger.Printf("This is a regular message.")29 logger.Fatalf("This is a fatal error.")30}

Full Screen

Full Screen

push

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := os.OpenFile("test.txt", os.O_WRONLY|os.O_CREATE, 0666)4 if err != nil {5 log.Fatalln("failed to open file:", err)6 }7 defer f.Close()8 log.SetOutput(f)9 log.Println("This is a test log entry")10}

Full Screen

Full Screen

push

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 file, err := os.OpenFile("log.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)5 if err != nil {6 log.Fatalf("failed to open log file: %v", err)7 }8 log.SetOutput(file)9 log.Println("This is a test log entry")10}11import (12func main() {13 fmt.Println("Hello, playground")14 file, err := os.OpenFile("log.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)15 if err != nil {16 log.Fatalf("failed to open log file: %v", err)17 }18 log.SetOutput(file)19 log.Print("This is a test log entry")20}21import (22func main() {23 fmt.Println("Hello, playground")24 file, err := os.OpenFile("log.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)25 if err != nil {26 log.Fatalf("failed to open log file: %v", err)27 }28 log.SetOutput(file)29 log.Printf("This is a test log entry")30}31import (32func main() {33 fmt.Println("Hello, playground")34 file, err := os.OpenFile("log.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)35 if err != nil {36 log.Fatalf("failed to open log file: %v", err)37 }38 log.SetOutput(file)39 log.Fatal("This is a test log entry")40}41import (42func main() {43 fmt.Println("Hello, playground")44 file, err := os.OpenFile("log.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)45 if err != nil {46 log.Fatalf("failed to open

Full Screen

Full Screen

push

Using AI Code Generation

copy

Full Screen

1log.Push(“Hello”)2log.Pop()3log.Print()4log.Print()5log.Print()6log.Print()7log.Print()8log.Print()9log.Print()10log.Print()11log.Print()12log.Print()13log.Print()14log.Print()15log.Print()16log.Print()17log.Print()18log.Print()19log.Print()20log.Print()21log.Print()22log.Print()23log.Print()24log.Print()25log.Print()

Full Screen

Full Screen

push

Using AI Code Generation

copy

Full Screen

1import "log"2func main() {3log.Print("This is a print statement")4log.Println("This is a print line statement")5log.Printf("This is a print format statement")6}7import "log"8func main() {9log.Print("This is a print statement")10log.Println("This is a print line statement")11log.Printf("This is a print format statement")12}13import "log"14func main() {15log.Print("This is a print statement")16log.Println("This is a print line statement")17log.Printf("This is a print format statement")18}19import "log"20func main() {21log.Print("This is a print statement")22log.Println("This is a print line statement")23log.Printf("This is a print format statement")24}25import "log"26func main() {27log.Print("This is a print statement")28log.Println("This is a print line statement")29log.Printf("This

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful