go - What errors are outputted to http.Server's ErrorLog struct field?
问题描述
I'm trying to understand the purpose of an ErrorLog
struct field in http.Server
struct. By its name I suspect that those are some kind of errors, but which ones?
What would trigger errors being outputted there? Broken network? Too large http requests?
package main
import (
"log"
"net/http"
)
func main() {
_ = &http.Server{
ErrorLog: log.Default(), // what errors are outputted here?
}
}
解决方案
The official documentation provides an overview of how the field is used:
// ErrorLog specifies an optional logger for errors accepting
// connections, unexpected behavior from handlers, and
// underlying FileSystem errors.
// If nil, logging is done via the log package's standard logger.
ErrorLog *log.Logger // Go 1.3
In practice, the field is accessed in the *http.Server
's logf
method. You can check where that method is called. In short (not exhaustive):
- on panics serving HTTP requests (
conn
'sserve(ctx context.Context)
) - on TLS handshake errors
- on the server's
Serve(l net.Listener) error
errors - on writing non-empty data to the response, if the connection was hijacked
- if the
Content-Length
is invalid - if you call
WriteHeader(code int)
on the same response more than once - if
Content-Length
and non-identity
Transfer-Encoding
headers are used together
推荐阅读
- wordpress - 如何在 woocommerce 上创建“有货”自定义状态,如果再次将其更改为“处理中”,如何减少库存?
- javascript - 没有在 zillow 网站(和其他)上的 devtools 中获取所有 html 数据
- extract - 使用 Google 地球引擎中的 ImageCollection 按多边形提取像素值
- asp.net-web-api - 请求有关从 azure 中继(混合)连接 webapi 的帮助
- zsh - zsh:如何在 vim 模式下为 history-beginning-search-forward 创建键绑定(使用 oh-my-zsh 的 vi-mode 插件)?
- php - 为什么不在 PHP 中的数据库中保存 order 和 order_detail
- r - 在 RStudio 4.1.0 中安装 Lubridate 1.3.3 的问题
- android - setContent 块是可组合的吗?
- java - 如何在两个数组中找到最接近的匹配对以在最后一个数组中查找结果
- php - 使用php将图像上传到文件夹