Skip to content

Commit

Permalink
log: add log file to the results tar archive (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontesi authored Dec 11, 2023
1 parent 65268fd commit c1be41a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cnf-certification-test/tnf_config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
targetNameSpaces:
- name: jmontesi
- name: tnf
podsUnderTestLabels:
- "test-network-function.com/generic: target"
# deprecated operator label ("test-network-function.com/operator:"") still configured by default, no need to add it here
Expand Down
7 changes: 4 additions & 3 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"time"
)

type Logger struct {
*slog.Logger
}
const (
LogFileName = "cnf-certsuite.log"
LogFilePermissions = 0o644
)

var logger *slog.Logger

Expand Down
10 changes: 4 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,20 @@ const (
junitFlagKey = "junit"
TNFReportKey = "cnf-certification-test"
extraInfoKey = "testsExtraInfo"
logFileName = "cnf-certsuite.log"
logFilePermissions = 0o644
)

func init() {
flags.InitFlags()
}

func createLogFile(outputDir string) (*os.File, error) {
logFilePath := outputDir + "/" + logFileName
logFilePath := outputDir + "/" + log.LogFileName
err := os.Remove(logFilePath)
if err != nil && !os.IsNotExist(err) {
return nil, fmt.Errorf("could not delete old log file, err: %v", err)
}

logFile, err := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE, logFilePermissions)
logFile, err := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE, log.LogFilePermissions)
if err != nil {
return nil, fmt.Errorf("could not open a new log file, err: %v", err)
}
Expand All @@ -68,7 +66,7 @@ func setupLogger(logFile *os.File) {
}

log.SetupLogger(logFile, logLevel)
log.Info("Log file: %s (level=%s)", logFileName, logLevel.String())
log.Info("Log file: %s (level=%s)", log.LogFileName, logLevel.String())
}

func main() {
Expand Down Expand Up @@ -97,7 +95,7 @@ func main() {
fmt.Printf("Claim file version: %s\n", versions.ClaimFormatVersion)
fmt.Printf("Checks filter: %s\n", *flags.LabelsFlag)
fmt.Printf("Output folder: %s\n", *flags.ClaimPath)
fmt.Printf("Log file: %s\n", logFileName)
fmt.Printf("Log file: %s\n", log.LogFileName)
fmt.Printf("\n")

if *flags.ListFlag {
Expand Down
3 changes: 3 additions & 0 deletions pkg/certsuite/certsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ func Run(labelsFilter, outputFolder string) error {
// Add all the web artifacts file paths.
allArtifactsFilePaths = append(allArtifactsFilePaths, webFilePaths...)

// Add the log file path
allArtifactsFilePaths = append(allArtifactsFilePaths, filepath.Join(outputFolder, log.LogFileName))

// tar.gz file creation with results and html artifacts, unless omitted by env var.
if !configuration.GetTestParameters().OmitArtifactsZipFile {
err = results.CompressResultsArtifacts(resultsOutputDir, allArtifactsFilePaths)
Expand Down

0 comments on commit c1be41a

Please sign in to comment.