OWASP / Go-SCP

Golang Secure Coding Practices guide

Home Page:https://owasp.org/www-project-go-secure-coding-practices-guide/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question about logging chapter

kevingo opened this issue · comments

Hi, I am a little bit don't understand the following paragraph on the logging chapter:

... Another issue with the native logger is that there is no way to turn logging on or off on a per-package basis.

What do you mean about no way to turn logging on or off on a per-package basis. ?

As I know, you can use log.SetOutput(ioutil.Discard) to disable logging output. The example code is following:

package main

import (
	"fmt"
	"io/ioutil"
	"log"
)

func main() {
	fmt.Println("Hello, World.")
	log.SetOutput(ioutil.Discard)
	log.Print("Hello from log")
}

Or you mean this functionality does not contain inside the log package, which means you have to import io/ioutil package to achieve it ?

Thanks.

Hi @kevingo

We were referring to something like the following in log4j for Java:
log4j.logger.<your package> = DEBUG|INFO|OFF|WARN...

It seems to me that your code suppresses all log messages. I'm not sure if it can be used to implement "per package logging", since we want to see logs, just not for all the packages in the import list.

@PauloASilva can you have a look at this and give some input please?

@kevingo this chapter aims to create awareness that "although called Log this package isn't enough for a real world application logging mechanism".

@jparnaut log4j is far from a "simple logging package" as Go's Log is and as written in the package there are a few other good logging packages.

What do you both think about making clear what's missing in Go's Log (e.g. logging level, per package logging, ...) and show examples using one of the most used third party logging packages?

Cheers,
Paulo A. Silva

Sure, sounds good!

Maybe we can add a feature comparison of the most popular third party logging packages vs Go's Log package.

Hi @kevingo,
Would you like to review the changes done on Logging section to make our point more clear diff?

@PauloASilva Nice! It's my pleasure. 👍