Hello everyone
i new to golang and i want to achieve this.
modify the package such that a user can be able to enable and disable loggin in the package, such that when loggin is enable, the package should log the answer in a file after processing before returning the result.
type Divider struct{
log bool
}
func NewDivider(islog bool) *Divider{
return &Divider{log: islog}
}
func (d *Divider) Divide(firstValue, secondValue float64) (float64) {
result = firstValue+secondValue
if d.log} {
log.Println(result)}
{
return result
}
You can take an input from a user on whether to write any application logs to a file(in the form of a boolean) and then store that in a global variable and check every time whether you should write the log to a file or not. You can also write a custom log function to avoid writing that code every time.
You can also use a config file to let the user define such a condition.