github.com/wangyougui/gf/v2@v2.6.5/os/glog/glog_config.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 package glog 8 9 import ( 10 "context" 11 "io" 12 ) 13 14 // SetConfig set configurations for the defaultLogger. 15 func SetConfig(config Config) error { 16 return defaultLogger.SetConfig(config) 17 } 18 19 // SetConfigWithMap set configurations with map for the defaultLogger. 20 func SetConfigWithMap(m map[string]interface{}) error { 21 return defaultLogger.SetConfigWithMap(m) 22 } 23 24 // SetPath sets the directory path for file logging. 25 func SetPath(path string) error { 26 return defaultLogger.SetPath(path) 27 } 28 29 // GetPath returns the logging directory path for file logging. 30 // It returns empty string if no directory path set. 31 func GetPath() string { 32 return defaultLogger.GetPath() 33 } 34 35 // SetFile sets the file name `pattern` for file logging. 36 // Datetime pattern can be used in `pattern`, eg: access-{Ymd}.log. 37 // The default file name pattern is: Y-m-d.log, eg: 2018-01-01.log 38 func SetFile(pattern string) { 39 defaultLogger.SetFile(pattern) 40 } 41 42 // SetLevel sets the default logging level. 43 func SetLevel(level int) { 44 defaultLogger.SetLevel(level) 45 } 46 47 // GetLevel returns the default logging level value. 48 func GetLevel() int { 49 return defaultLogger.GetLevel() 50 } 51 52 // SetWriter sets the customized logging `writer` for logging. 53 // The `writer` object should implements the io.Writer interface. 54 // Developer can use customized logging `writer` to redirect logging output to another service, 55 // eg: kafka, mysql, mongodb, etc. 56 func SetWriter(writer io.Writer) { 57 defaultLogger.SetWriter(writer) 58 } 59 60 // GetWriter returns the customized writer object, which implements the io.Writer interface. 61 // It returns nil if no customized writer set. 62 func GetWriter() io.Writer { 63 return defaultLogger.GetWriter() 64 } 65 66 // SetDebug enables/disables the debug level for default defaultLogger. 67 // The debug level is enabled in default. 68 func SetDebug(debug bool) { 69 defaultLogger.SetDebug(debug) 70 } 71 72 // SetAsync enables/disables async logging output feature for default defaultLogger. 73 func SetAsync(enabled bool) { 74 defaultLogger.SetAsync(enabled) 75 } 76 77 // SetStdoutPrint sets whether ouptput the logging contents to stdout, which is true in default. 78 func SetStdoutPrint(enabled bool) { 79 defaultLogger.SetStdoutPrint(enabled) 80 } 81 82 // SetHeaderPrint sets whether output header of the logging contents, which is true in default. 83 func SetHeaderPrint(enabled bool) { 84 defaultLogger.SetHeaderPrint(enabled) 85 } 86 87 // SetPrefix sets prefix string for every logging content. 88 // Prefix is part of header, which means if header output is shut, no prefix will be output. 89 func SetPrefix(prefix string) { 90 defaultLogger.SetPrefix(prefix) 91 } 92 93 // SetFlags sets extra flags for logging output features. 94 func SetFlags(flags int) { 95 defaultLogger.SetFlags(flags) 96 } 97 98 // GetFlags returns the flags of defaultLogger. 99 func GetFlags() int { 100 return defaultLogger.GetFlags() 101 } 102 103 // SetCtxKeys sets the context keys for defaultLogger. The keys is used for retrieving values 104 // from context and printing them to logging content. 105 // 106 // Note that multiple calls of this function will overwrite the previous set context keys. 107 func SetCtxKeys(keys ...interface{}) { 108 defaultLogger.SetCtxKeys(keys...) 109 } 110 111 // GetCtxKeys retrieves and returns the context keys for logging. 112 func GetCtxKeys() []interface{} { 113 return defaultLogger.GetCtxKeys() 114 } 115 116 // PrintStack prints the caller stack, 117 // the optional parameter `skip` specify the skipped stack offset from the end point. 118 func PrintStack(ctx context.Context, skip ...int) { 119 defaultLogger.PrintStack(ctx, skip...) 120 } 121 122 // GetStack returns the caller stack content, 123 // the optional parameter `skip` specify the skipped stack offset from the end point. 124 func GetStack(skip ...int) string { 125 return defaultLogger.GetStack(skip...) 126 } 127 128 // SetStack enables/disables the stack feature in failure logging outputs. 129 func SetStack(enabled bool) { 130 defaultLogger.SetStack(enabled) 131 } 132 133 // SetLevelStr sets the logging level by level string. 134 func SetLevelStr(levelStr string) error { 135 return defaultLogger.SetLevelStr(levelStr) 136 } 137 138 // SetLevelPrefix sets the prefix string for specified level. 139 func SetLevelPrefix(level int, prefix string) { 140 defaultLogger.SetLevelPrefix(level, prefix) 141 } 142 143 // SetLevelPrefixes sets the level to prefix string mapping for the defaultLogger. 144 func SetLevelPrefixes(prefixes map[int]string) { 145 defaultLogger.SetLevelPrefixes(prefixes) 146 } 147 148 // GetLevelPrefix returns the prefix string for specified level. 149 func GetLevelPrefix(level int) string { 150 return defaultLogger.GetLevelPrefix(level) 151 } 152 153 // SetHandlers sets the logging handlers for default defaultLogger. 154 func SetHandlers(handlers ...Handler) { 155 defaultLogger.SetHandlers(handlers...) 156 } 157 158 // SetWriterColorEnable sets the file logging with color 159 func SetWriterColorEnable(enabled bool) { 160 defaultLogger.SetWriterColorEnable(enabled) 161 }