10 examples of 'golang logging' in Go

Every line of 'golang logging' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
40func logging(level int, format string, v ...interface{}) {
41
42 switch level {
43 case 0:
44 log.Println(fmt.Sprintf("[error] "+format, v...))
45 case 2:
46 log.Println(fmt.Sprintf("[info] "+format, v...))
47 case 4:
48 log.Println(fmt.Sprintf("[debug] "+format, v...))
49 }
50}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

8func (c *Client) Logging(l *lumber.Logger, level string) {
9 c.logger = l
10 if level == "DEBUG" {
11 c.debug = true
12 }
13}
587func Logging(l *logs.Logger) Decorator {
588 return func(r Request) Request {
589 return RequestFunc(func(t *TransferRequest) error {
590 l.Println("TransferRequest", t)
591 return r.Process(t)
592 })
593 }
594}
145func setupLogging() {
146 klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
147 glog.InitFlags(klogFlags)
148
149 // Sync the glog and klog flags.
150 flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
151 f2 := klogFlags.Lookup(f1.Name)
152 if f2 != nil {
153 value := f1.Value.String()
154 f2.Value.Set(value)
155 }
156 })
157}
75func setupLogging(debug bool) {
76 var traceDest io.Writer
77 traceDest = ioutil.Discard
78 if debug {
79 traceDest = os.Stderr
80 }
81 logger = log.New(traceDest, "INFO: ", log.LstdFlags)
82}
34func configureLogging() {
35 // Configure logging.
36 log.SetFlags(log.LstdFlags | log.Lshortfile)
37 log.SetOutput(Log)
38}
187func initLogging() {
188 if err := setUpVerboseLogLevel(verbose); err != nil {
189 er(err)
190 }
191}
170func configureLogging(cmd *cobra.Command, args []string) {
171 verbose, _ := cmd.Flags().GetBool(FlagVerbose)
172
173 for category, level := range logLevels {
174 if verbose {
175 logger.SetLevel(logger.DEBUG, category)
176 } else {
177 logger.SetLevel(level, category)
178 }
179 }
180}
63func (a *MQServer) SetLog() {
64 level, err := logrus.ParseLevel(a.LogLevel)
65 if err != nil {
66 fmt.Println("set log level error." + err.Error())
67 return
68 }
69 logrus.SetLevel(level)
70}
331func (config *LoggingConfig) InitLogging(outWriter, errWriter io.Writer) {
332 config.Info = appsodylogger{name: "Info"}
333 config.Warning = appsodylogger{name: "Warning"}
334 config.Error = appsodylogger{name: "Error"}
335 config.Debug = appsodylogger{name: "Debug"}
336 config.Container = appsodylogger{name: "Container"}
337 config.InitScript = appsodylogger{name: "InitScript"}
338 config.DockerLog = appsodylogger{name: "Docker"}
339 config.BuildahLog = appsodylogger{name: "Buildah"}
340
341 var allLoggers = []*appsodylogger{&config.Info, &config.Warning, &config.Error, &config.Debug, &config.Container, &config.InitScript, &config.DockerLog, &config.BuildahLog}
342
343 for _, l := range allLoggers {
344 l.outWriter = outWriter
345 l.errWriter = errWriter
346 }
347}

Related snippets