Skip to content

Commit 2e23a24

Browse files
committed
logger improvements
1 parent cc8a8b3 commit 2e23a24

4 files changed

Lines changed: 41 additions & 25 deletions

File tree

cmd/check.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ import (
1818
"fmt"
1919
"github.com/DataBridgeTech/dbqcore"
2020
"github.com/DataBridgeTech/dbqctl/internal"
21-
"log"
21+
"log/slog"
2222
"os"
2323
"strings"
2424

2525
"github.com/spf13/cobra"
2626
)
2727

28+
type FailedCheckDetails struct {
29+
ID string
30+
Err error
31+
}
32+
2833
func NewCheckCommand(app internal.DbqCliApp) *cobra.Command {
2934
var checksFile string
3035

@@ -37,7 +42,8 @@ which outlines the rules and constraints that the data within the dataset should
3742
By automating these checks, you can proactively identify and address data quality issues, ensuring that your datasets meet the required standards for analysis and decision-making.
3843
`,
3944
RunE: func(cmd *cobra.Command, args []string) error {
40-
log.Printf("Reading checks configuration file: %s \n", checksFile)
45+
slog.Debug("Reading checks configuration file",
46+
"checks_config_path", checksFile)
4147

4248
checksCfg, err := dbqcore.LoadChecksConfig(checksFile)
4349
if err != nil {
@@ -56,24 +62,35 @@ By automating these checks, you can proactively identify and address data qualit
5662
return fmt.Errorf("specified data source not found in dbq configuration: %s", dataSourceId)
5763
}
5864

59-
for dsIdx, dataset := range datasets {
60-
log.Printf("[%d/%d] Running quality checks for: %s", dsIdx+1, len(datasets), dataset)
61-
for cIdx, check := range rule.Checks {
62-
pass, _, err := app.RunCheck(&check, dataSource, dataset, rule.Where)
65+
var failedChecks []FailedCheckDetails
66+
for _, dataset := range datasets {
67+
fmt.Printf("running %d quality checks for '%s'\n", len(rule.Checks), dataset)
68+
for _, check := range rule.Checks {
69+
pass, _, _ := app.RunCheck(&check, dataSource, dataset, rule.Where)
70+
fmt.Printf(" check %s ('%s') ... %s\n", check.Description, check.ID, getCheckResultLabel(pass))
71+
6372
if err != nil {
64-
log.Printf("Failed to run check: %s", err.Error())
73+
failedChecks = append(failedChecks, FailedCheckDetails{ID: check.ID, Err: err})
6574
}
6675

67-
log.Printf(" [%d/%d] '%s': %s", cIdx+1, len(rule.Checks), check.ID, getCheckResultLabel(pass))
6876
if !pass && strGetOrDefault(string(check.OnFail), dbqcore.OnFailActionError) == dbqcore.OnFailActionError {
6977
exitCode = 1
7078
}
7179
}
7280
}
81+
82+
if len(failedChecks) != 0 {
83+
for _, result := range failedChecks {
84+
fmt.Println()
85+
fmt.Printf("--- %s ---\n", result.ID)
86+
fmt.Printf("error: %s\n", result.Err)
87+
}
88+
}
7389
}
7490

7591
if exitCode != 0 {
76-
log.Printf("One or more checks with on_fail = 'error' action have failed, exiting.")
92+
// todo: print detailed report
93+
// fmt.Printf("\ncheck result: FAILED. 1 passed; 1 failed; \n")
7794
os.Exit(exitCode)
7895
}
7996

@@ -124,9 +141,9 @@ func parseDatasetString(input string) (datasource string, datasets []string, err
124141

125142
func getCheckResultLabel(passed bool) string {
126143
if passed {
127-
return "passed"
144+
return "ok"
128145
} else {
129-
return "failed"
146+
return "FAILED"
130147
}
131148
}
132149

cmd/import.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
package cmd
1616

1717
import (
18-
"log"
19-
18+
"fmt"
2019
"github.com/DataBridgeTech/dbqctl/internal"
2120
"github.com/spf13/cobra"
21+
"log"
2222
)
2323

2424
func NewImportCommand(app internal.DbqCliApp) *cobra.Command {
@@ -50,7 +50,7 @@ This command is useful for quickly onboarding data from external systems, allowi
5050
return nil
5151
}
5252

53-
log.Printf("Found %d datasets in %s to import: %v\n", len(datasets), curDataSource, datasets)
53+
fmt.Printf("found %d datasets in %s to import: %v\n", len(datasets), curDataSource, datasets)
5454

5555
ds := app.FindDataSourceById(dataSource)
5656
if ds != nil {
@@ -63,7 +63,7 @@ This command is useful for quickly onboarding data from external systems, allowi
6363
if err != nil {
6464
return err
6565
}
66-
log.Println("dbq config has been updated")
66+
fmt.Println("dbq config has been updated")
6767
}
6868

6969
return nil

cmd/ping.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
package cmd
1616

1717
import (
18-
"log"
19-
18+
"fmt"
2019
"github.com/DataBridgeTech/dbqctl/internal"
2120
"github.com/spf13/cobra"
2221
)
@@ -40,12 +39,12 @@ This is useful for quickly determining if the data source is online and respondi
4039
}
4140

4241
for _, curDataSource := range sourcesToPing {
43-
log.Printf("Pinging data source: %s...\n", curDataSource)
42+
fmt.Printf("Conneting to data source: %s...\n", curDataSource)
4443
info, err := app.PingDataSource(curDataSource)
4544
if err != nil {
46-
log.Printf("Connection failed: %s\n", err.Error())
45+
fmt.Printf("Connection failed: %s\n", err.Error())
4746
} else {
48-
log.Printf("Connected: %s\n", info)
47+
fmt.Printf("Connected: %s\n", info)
4948
}
5049
}
5150
},

cmd/profile.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ package cmd
1616

1717
import (
1818
"encoding/json"
19-
"log"
20-
19+
"fmt"
2120
"github.com/DataBridgeTech/dbqcore"
2221
"github.com/DataBridgeTech/dbqctl/internal"
2322
"github.com/spf13/cobra"
@@ -58,7 +57,7 @@ and helps in making better decisions about data processing and analysis.
5857
for _, curDataSet := range dataSetsToProfile {
5958
metrics, err := app.ProfileDataset(dataSource, curDataSet, sample)
6059
if err != nil {
61-
log.Printf("Failed to profile %s: %s\n", curDataSet, err)
60+
fmt.Printf("Failed to profile %s: %s\n", curDataSet, err)
6261
} else {
6362
profileResults.Profiles[curDataSet] = metrics
6463
}
@@ -67,9 +66,10 @@ and helps in making better decisions about data processing and analysis.
6766
// todo: introduce output format flag
6867
jsonData, err := json.Marshal(profileResults)
6968
if err != nil {
70-
log.Fatalf("Failed to marshal metrics to JSON: %v", err)
69+
fmt.Println("failed to marshal metrics to JSON")
70+
panic(err)
7171
}
72-
log.Println(string(jsonData))
72+
fmt.Println(string(jsonData))
7373

7474
return nil
7575
},

0 commit comments

Comments
 (0)