diff --git a/go.mod b/go.mod index ff28d6e..44a8969 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,8 @@ require ( github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4 // indirect github.com/acomagu/bufpipe v1.0.3 // indirect github.com/cloudflare/circl v1.1.0 // indirect - github.com/darklab8/darklab_goutils v0.3.2 // indirect + github.com/darklab8/go-typelog v0.3.2 // indirect + github.com/darklab8/go-utils v0.10.6 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/go-git/gcfg v1.5.0 // indirect diff --git a/go.sum b/go.sum index 9a2beb7..cf75812 100644 --- a/go.sum +++ b/go.sum @@ -13,10 +13,14 @@ github.com/cloudflare/circl v1.1.0 h1:bZgT/A+cikZnKIwn7xL2OBj012Bmvho/o6RpRvv3GK github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/darklab8/darklab_goutils v0.3.1 h1:R4mAGRKG6YOfoFk/OE0JCvVMKzMyQR1+DOzEVom9UXs= -github.com/darklab8/darklab_goutils v0.3.1/go.mod h1:sL2yFr77PquFePdB9tsTFzNYspyz+hkW3a3sVUjFyrU= -github.com/darklab8/darklab_goutils v0.3.2 h1:VRuICLmOh3TspmLqFeQ3If8Qkjno9gHh/qmajpU+UFg= -github.com/darklab8/darklab_goutils v0.3.2/go.mod h1:sL2yFr77PquFePdB9tsTFzNYspyz+hkW3a3sVUjFyrU= +github.com/darklab8/go-typelog v0.3.2 h1:LfQ4bUpKifNKZZFoAhrbasmpLhaXrjwnNL9GcquOy8w= +github.com/darklab8/go-typelog v0.3.2/go.mod h1:AwwOf3dkp/tpevHFNbkB+PbwlDrUUgO1CVFkEnj+q5w= +github.com/darklab8/go-utils v0.3.1 h1:R4mAGRKG6YOfoFk/OE0JCvVMKzMyQR1+DOzEVom9UXs= +github.com/darklab8/go-utils v0.3.1/go.mod h1:sL2yFr77PquFePdB9tsTFzNYspyz+hkW3a3sVUjFyrU= +github.com/darklab8/go-utils v0.3.2 h1:VRuICLmOh3TspmLqFeQ3If8Qkjno9gHh/qmajpU+UFg= +github.com/darklab8/go-utils v0.3.2/go.mod h1:sL2yFr77PquFePdB9tsTFzNYspyz+hkW3a3sVUjFyrU= +github.com/darklab8/go-utils v0.10.6 h1:BdBWa9b8uYJRDnf7C2A0GLXgCJwOAe96XIZ4uMTVE/M= +github.com/darklab8/go-utils v0.10.6/go.mod h1:sbbAj7uyQU+PZOOeI60gOdM+ji+k4at93EcdAfRJZsI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/interface_cli/actions/changelog/templates/template.go b/interface_cli/actions/changelog/templates/template.go index ea7c23e..2132b9e 100644 --- a/interface_cli/actions/changelog/templates/template.go +++ b/interface_cli/actions/changelog/templates/template.go @@ -10,7 +10,7 @@ import ( "text/template" "time" - "github.com/darklab8/darklab_goutils/goutils/utils" + "github.com/darklab8/go-utils/goutils/utils" ) type Templates struct { diff --git a/interface_cli/actions/commit_msg.go b/interface_cli/actions/commit_msg.go index 5263c00..391887f 100644 --- a/interface_cli/actions/commit_msg.go +++ b/interface_cli/actions/commit_msg.go @@ -9,9 +9,9 @@ import ( "os" "path/filepath" - "github.com/darklab8/darklab_goutils/goutils/logus_core" - "github.com/darklab8/darklab_goutils/goutils/utils" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_types" + "github.com/darklab8/go-utils/goutils/utils" + "github.com/darklab8/go-utils/goutils/utils/utils_logus" + "github.com/darklab8/go-utils/goutils/utils/utils_types" ) func CommmitMsg(args []string) { @@ -22,7 +22,7 @@ func CommmitMsg(args []string) { conf := settings.GetConfig() inputFile := utils_types.FilePath(filepath.Join(string(utils.GetProjectDir()), args[0])) - logus.Log.Debug("Received CommitFile", logus_core.FilePath(inputFile)) + logus.Log.Debug("Received CommitFile", utils_logus.FilePath(inputFile)) file, err := os.ReadFile(string(inputFile)) logus.Log.CheckFatal(err, "Could not read the file due to this error") diff --git a/interface_cli/actions/init.go b/interface_cli/actions/init.go index 041bdf9..51c85a5 100644 --- a/interface_cli/actions/init.go +++ b/interface_cli/actions/init.go @@ -7,7 +7,7 @@ import ( "fmt" "strings" - "github.com/darklab8/darklab_goutils/goutils/utils" + "github.com/darklab8/go-utils/goutils/utils" ) const ( diff --git a/interface_cli/actions/init_test.go b/interface_cli/actions/init_test.go index e681c49..9b77fdb 100644 --- a/interface_cli/actions/init_test.go +++ b/interface_cli/actions/init_test.go @@ -8,11 +8,11 @@ import ( "path/filepath" "testing" - "github.com/darklab8/darklab_goutils/goutils/utils" + "github.com/darklab8/go-utils/goutils/utils" ) func TestWriteCommentedConfig(t *testing.T) { - current_folder := utils.GetCurrrentFolder() + current_folder := utils.GetCurrentFolder() temp_data := filepath.Join(string(current_folder), "temp_data") err := os.MkdirAll(temp_data, os.ModePerm) logus.Log.CheckFatal(err, "failed to create temp_data folder") diff --git a/interface_cli/shared.go b/interface_cli/shared.go index 35d6bea..a734b51 100644 --- a/interface_cli/shared.go +++ b/interface_cli/shared.go @@ -4,7 +4,7 @@ import ( "autogit/settings/logus" "fmt" - "github.com/darklab8/darklab_goutils/goutils/logus_core" + "github.com/darklab8/go-typelog/typelog" "github.com/spf13/cobra" ) @@ -18,7 +18,7 @@ func (s *sharedFlags) Bind(Cmd *cobra.Command) { func (s *sharedFlags) Run() { if *(s.verboseLogging) { - logus.Log = logus_core.NewLogger(logus_core.LEVEL_DEBUG, false, false) + logus.Log = typelog.NewLogger("autogit", typelog.WithLogLevel(typelog.LEVEL_DEBUG)) } logus.Log.Debug(fmt.Sprintf("verbose=%t\n", *(s.verboseLogging))) } diff --git a/semanticgit/conventionalcommits/main.go b/semanticgit/conventionalcommits/main.go index 02a8807..b518ef8 100644 --- a/semanticgit/conventionalcommits/main.go +++ b/semanticgit/conventionalcommits/main.go @@ -9,7 +9,7 @@ import ( "fmt" "strings" - "github.com/darklab8/darklab_goutils/goutils/utils" + "github.com/darklab8/go-utils/goutils/utils" ) type ConventionalCommit struct { diff --git a/semanticgit/git/gitraw/gitraw.go b/semanticgit/git/gitraw/gitraw.go index 832e38b..dde2751 100644 --- a/semanticgit/git/gitraw/gitraw.go +++ b/semanticgit/git/gitraw/gitraw.go @@ -3,7 +3,7 @@ package gitraw import ( "autogit/settings/logus" - "github.com/darklab8/darklab_goutils/goutils/utils" + "github.com/darklab8/go-utils/goutils/utils" "github.com/go-git/go-git/v5" ) diff --git a/semanticgit/git/test_code.go b/semanticgit/git/test_code.go index 62c9ae4..dbda5ff 100644 --- a/semanticgit/git/test_code.go +++ b/semanticgit/git/test_code.go @@ -4,7 +4,7 @@ import ( "autogit/settings/logus" "fmt" - "github.com/darklab8/darklab_goutils/goutils/utils" + "github.com/darklab8/go-utils/goutils/utils" "github.com/go-git/go-billy/v5/memfs" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" diff --git a/semanticgit/main.go b/semanticgit/main.go index a6f0eef..f48ae22 100644 --- a/semanticgit/main.go +++ b/semanticgit/main.go @@ -14,7 +14,7 @@ import ( "autogit/settings/logus" "autogit/settings/types" - "github.com/darklab8/darklab_goutils/goutils/logus_core" + "github.com/darklab8/go-typelog/typelog" ) type SemanticGit struct { @@ -38,7 +38,7 @@ func (g *SemanticGit) GetCurrentVersion() *semvertype.SemVer { vers, err := semver.Parse(tag.Name) if err != nil { - logus.Log.Warn("failed to parse tag=", logus.TagName(tag.Name), logus_core.OptError(err)) + logus.Log.Warn("failed to parse tag=", logus.TagName(tag.Name), typelog.OptError(err)) return git.ShouldWeStopIteration(false) } diff --git a/settings/changelog.go b/settings/changelog.go index ef88f75..7ceea8e 100644 --- a/settings/changelog.go +++ b/settings/changelog.go @@ -5,7 +5,7 @@ import ( "autogit/semanticgit/conventionalcommits/conventionalcommitstype" "autogit/settings/logus" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_types" + "github.com/darklab8/go-utils/goutils/utils/utils_types" ) type ChangelogScheme struct { diff --git a/settings/envs/envs.go b/settings/envs/envs.go index c64e1ce..0f1fcaf 100644 --- a/settings/envs/envs.go +++ b/settings/envs/envs.go @@ -4,10 +4,8 @@ import ( "fmt" "os" "path/filepath" - "strings" - "github.com/darklab8/darklab_goutils/goutils/logus_core/logus_types" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_types" + "github.com/darklab8/go-utils/goutils/utils/utils_types" ) /* @@ -17,27 +15,10 @@ And autogit is able to run with correct settings only if run from project root TODO fix actually to detect root folder of it, then it will not be necessary value */ -var LogTurnJSONLogging bool -var LogShowFileLocations bool -var LogLevel logus_types.LogLevel - var PathUserHome utils_types.FilePath var PathGitConfig utils_types.FilePath -const ( - EnvTrue = "true" -) - func init() { - LogTurnJSONLogging = strings.ToLower(os.Getenv("AUTOGIT_LOG_JSON")) == EnvTrue - LogShowFileLocations = strings.ToLower(os.Getenv("AUTOGIT_LOG_SHOW_FILE_LOCATIONS")) == EnvTrue - - log_level_str, is_log_level_set := os.LookupEnv("AUTOGIT_LOG_LEVEL") - if !is_log_level_set { - log_level_str = "INFO" - } - LogLevel = logus_types.LogLevel(log_level_str) - PathUserHome = utils_types.FilePath(os.Getenv("HOME")) dirname, err := os.UserHomeDir() diff --git a/settings/logus/logger.go b/settings/logus/logger.go index 196d9ff..3264377 100644 --- a/settings/logus/logger.go +++ b/settings/logus/logger.go @@ -1,20 +1,7 @@ package logus -import ( - "autogit/settings/envs" - - "github.com/darklab8/darklab_goutils/goutils/logus_core" - "github.com/darklab8/darklab_goutils/goutils/logus_core/logus_types" -) +import "github.com/darklab8/go-typelog/typelog" var ( - Log *logus_core.Logger + Log *typelog.Logger = typelog.NewLogger("autogit") ) - -func init() { - - Log = logus_core.NewLogger( - logus_types.LogLevel(envs.LogLevel), - logus_types.EnableJsonFormat(envs.LogTurnJSONLogging), - logus_types.EnableFileShowing(envs.LogShowFileLocations)) -} diff --git a/settings/logus/params.go b/settings/logus/params.go index 3400567..9148d3b 100644 --- a/settings/logus/params.go +++ b/settings/logus/params.go @@ -5,79 +5,78 @@ import ( "autogit/semanticgit/semver/semvertype" "autogit/settings/types" "fmt" + "log/slog" "strconv" - "github.com/darklab8/darklab_goutils/goutils/logus_core" + "github.com/darklab8/go-typelog/typelog" "github.com/go-git/go-git/v5/plumbing" ) -func ConfigPath(value types.ConfigPath) logus_core.SlogParam { - return func(c *logus_core.SlogGroup) { - c.Params["config_path"] = string(value) - } +func ConfigPath(value types.ConfigPath) typelog.LogType { + return typelog.String("config_path", string(value)) } -func CommitHash(value plumbing.Hash) logus_core.SlogParam { - return func(c *logus_core.SlogGroup) { - c.Params["commit_hash"] = value.String() - } +func CommitHash(value plumbing.Hash) typelog.LogType { + return typelog.String("commit_hash", value.String()) } -func TagName(value types.TagName) logus_core.SlogParam { - return func(c *logus_core.SlogGroup) { - c.Params["tag_name"] = string(value) - } +func TagName(value types.TagName) typelog.LogType { + return typelog.String("tag_name", string(value)) } -func ProjectFolder(value types.ProjectFolder) logus_core.SlogParam { - return func(c *logus_core.SlogGroup) { - c.Params["project_folder"] = string(value) - } +func ProjectFolder(value types.ProjectFolder) typelog.LogType { + return typelog.String("project_folder", string(value)) } -func CommitMessage(value types.CommitOriginalMsg) logus_core.SlogParam { - return func(c *logus_core.SlogGroup) { - c.Params["commit_file"] = string(value) - } +func CommitMessage(value types.CommitOriginalMsg) typelog.LogType { + return typelog.String("commit_file", string(value)) } -func SettingsKey(value any) logus_core.SlogParam { - return func(c *logus_core.SlogGroup) { - c.Params["settings_key"] = fmt.Sprintf("%v", value) - } +func SettingsKey(value any) typelog.LogType { + return typelog.Any("settings_key", value) } -func Commit(commit conventionalcommitstype.ParsedCommit) logus_core.SlogParam { - return func(c *logus_core.SlogGroup) { - c.Params["commit_type"] = string(commit.Type) - c.Params["commit_scope"] = string(commit.Scope) - c.Params["commit_subject"] = string(commit.Subject) - c.Params["commit_body"] = string(commit.Body) - c.Params["commit_exlamation"] = strconv.FormatBool(commit.Exclamation) - c.Params["commit_hash"] = string(commit.Hash) +func Commit(commit conventionalcommitstype.ParsedCommit) typelog.LogType { + return func(c *typelog.LogAtrs) { + c.Append( + slog.String("commit_type", string(commit.Type)), + slog.String("commit_scope", string(commit.Scope)), + slog.String("commit_subject", string(commit.Subject)), + slog.String("commit_body", string(commit.Body)), + slog.String("commit_exlamation", strconv.FormatBool(commit.Exclamation)), + slog.String("commit_hash", string(commit.Hash)), + ) + for index, footer := range commit.Footers { // Should have made structured logging allowing nested dictionaries. // Using as work around more lazy option - c.Params[fmt.Sprintf("commit_footer_%d", index)] = fmt.Sprintf( - "token: %s, content: %s", - footer.Token, - footer.Content, + c.Append( + slog.String( + fmt.Sprintf("commit_footer_%d", index), + fmt.Sprintf( + "token: %s, content: %s", + footer.Token, + footer.Content, + ), + ), ) } for index, issue := range commit.Issue { // Should have made structured logging allowing nested dictionaries. // Using as work around more lazy option - c.Params[fmt.Sprintf("commit_issue_%d", index)] = string(issue) + c.Append( + slog.String(fmt.Sprintf("commit_issue_%d", index), string(issue)), + ) } } } -func Semver(semver *semvertype.SemVer) logus_core.SlogParam { - return func(c *logus_core.SlogGroup) { +func Semver(semver *semvertype.SemVer) typelog.LogType { + return func(c *typelog.LogAtrs) { if semver == nil { - c.Params["semver"] = "nil" + c.Append(slog.String("semver", "nil")) return } - c.Params["semver"] = string(semver.ToString()) + c.Append(slog.String("semver", string(semver.ToString()))) } } diff --git a/settings/regex.go b/settings/regex.go index 2efab06..e01b2c5 100644 --- a/settings/regex.go +++ b/settings/regex.go @@ -3,8 +3,8 @@ package settings import ( "regexp" - "github.com/darklab8/darklab_goutils/goutils/utils" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_types" + "github.com/darklab8/go-utils/goutils/utils" + "github.com/darklab8/go-utils/goutils/utils/utils_types" ) type RegexScheme struct { diff --git a/settings/settings.go b/settings/settings.go index 67d5420..1ec0fe4 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -14,8 +14,9 @@ import ( "strconv" "strings" - "github.com/darklab8/darklab_goutils/goutils/logus_core" - "github.com/darklab8/darklab_goutils/goutils/utils/utils_types" + "github.com/darklab8/go-typelog/typelog" + "github.com/darklab8/go-utils/goutils/utils/utils_logus" + "github.com/darklab8/go-utils/goutils/utils/utils_types" "gopkg.in/yaml.v3" ) @@ -71,10 +72,10 @@ func readSettingsfile(configPath types.ConfigPath) []byte { local_file_is_not_found := false if err != nil { if is_file_missing(err) { - logus.Log.Debug("not found at path repository local file with config. Fallback to global config", logus_core.FilePath(configPath.ToFilePath()), logus_core.OptError(err)) + logus.Log.Debug("not found at path repository local file with config. Fallback to global config", utils_logus.FilePath(configPath.ToFilePath()), typelog.OptError(err)) local_file_is_not_found = true } else { - logus.Log.CheckFatal(err, "Could not read the file due to error", logus.ConfigPath(configPath), logus_core.OptError(err)) + logus.Log.CheckFatal(err, "Could not read the file due to error", logus.ConfigPath(configPath), typelog.OptError(err)) } } else { logus.Log.Debug("succesfuly read config from local repository project path", logus.ConfigPath(configPath)) @@ -85,10 +86,10 @@ func readSettingsfile(configPath types.ConfigPath) []byte { file, err = os.ReadFile(string(GetGlobalConfigPath())) if err != nil { if is_file_missing(err) { - logus.Log.Debug("not found at path repository global file with config. Fallback to other in memory config", logus_core.FilePath(configPath.ToFilePath()), logus_core.OptError(err)) + logus.Log.Debug("not found at path repository global file with config. Fallback to other in memory config", utils_logus.FilePath(configPath.ToFilePath()), typelog.OptError(err)) global_file_is_not_found = true } else { - logus.Log.CheckFatal(err, "Could not read the file due to error", logus.ConfigPath(configPath), logus_core.OptError(err)) + logus.Log.CheckFatal(err, "Could not read the file due to error", logus.ConfigPath(configPath), typelog.OptError(err)) } } } diff --git a/settings/testutils/fixtures.go b/settings/testutils/fixtures.go index fa7a6e8..72deaf3 100644 --- a/settings/testutils/fixtures.go +++ b/settings/testutils/fixtures.go @@ -5,11 +5,11 @@ import ( "autogit/settings/types" "path/filepath" - "github.com/darklab8/darklab_goutils/goutils/utils" + "github.com/darklab8/go-utils/goutils/utils" ) func FixtureSettings() { - workdir := utils.GetCurrrentFolder() + workdir := utils.GetCurrentFolder() originalSettingsPath := workdir rootFolder := filepath.Dir(string(originalSettingsPath)) testSettingsPath := types.ConfigPath(filepath.Join(rootFolder, "settings", "autogit.example.yml")) diff --git a/settings/types/types.go b/settings/types/types.go index cd500c5..37e95dc 100644 --- a/settings/types/types.go +++ b/settings/types/types.go @@ -1,6 +1,6 @@ package types -import "github.com/darklab8/darklab_goutils/goutils/utils/utils_types" +import "github.com/darklab8/go-utils/goutils/utils/utils_types" type ConfigPath utils_types.FilePath