How to use saveLog method of main Package

Best Syzkaller code snippet using main.saveLog

ipfsPin.go

Source:ipfsPin.go Github

copy

Full Screen

...20 ticker := time.NewTicker(time.Second * time.Duration(n))21 sum := 022 for range ticker.C {23 sum++24 saveLog(fmt.Sprintf("执行次数:%v", sum))25 data := getList()26 batchShell(data)27 }28}29func batchShell(d []string) {30 // 批量执行添加命令31 for _, cid := range d {32 //execCommand(string(cid))33 shell := fmt.Sprintf("crust tools ipfs pin add %v", cid)34 res := execCommand(shell)35 status := strings.Contains(res, "recursively")36 if status {37 // 如果成功就上报38 saveLog(fmt.Sprintf("添加成功,CID:%v", cid))39 innerIp := execCommand("/sbin/ifconfig -a|grep inet|grep -vE '127.0.0.1|inet6|172'|awk '{print $2}'|tr -d \"addr:\" | uniq")40 syncCid(cid, innerIp)41 }42 }43}44func saveLog(s string) {45 // 记录log日志46 tm := time.Now().Format("2006-01-02 15:04:05")47 f, err := os.OpenFile("log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)48 defer func() {49 if err = f.Close(); err != nil {50 return51 }52 }()53 if err != nil {54 return55 }56 str := tm + "\t" + s + "\n"57 _, err = f.WriteString(str)58 if err != nil {59 return60 }61}62func execCommand(c string) string {63 // 执行命令并返回结果64 cmd := exec.Command("/bin/bash", "-c", c)65 stdout, _ := cmd.StdoutPipe()66 saveLog("开始执行命令:" + c)67 if err := cmd.Start(); err != nil {68 msg := "开始执行失败:" + err.Error()69 fmt.Println(msg)70 saveLog(msg)71 return ""72 }73 out, _ := ioutil.ReadAll(stdout)74 defer func() {75 if err := stdout.Close(); err != nil {76 return77 }78 }()79 if err := cmd.Wait(); err != nil {80 msg := "执行等待失败:" + err.Error()81 fmt.Println(msg)82 saveLog(msg)83 return ""84 }85 sOut := strings.TrimSuffix(string(out), "\n")86 saveLog("执行结果:" + sOut)87 return sOut88}89type FileList struct {90 Success bool `json:"success"`91 Code string `json:"code"`92 Message interface{} `json:"message"`93 Data []string `json:"data"`94}95func getList() []string {96 // 获取列表97 client := &http.Client{98 Timeout: time.Second * 3,99 }100 url := "https://www.infin.cloud/web/user-file/not-ping-file-cid-list"101 req, _ := http.NewRequest(http.MethodGet, url, nil)102 resp, err := client.Do(req)103 if err != nil {104 msg := "获取列表,请求失败"105 saveLog(fmt.Sprintf("%v", err))106 saveLog(msg)107 fmt.Println(msg)108 return nil109 }110 saveLog(fmt.Sprintf("获取列表,请求成功"))111 fmt.Println("获取列表,请求成功")112 defer func() {113 if err := resp.Body.Close(); err != nil {114 return115 }116 }()117 body, err := ioutil.ReadAll(resp.Body)118 if err != nil {119 msg := "获取列表,解析响应失败"120 saveLog(fmt.Sprintf("%v", err))121 saveLog(msg)122 fmt.Println(msg)123 return nil124 }125 var lst FileList126 err = json.Unmarshal([]byte(string(body)), &lst)127 if err != nil {128 msg := "获取列表,解析参数失败"129 fmt.Println(msg)130 saveLog(msg)131 return nil132 }133 if lst.Success == true {134 msg := "获取列表,解析参数成功"135 saveLog(msg)136 fmt.Println(msg)137 }138 saveLog(fmt.Sprintf("%v", lst.Data))139 return lst.Data140}141func syncCid(c string, ip string) {142 // 上报CID143 client := &http.Client{144 Timeout: time.Second * 3,145 }146 fmt.Println(ip)147 url := fmt.Sprintf("https://www.infin.cloud/web/user-file/local-ping-sync?cid=%v&ip=%v", c, ip)148 req, err := http.NewRequest(http.MethodGet, url, nil)149 if err != nil {150 msg := "上报CID,req构建失败"151 saveLog(fmt.Sprintf("%v", err))152 saveLog(msg)153 fmt.Println(msg)154 return155 }156 resp, err := client.Do(req)157 if err != nil {158 msg := "上报CID,请求失败"159 saveLog(fmt.Sprintf("%v", err))160 saveLog(msg)161 fmt.Println(msg)162 return163 }164 body, _ := ioutil.ReadAll(resp.Body)165 saveLog("上报成功:" + string(body))166 fmt.Println(string(body))167 defer func() {168 if err := resp.Body.Close(); err != nil {169 return170 }171 }()172}...

Full Screen

Full Screen

procDaemon.go

Source:procDaemon.go Github

copy

Full Screen

...17func init() {18 if _, err := os.Stat(workPath); err != nil {19 err := os.MkdirAll(workPath, 0644)20 if err != nil {21 saveLog("目录创建错误:" + err.Error())22 os.Exit(1)23 }24 }25}26func main() {27 var msg string28 if len(os.Args) != 2 {29 msg = "参数错误,请重新输入"30 fmt.Println(msg)31 return32 }33 switch os.Args[1] {34 case "start":35 pid := getPid()36 if pid != "" && pid != "0" {37 return38 }39 cmd := Daemon()40 if cmd == nil {41 log.Println("服务启动失败!")42 return43 }44 case "status":45 pid, _ := strconv.Atoi(getPid())46 proc, err := os.FindProcess(pid)47 if err != nil || pid == 0 {48 fmt.Println("procDaemon 未启动")49 return50 }51 if proc != nil {52 fmt.Println("procDaemon 已启动")53 return54 }55 case "stop":56 msg = "procDaemon 已退出!"57 pid, _ := strconv.Atoi(getPid())58 proc, err := os.FindProcess(pid)59 if err != nil || pid == 0 {60 fmt.Println("procDaemon 未启动")61 return62 }63 err = proc.Kill()64 if err != nil {65 fmt.Println("procDaemon 退出失败")66 return67 }68 setPid("0")69 fmt.Println(msg)70 saveLog(msg)71 case "--daemon":72 // 后台的业务代码73 wg.Add(1)74 ch1 := make(chan int, 1)75 go clock(2, ch1)76 for i := range ch1 {77 saveLog(fmt.Sprintf("执行次数:%v", i))78 }79 wg.Wait()80 }81}82func getPid() string {83 pidFile, err := os.OpenFile(PidPath, os.O_CREATE|os.O_RDONLY, 0444)84 if err != nil {85 saveLog("获取PID出现错误:" + err.Error())86 return ""87 }88 defer func() {89 if err = pidFile.Close(); err != nil {90 return91 }92 }()93 pid, err := ioutil.ReadAll(pidFile)94 if err != nil {95 saveLog("转换PID出现错误:" + err.Error())96 return ""97 }98 return string(pid)99}100func setPid(s string) {101 pidFile, err := os.OpenFile(PidPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0444)102 if err != nil {103 saveLog("设置PID出现错误:" + err.Error())104 return105 }106 defer func() {107 if err = pidFile.Close(); err != nil {108 return109 }110 }()111 _, err = pidFile.WriteString(s)112 if err != nil {113 return114 }115}116func Daemon() *exec.Cmd {117 if os.Getppid() != 1 {118 var msg string119 filepath := os.Args[0]120 cmd := exec.Command(filepath, "--daemon")121 if err := cmd.Start(); err != nil {122 msg = "服务启动失败:" + err.Error()123 saveLog(msg)124 return nil125 }126 msg = fmt.Sprintf("服务pid=%d:开始运行...", cmd.Process.Pid)127 saveLog(msg)128 pidStr := strconv.Itoa(cmd.Process.Pid)129 setPid(pidStr)130 fmt.Println("procDaemon 已启动!")131 os.Exit(0)132 return cmd133 }134 return nil135}136func clock(n int, c chan<- int) {137 // n:定时间隔138 defer wg.Done()139 ticker := time.NewTicker(time.Second * time.Duration(n))140 sum := 0141 for range ticker.C {142 sum++143 c <- sum144 }145}146func saveLog(s string) {147 // 记录log日志148 tm := time.Now().Format("2006-01-02 15:04:05")149 f, err := os.OpenFile(LogPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)150 defer func() {151 if err = f.Close(); err != nil {152 return153 }154 }()155 if err != nil {156 return157 }158 str := tm + "\t" + s + "\n"159 _, err = f.WriteString(str)160 if err != nil {...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...18 barkKey = "test"19 var wg sync.WaitGroup20 wg.Add(1)21 nyc, _ := time.LoadLocation("Asia/Shanghai")22 saveLog(barkPush("测试发送", barkKey, "测试"))23 c := cron.New(cron.WithLocation(nyc))24 _, err := c.AddFunc("0/5 7-22 * * MON-FRI", getlubu)25 if err != nil {26 saveLog(err.Error())27 return28 }29 getlubu()30 c.Start()31 wg.Wait()32 saveLog("已结束运行")33}34func getlubu() {35 saveLog("开始获取牌价\n")36 // Request the HTML page.37 res, err := http.Get("https://www.boc.cn/sourcedb/whpj/")38 if err != nil {39 log.Fatal(err)40 }41 defer func(Body io.ReadCloser) {42 err := Body.Close()43 if err != nil {44 log.Fatal(err)45 }46 }(res.Body)47 if res.StatusCode != 200 {48 log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)49 }50 // Load the HTML document51 doc, err := goquery.NewDocumentFromReader(res.Body)52 if err != nil {53 log.Fatal(err)54 }55 gong := "body > div.wrapper > div.BOC_main > div.publish > div:nth-child(3) > table > tbody > tr:nth-child("56 namegps := ") > td:nth-child(1)"57 salegps := ") > td:nth-child(2)"58 buygps := ") > td:nth-child(4)"59 timegps := ") > td:nth-child(8)"60 for i := 2; i < 30; i++ {61 name := gong + strconv.Itoa(i) + namegps62 nameText := doc.Find(name).Text()63 if nameText == "卢布" {64 saleName := gong + strconv.Itoa(1) + ") > th:nth-child(2)"65 buyName := gong + strconv.Itoa(1) + ") > th:nth-child(4)"66 timeName := gong + strconv.Itoa(1) + ") > th:nth-child(8)"67 saleDom := gong + strconv.Itoa(i) + salegps68 buyDom := gong + strconv.Itoa(i) + buygps69 timeDom := gong + strconv.Itoa(i) + timegps70 saleNameText := doc.Find(saleName).Text()71 buyNameText := doc.Find(buyName).Text()72 timeNameText := doc.Find(timeName).Text()73 saleText := doc.Find(saleDom).Text()74 buyText := doc.Find(buyDom).Text()75 timeText := doc.Find(timeDom).Text()76 PriceBody := saleNameText + ": " + saleText + "\n" + buyNameText + ": " + buyText + "\n"77 body := PriceBody + timeNameText + ": " + timeText78 if lastPrice != PriceBody {79 saveLog(barkPush(body, barkKey, nameText))80 lastPrice = PriceBody81 }82 break83 }84 if i == 29 {85 result, _ := ioutil.ReadAll(res.Body)86 saveLog(string(result))87 saveLog(barkPush("貌似被封了", barkKey, nameText))88 }89 }90 saveLog("结束获取牌价\n")91}92//计算两个时间相差多少秒93func timeDiff(start, end time.Time) int {94 return int(end.Sub(start).Seconds())95}

Full Screen

Full Screen

saveLog

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := os.Create("log.txt")4 if err != nil {5 log.Fatal(err)6 }7 saveLog(f)8}9import (10func saveLog(f *os.File) {11 log.SetOutput(f)12 log.Println("This is a test log entry")13}

Full Screen

Full Screen

saveLog

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 main.saveLog("Hello")4}5import (6func main() {7 main.saveLog("Hello")8}9import (10func main() {11 main.saveLog("Hello")12}13import (14func main() {15 main.saveLog("Hello")16}17import (18func main() {19 main.saveLog("Hello")20}21import (22func main() {23 main.saveLog("Hello")24}25import (26func main() {27 main.saveLog("Hello")28}29import (30func main() {31 main.saveLog("Hello")32}33import (34func main() {35 main.saveLog("Hello")36}37import (38func main() {39 main.saveLog("Hello")40}41import (42func main() {43 main.saveLog("Hello")44}45import (46func main() {47 main.saveLog("Hello")48}49import (50func main() {51 main.saveLog("Hello")52}

Full Screen

Full Screen

saveLog

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err = saveLog("Error")4 if err != nil {5 log.Fatal(err)6 }7}8import (9func saveLog(logType string) error {10 f, err := os.OpenFile("log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)11 if err != nil {12 }13 defer f.Close()14 if _, err := f.WriteString(fmt.Sprintf("%s15", logType)); err != nil {16 }17}18Your name to display (optional):19Your name to display (optional):

Full Screen

Full Screen

saveLog

Using AI Code Generation

copy

Full Screen

1import (2func saveLog() {3 log.Println("hello from saveLog")4}5import (6func saveLog() {7 log.Println("hello from saveLog")8}9import (10func saveLog() {11 log.Println("hello from saveLog")12}13import (14func saveLog() {15 log.Println("hello from saveLog")16}17import (18func saveLog() {19 log.Println("hello from saveLog")20}21import (22func saveLog() {23 log.Println("hello from saveLog")24}25import (26func saveLog() {27 log.Println("hello from saveLog")28}29import (30func saveLog() {31 log.Println("hello from saveLog")32}33import (34func saveLog() {35 log.Println("hello from saveLog")36}37import (38func saveLog() {39 log.Println("hello from saveLog")40}41import (42func saveLog() {43 log.Println("hello from saveLog")44}45import (46func saveLog() {47 log.Println("hello from saveLog")48}49import (50func saveLog() {51 log.Println("hello

Full Screen

Full Screen

saveLog

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 var log = Log{"", "2.go"}4 log.saveLog()5}6import "fmt"7func main() {8 var log = Log{"", "3.go"}9 log.saveLog()10}11import "fmt"12func main() {13 var log = Log{"", "4.go"}14 log.saveLog()15}16import "fmt"17func main() {18 var log = Log{"", "5.go"}19 log.saveLog()20}21import "fmt"22func main() {23 var log = Log{"", "6.go"}24 log.saveLog()25}26import "fmt"27func main() {28 var log = Log{"", "7.go"}29 log.saveLog()30}31import "fmt"32func main() {33 var log = Log{"", "8.go"}34 log.saveLog()35}36import "fmt"37func main() {38 var log = Log{"", "9.go"}39 log.saveLog()40}41import "fmt"42func main() {43 var log = Log{"", "10.go"}44 log.saveLog()45}46import "fmt"47func main() {48 var log = Log{"", "11.go"}49 log.saveLog()50}51import "fmt"52func main() {53 var log = Log{"", "12.go"}54 log.saveLog()55}

Full Screen

Full Screen

saveLog

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 var log = NewLog()5 log.saveLog("test")6}7import (8func main() {9 fmt.Println("Hello, playground")10 var log = NewLog()11 log.saveLog("test")12}13import (14func main() {15 fmt.Println("Hello, playground")16 var log = NewLog()17 log.saveLog("test")18}19import (20func main() {21 fmt.Println("Hello, playground")22 var log = NewLog()23 log.saveLog("test")24}25import (26func main() {27 fmt.Println("Hello, playground")28 var log = NewLog()29 log.saveLog("test")30}31import (32func main() {33 fmt.Println("Hello, playground")34 var log = NewLog()35 log.saveLog("test")36}37import (38func main() {39 fmt.Println("Hello, playground")40 var log = NewLog()41 log.saveLog("test")42}43import (44func main() {45 fmt.Println("Hello, playground")46 var log = NewLog()47 log.saveLog("test")48}49import (50func main() {51 fmt.Println("Hello, playground")52 var log = NewLog()53 log.saveLog("test")54}

Full Screen

Full Screen

saveLog

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 saveLog("Hello, playground")5}6func saveLog(logData string) {7 log.Println(logData)8}

Full Screen

Full Screen

saveLog

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4}5import (6func main() {7 fmt.Println("Hello, playground")8}9import (10func main() {11 fmt.Println("Hello, playground")12}13import (14func main() {15 fmt.Println("Hello, playground")16}17import (18func main() {19 fmt.Println("Hello, playground")20}21import (22func main() {23 fmt.Println("Hello, playground")24}25import (26func main() {27 fmt.Println("Hello, playground")28}29import (30func main() {31 fmt.Println("Hello, playground")32}

Full Screen

Full Screen

saveLog

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 main.saveLog("test")4}5func main() {6 http.HandleFunc("/", hello)7 http.ListenAndServe(":8080", nil)8}9func hello(w http.ResponseWriter, r *http.Request) {10 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))11}12func main() {13 http.HandleFunc("/", hello)14 http.ListenAndServe(":8080", nil)15}16var hello = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {17 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))18})19func main() {20 http.HandleFunc("/", hello)21 http.ListenAndServe(":8080", nil)22}23func hello(w http.ResponseWriter, r *http.Request) {24 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))25}26var hello = http.HandlerFunc(hello)27func main() {28 http.HandleFunc("/", hello)29 http.ListenAndServe(":8080", nil)30}31func hello(w http.ResponseWriter, r *http.Request) {32 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))33}34var hello = http.HandlerFunc(hello)

Full Screen

Full Screen

saveLog

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello from 2.go")4 SaveLog1.SaveLog("This is a test log message")5}6import (7func main() {8 fmt.Println("Hello from 3.go")9 SaveLog1.SaveLog("This is a test log message")10}11import (12func main() {13 fmt.Println("Hello from 1.go")14 SaveLog1.SaveLog("This is a test log message")15}16import (17func main() {18 fmt.Println("Hello from 2.go")

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.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful