diff --git a/lib/dbsteward.go b/lib/dbsteward.go index 913e871..d2547dd 100644 --- a/lib/dbsteward.go +++ b/lib/dbsteward.go @@ -123,17 +123,17 @@ func (dbsteward *DBSteward) ArgParse() { // XML file parameter sanity checks if len(args.XmlFiles) > 0 { if len(args.OldXmlFiles) > 0 { - dbsteward.Fatal("Parameter error: xml and oldxml options are not to be mixed. Did you mean newxml?") + dbsteward.fatal("Parameter error: xml and oldxml options are not to be mixed. Did you mean newxml?") } if len(args.NewXmlFiles) > 0 { - dbsteward.Fatal("Parameter error: xml and newxml options are not to be mixed. Did you mean oldxml?") + dbsteward.fatal("Parameter error: xml and newxml options are not to be mixed. Did you mean oldxml?") } } if len(args.OldXmlFiles) > 0 && len(args.NewXmlFiles) == 0 { - dbsteward.Fatal("Parameter error: oldxml needs newxml specified for differencing to occur") + dbsteward.fatal("Parameter error: oldxml needs newxml specified for differencing to occur") } if len(args.NewXmlFiles) > 0 && len(args.OldXmlFiles) == 0 { - dbsteward.Fatal("Parameter error: oldxml needs newxml specified for differencing to occur") + dbsteward.fatal("Parameter error: oldxml needs newxml specified for differencing to occur") } // database connectivity values @@ -199,20 +199,20 @@ func (dbsteward *DBSteward) ArgParse() { // validate mode parameters if mode == ModeXmlDataInsert { if len(args.XmlFiles) == 0 { - dbsteward.Fatal("xmldatainsert needs xml parameter defined") + dbsteward.fatal("xmldatainsert needs xml parameter defined") } else if len(args.XmlFiles) > 1 { - dbsteward.Fatal("xmldatainsert only supports one xml file") + dbsteward.fatal("xmldatainsert only supports one xml file") } } if mode == ModeExtract || mode == ModeDbDataDiff { if len(args.DbHost) == 0 { - dbsteward.Fatal("dbhost not specified") + dbsteward.fatal("dbhost not specified") } if len(args.DbName) == 0 { - dbsteward.Fatal("dbname not specified") + dbsteward.fatal("dbname not specified") } if len(args.DbUser) == 0 { - dbsteward.Fatal("dbuser not specified") + dbsteward.fatal("dbuser not specified") } if args.DbPassword == nil { p, err := util.PromptPassword("[DBSteward] Enter password for postgres://%s@%s:%d/%s: ", args.DbUser, args.DbHost, args.DbPort, args.DbName) @@ -222,7 +222,7 @@ func (dbsteward *DBSteward) ArgParse() { } if mode == ModeExtract || mode == ModeSqlDiff { if len(args.OutputFile) == 0 { - dbsteward.Fatal("output file not specified") + dbsteward.fatal("output file not specified") } } if mode == ModeXmlSlonyId { @@ -230,14 +230,14 @@ func (dbsteward *DBSteward) ArgParse() { if args.SlonyIdIn[0] == args.SlonyIdOut { // TODO(go,nth) resolve filepaths to do this correctly // TODO(go,nth) check all SlonyIdIn elements - dbsteward.Fatal("slonyidin and slonyidout file paths should not be the same") + dbsteward.fatal("slonyidin and slonyidout file paths should not be the same") } } } if len(args.OutputDir) > 0 { if !util.IsDir(args.OutputDir) { - dbsteward.Fatal("outputdir is not a directory, must be a writable directory") + dbsteward.fatal("outputdir is not a directory, must be a writable directory") } dbsteward.fileOutputDirectory = args.OutputDir } @@ -245,12 +245,12 @@ func (dbsteward *DBSteward) ArgParse() { if args.XmlCollectDataAddendums > 0 { if mode != ModeDbDataDiff { - dbsteward.Fatal("--xmlcollectdataaddendums is only supported for fresh builds") + dbsteward.fatal("--xmlcollectdataaddendums is only supported for fresh builds") } // dammit go // invalid operation: args.XmlCollectDataAddendums > len(args.XmlFiles) (mismatched types uint and int) if int(args.XmlCollectDataAddendums) > len(args.XmlFiles) { - dbsteward.Fatal("Cannot collect more data addendums than files provided") + dbsteward.fatal("Cannot collect more data addendums than files provided") } } @@ -295,7 +295,7 @@ func (dbsteward *DBSteward) ArgParse() { case ModeSlonyDiff: dbsteward.doSlonyDiff(args.SlonyDiffOld, args.SlonyDiffNew) default: - dbsteward.Fatal("No operation specified") + dbsteward.fatal("No operation specified") } } @@ -310,7 +310,7 @@ func (dbsteward *DBSteward) Logger() *slog.Logger { return dbsteward.slogLogger } -func (dbsteward *DBSteward) Fatal(s string, args ...interface{}) { +func (dbsteward *DBSteward) fatal(s string, args ...interface{}) { dbsteward.logger.Fatal().Msgf(s, args...) } func (dbsteward *DBSteward) fatalIfError(err error, s string, args ...interface{}) { @@ -319,20 +319,10 @@ func (dbsteward *DBSteward) fatalIfError(err error, s string, args ...interface{ } } -func (dbsteward *DBSteward) Warning(s string, args ...interface{}) { +func (dbsteward *DBSteward) warning(s string, args ...interface{}) { dbsteward.logger.Warn().Msgf(s, args...) } -func (dbsteward *DBSteward) Error(s string, args ...interface{}) { - dbsteward.logger.Error().Msgf(s, args...) -} - -func (dbsteward *DBSteward) ErrorIfError(err error, s string, args ...interface{}) { - if err != nil { - dbsteward.logger.Error().Err(err).Msgf(s, args...) - } -} - func (dbsteward *DBSteward) Info(s string, args ...interface{}) { dbsteward.logger.Info().Msgf(s, args...) } @@ -382,7 +372,7 @@ func (dbsteward *DBSteward) reconcileSqlFormat(target, requested ir.SqlFormat) i return target } - dbsteward.Warning("XML is targeted for %s but you are forcing %s. Things will probably break!", target, requested) + dbsteward.warning("XML is targeted for %s but you are forcing %s. Things will probably break!", target, requested) return requested } @@ -411,7 +401,7 @@ func (dbsteward *DBSteward) defineSqlFormatDefaultValues(SqlFormat ir.SqlFormat, if SqlFormat != ir.SqlFormatPgsql8 { if len(args.PgDataXml) > 0 { - dbsteward.Fatal("pgdataxml parameter is not supported by %s driver", SqlFormat) + dbsteward.fatal("pgdataxml parameter is not supported by %s driver", SqlFormat) } } } @@ -445,19 +435,19 @@ func (dbsteward *DBSteward) doXmlDataInsert(defFile string, dataFile string) { dataRows := dataTable.Rows if dataRows == nil { - dbsteward.Fatal("table %s in %s does not have a element", dataTable.Name, dataFile) + dbsteward.fatal("table %s in %s does not have a element", dataTable.Name, dataFile) } if len(dataRows.Columns) == 0 { - dbsteward.Fatal("Unexpected: no rows[columns] found in table %s in file %s", dataTable.Name, dataFile) + dbsteward.fatal("Unexpected: no rows[columns] found in table %s in file %s", dataTable.Name, dataFile) } if len(dataRows.Rows) > 1 { - dbsteward.Fatal("Unexpected: more than one rows->row found in table %s in file %s", dataTable.Name, dataFile) + dbsteward.fatal("Unexpected: more than one rows->row found in table %s in file %s", dataTable.Name, dataFile) } if len(dataRows.Rows[0].Columns) != len(dataRows.Columns) { - dbsteward.Fatal("Unexpected: Table %s in %s defines %d colums but has %d elements", + dbsteward.fatal("Unexpected: Table %s in %s defines %d colums but has %d elements", dataTable.Name, dataFile, len(dataRows.Columns), len(dataRows.Rows[0].Columns)) } diff --git a/lib/loghandler.go b/lib/loghandler.go index 8554d8e..4d4d0d4 100644 --- a/lib/loghandler.go +++ b/lib/loghandler.go @@ -67,7 +67,7 @@ func (h *logHandler) Handle(ctx context.Context, r slog.Record) error { default: // Should be Error, but in case other levels get define at // least nothing gets lost - h.dbsteward.Error(msg) + h.dbsteward.logger.Error().Msgf(msg) } h.output.Reset() return nil