util/intelp2m: Add logger
Add logging to a file, ./logs.txt by default. --logs option is used to override this path. Error messages are duplicated to the console. Change-Id: I97aba146b6d8866a7fa46bac80c27c0896b26cf7 Signed-off-by: Maxim Polyakov <max.senia.poliak@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/70542 Reviewed-by: David Hendricks <david.hendricks@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
2e9dd0ade2
commit
be7eb06131
6 changed files with 67 additions and 2 deletions
2
util/intelp2m/.gitignore
vendored
2
util/intelp2m/.gitignore
vendored
|
|
@ -1,2 +1,2 @@
|
|||
intelp2m
|
||||
generate/gpio.h
|
||||
gpio.h
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ basic functions:
|
|||
-v | -version Print version
|
||||
-file <path> Set path to the inteltool file. <inteltool.log> by default
|
||||
-out <path> Set path to the generated file. <generate/gpio.h> by default
|
||||
-logs <path> Override the log file path. <logs.txt> by default
|
||||
-p | -platform <type> Set the PCH platform type. <sunrise> by default
|
||||
(enter ? to show datails)
|
||||
|
||||
|
|
@ -193,6 +194,8 @@ func ParseOptions() {
|
|||
flag.Usage = Usage
|
||||
flag.StringVar(&p2m.Config.InputPath, "file", "inteltool.log", "")
|
||||
flag.StringVar(&p2m.Config.OutputPath, "out", "generate/gpio.h", "")
|
||||
flag.StringVar(&p2m.Config.LogsPath, "logs", "logs.txt", "")
|
||||
|
||||
help := flag.Bool("help", false, "")
|
||||
|
||||
vers, v := flag.Bool("version", false, ""), flag.Bool("v", false, "")
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ type Settings struct {
|
|||
Field FieldType
|
||||
InputPath string
|
||||
OutputPath string
|
||||
LogsPath string
|
||||
InputFile *os.File
|
||||
OutputFile *os.File
|
||||
IgnoredFields bool
|
||||
|
|
|
|||
50
util/intelp2m/logs/logs.go
Normal file
50
util/intelp2m/logs/logs.go
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package logs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"review.coreboot.org/coreboot.git/util/intelp2m/config/p2m"
|
||||
)
|
||||
|
||||
var (
|
||||
linfo *log.Logger
|
||||
lwarning *log.Logger
|
||||
lerror *log.Logger
|
||||
)
|
||||
|
||||
func Init() (*os.File, error) {
|
||||
|
||||
flags := os.O_RDWR | os.O_CREATE | os.O_APPEND
|
||||
file, err := os.OpenFile(p2m.Config.LogsPath, flags, 0666)
|
||||
if err != nil {
|
||||
fmt.Printf("logs: error opening %s file: %v", p2m.Config.LogsPath, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
attributes := log.Lshortfile
|
||||
linfo = log.New(file, "INFO: ", attributes)
|
||||
lwarning = log.New(file, "WARNING: ", attributes)
|
||||
lerror = log.New(file, "ERROR: ", attributes)
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func Infof(format string, v ...any) {
|
||||
if linfo != nil {
|
||||
linfo.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
}
|
||||
|
||||
func Warnf(format string, v ...any) {
|
||||
if lwarning != nil {
|
||||
lwarning.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
}
|
||||
|
||||
func Errorf(format string, v ...any) {
|
||||
if lerror != nil {
|
||||
lerror.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
log.Output(2, fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"review.coreboot.org/coreboot.git/util/intelp2m/cli"
|
||||
"review.coreboot.org/coreboot.git/util/intelp2m/config/p2m"
|
||||
"review.coreboot.org/coreboot.git/util/intelp2m/logs"
|
||||
"review.coreboot.org/coreboot.git/util/intelp2m/parser"
|
||||
)
|
||||
|
||||
|
|
@ -33,6 +34,13 @@ func main() {
|
|||
|
||||
cli.ParseOptions()
|
||||
|
||||
if file, err := logs.Init(); err != nil {
|
||||
fmt.Printf("logs init error: %v\n", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
defer file.Close()
|
||||
}
|
||||
|
||||
if file, err := os.Open(p2m.Config.InputPath); err != nil {
|
||||
fmt.Printf("input file error: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
|
@ -53,6 +61,8 @@ func main() {
|
|||
defer file.Close()
|
||||
}
|
||||
|
||||
logs.Infof("start %s", os.Args[0])
|
||||
|
||||
prs := parser.ParserData{}
|
||||
prs.Parse()
|
||||
|
||||
|
|
@ -80,5 +90,6 @@ static const struct pad_config gpio_table[] = {`, Version)
|
|||
|
||||
#endif /* CFG_GPIO_H */
|
||||
`)
|
||||
logs.Infof("exit from %s\n", os.Args[0])
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
1.3
|
||||
1.4
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue