dpp80346 2017-02-22 02:44
浏览 54
已采纳

默认情况下,标准库http软件包日志记录到stdout,我可以禁用它吗?

When using the built-in http module in Go, I notice that http.ListenAndServe() will make logging calls to stdout by default. The main thing showing up in my terminal is:

http: TLS handshake error from x.x.x.x:x: tls: client offered an unsupported, maximum protocol version of 301.

Now I understand what this error is and what causes it, but the fact of the matter is, I don't particularly care.

How can I stop the http package (or ListenAndServe(), whatever) from logging to stdout by default? It's clogging up my pretty console. I'm 95% certain that I'm not the one logging the messages as all of the logs I have setup have "INFO", "WARNING" etc prefixes on them.

  • 写回答

1条回答 默认 最新

  • duanbaque4230 2017-02-22 02:53
    关注

    It doesn't log to stdout, it logs to the http server's ErrorLog if it's set, and to the standard logger (the one used by the non-method functions in log) otherwise. If you have a logger already, construct a http.Server with that logger as its ErrorLog and call ListenAndServe on that. Otherwise use log.SetOutput to change the destination of the standard log.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了