java命令行debug_Golang命令行进行debug调试操作

GoLang调试工具Delve

1.先获取呗:

go get -u github.com/derekparker/delve/cmd/dlv

2.编写测试代码呗:

func main(){

http.HandleFunc("/test",func(writer http.ResponseWriter,req *http.Request){

//TODO

})

log.Fatal(http.ListenAndServe("127.0.0.1:8080",nil))

}

3.debug 启动:

dlv debug test.go

4.打断点:

4.1):对方法打断点:

b main.函数名

4.2):运行到断点处:

c

4.3:对某一行打断点:

需要得到文件的位置再打断点:

b /Users/joker/go/src/…/test.go:14 对14行打断点

至于如何进行与ide上的操作一致的呢: 通过n,s

n:相当于Java-Eclipse的F6

s:相当于Java-Eclipse的F5

如何查看变量呢:p

p testName 则会输出testName的值

args:则会输出所有方法参数信息

locals:则会输出所有的本地变量

emmmmmmmm golang 的命令行编译感觉好不方便,还是想办法搞到ide上吧

用go玩Debug, Info, Error级别的log

直接上代码:

package mylog

import (

"log"

"os"

)

var (

Debug *log.Logger

Info *log.Logger

Error *log.Logger

)

func init() {

log.Println("init ...")

Debug = log.New(os.Stdout, "[DEBUG] ", log.Ldate|log.Ltime|log.Lshortfile)

Info = log.New(os.Stdout, "[INFO] ", log.Ldate|log.Ltime|log.Lshortfile)

Error = log.New(os.Stderr, "[ERROR] ", log.Ldate|log.Ltime|log.Lshortfile)

}

package main

import "mylog"

func main(){

mylog.Debug.Println("good");

mylog.Info.Println("good");

mylog.Error.Println("good");

}

就这样。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Prometheus Client 是一个用于监控和度量的开源工具集,而 Prometheus Client Golang 是 Prometheus 官方提供的 Golang 版本的客户端库。允许 Golang 应用程序暴露指标(metrics)并将其暴露给 Prometheus 服务器进行收集和分析。 使用 Prometheus Client Golang,你可以在你的 Golang 应用程序中定义和注册自定义指标,并且通过 HTTP 接口将指标暴露给 Prometheus 服务器。这样,你就可以使用 Prometheus 的强大功能来监控和可视化你的应用程序的性能指标、错误率、资源使用情况等。 要使用 Prometheus Client Golang,你需要导入 `github.com/prometheus/client_golang/prometheus` 包并使用其中的函数和结构体来定义和注册指标。然后,在你的应用程序中,可以通过适当的接口将指标暴露给 Prometheus 服务器。 以下是一个简单的示例,展示了如何在 Golang 应用程序中使用 Prometheus Client Golang: ```go package main import ( "net/http" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) func main() { // 创建一个新的 Counter 指标 counter := prometheus.NewCounter(prometheus.CounterOpts{ Name: "my_counter", Help: "A simple counter", }) // 注册指标 prometheus.MustRegister(counter) // 增加指标值 counter.Inc() // 创建一个 HTTP 处理程序来暴露指标 http.Handle("/metrics", promhttp.Handler()) // 启动 HTTP 服务器 http.ListenAndServe(":8080", nil) } ``` 在上面的示例中,我们首先创建了一个名为 `my_counter` 的 Counter 指标。然后,我们注册这个指标,并通过 `Inc()` 方法增加其值。接下来,我们创建了一个 HTTP 处理程序来暴露指标,并将其绑定到 `/metrics` 路径上。最后,我们启动了一个 HTTP 服务器来监听端口 8080,并通过该端口暴露指标给 Prometheus。 通过运行上面的代码,你可以在浏览器中访问 `http://localhost:8080/metrics` 查看 Prometheus 格式的指标数据。这些数据可以被 Prometheus 服务器抓取并进行监控和分析。 希望这个简单示例能帮助你了解如何在 Golang 应用程序中使用 Prometheus Client Golang。有关更多详细信息和更高级的用法,请参考 Prometheus Client Golang 的官方文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值