You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
423 B
27 lines
423 B
3 years ago
|
package logs
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
)
|
||
|
|
||
|
// Create a logfile in the same directory as executable and set output
|
||
|
// of `log` package to it
|
||
|
func SetUp() error {
|
||
|
executablePath, err := os.Executable()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
exeDir := filepath.Dir(executablePath)
|
||
|
|
||
|
logfile, err := os.Create(filepath.Join(exeDir, "logs.log"))
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
log.SetOutput(logfile)
|
||
|
|
||
|
return nil
|
||
|
}
|