2019-02-02 16:18:25 +08:00
|
|
|
|
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
2018-09-14 13:02:13 +08:00
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-09-14 13:02:13 +08:00
|
|
|
|
|
|
|
|
|
package ghttp
|
|
|
|
|
|
2020-03-25 15:09:13 +08:00
|
|
|
|
import "github.com/gogf/gf/internal/intlog"
|
|
|
|
|
|
2019-03-31 20:52:30 +08:00
|
|
|
|
// 设置日志目录,只有在设置了日志目录的情况下才会输出日志到日志文件中。
|
2019-06-19 09:06:52 +08:00
|
|
|
|
func (s *Server) SetLogPath(path string) {
|
|
|
|
|
if len(path) == 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-03-25 15:09:13 +08:00
|
|
|
|
intlog.Print("SetLogPath:", path)
|
2019-06-19 09:06:52 +08:00
|
|
|
|
s.config.LogPath = path
|
2019-09-26 20:01:48 +08:00
|
|
|
|
s.config.ErrorLogEnabled = true
|
|
|
|
|
s.config.AccessLogEnabled = true
|
2018-09-14 13:02:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-31 20:52:30 +08:00
|
|
|
|
// 设置日志内容是否输出到终端,默认情况下只有错误日志才会自动输出到终端。
|
|
|
|
|
// 如果需要输出请求日志到终端,默认情况下使用SetAccessLogEnabled方法开启请求日志特性即可。
|
2019-06-19 09:06:52 +08:00
|
|
|
|
func (s *Server) SetLogStdout(enabled bool) {
|
|
|
|
|
s.config.LogStdout = enabled
|
2019-03-28 09:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-14 13:02:13 +08:00
|
|
|
|
// 设置是否开启access log日志功能
|
2019-06-19 09:06:52 +08:00
|
|
|
|
func (s *Server) SetAccessLogEnabled(enabled bool) {
|
|
|
|
|
s.config.AccessLogEnabled = enabled
|
2018-09-14 13:02:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置是否开启error log日志功能
|
2019-06-19 09:06:52 +08:00
|
|
|
|
func (s *Server) SetErrorLogEnabled(enabled bool) {
|
|
|
|
|
s.config.ErrorLogEnabled = enabled
|
2018-09-14 13:02:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-14 22:53:28 +08:00
|
|
|
|
// 设置是否开启error stack打印功能
|
|
|
|
|
func (s *Server) SetErrorStack(enabled bool) {
|
|
|
|
|
s.config.ErrorStack = enabled
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-14 13:02:13 +08:00
|
|
|
|
// 获取日志目录
|
2019-06-19 09:06:52 +08:00
|
|
|
|
func (s *Server) GetLogPath() string {
|
|
|
|
|
return s.config.LogPath
|
2018-09-14 13:02:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// access log日志功能是否开启
|
2019-06-19 09:06:52 +08:00
|
|
|
|
func (s *Server) IsAccessLogEnabled() bool {
|
|
|
|
|
return s.config.AccessLogEnabled
|
2018-09-14 13:02:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// error log日志功能是否开启
|
2019-06-19 09:06:52 +08:00
|
|
|
|
func (s *Server) IsErrorLogEnabled() bool {
|
|
|
|
|
return s.config.ErrorLogEnabled
|
2018-09-14 13:02:13 +08:00
|
|
|
|
}
|