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