Files
gf/net/ghttp/ghttp_server_config_logging.go

57 lines
1.6 KiB
Go
Raw Normal View History

// 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,
// 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"
2020-05-01 03:31:04 +08:00
// SetLogPath sets the log path for server.
// It logs content to file only if the log path is set.
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
}
2020-05-01 03:31:04 +08:00
// SetLogStdout sets whether output the logging content to stdout.
2019-06-19 09:06:52 +08:00
func (s *Server) SetLogStdout(enabled bool) {
s.config.LogStdout = enabled
}
2020-05-01 03:31:04 +08:00
// SetAccessLogEnabled enables/disables the 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
}
2020-05-01 03:31:04 +08:00
// SetErrorLogEnabled enables/disables the 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
}
2020-05-01 03:31:04 +08:00
// SetErrorStack enables/disables the error stack feature.
func (s *Server) SetErrorStack(enabled bool) {
s.config.ErrorStack = enabled
}
2020-05-01 03:31:04 +08:00
// GetLogPath returns the log path.
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
}
2020-05-01 03:31:04 +08:00
// IsAccessLogEnabled checks whether the access log enabled.
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
}
2020-05-01 03:31:04 +08:00
// IsErrorLogEnabled checks whether the error log enabled.
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
}