From 0357d33cc103d207843b4efe45c75ce2b4ac71c6 Mon Sep 17 00:00:00 2001 From: Francis Date: Wed, 27 Dec 2023 20:15:22 +0000 Subject: [PATCH 1/4] Deployment isnt part of the tool so removed from readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 58b5707..1edd79c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # MageComm CLI Tool -MageComm CLI is a command line tool for managing Magento applications. It provides a convenient way to execute restricted magerun commands, manage deployments, and cat specific files within an archive. -The main use case for this tool is to provide a way to execute magerun commands in a controlled manner via a messaging service. This allows us to execute commands on a remote server without exposing the application server itself +MageComm CLI is a command line tool for managing Magento applications. It provides a convenient way to execute restricted magerun commands, and cat specific files within an archive. +The main use case for this tool is to provide a way to execute magerun commands in a controlled manner via a messaging service. This allows us to execute commands on a remote server without exposing the application server. *It is important to note that the environment configuration/env is important to set if you plan to use this tool in a shared rmq/sqs instance as this will prefix your queues to avoid cross communication* From 516782245c3d32c80b75a478cdfaa94d1c3e19ea Mon Sep 17 00:00:00 2001 From: Francis Date: Wed, 27 Dec 2023 20:18:41 +0000 Subject: [PATCH 2/4] Format broken examples --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1edd79c..7f751f3 100644 --- a/README.md +++ b/README.md @@ -124,9 +124,9 @@ example config.json: e.g `magecomm --debug listen` `magecomm --debug magerun cache:clean` -`magecomm --debug cat path/to/archive.tar.gz /path/to/file.txt` -`magecomm --config=/custom/config/path.json magerun indexer:status` -`magecomm --config=/custom/config/path.json --debug magerun indexer:reindex` +`magecomm --debug cat path/to/archive.tar.gz /path/to/file.txt` +`magecomm --config=/custom/config/path.json magerun indexer:status` +`magecomm --config=/custom/config/path.json --debug magerun indexer:reindex` ### Commands From ba34b51a2266490cf20f9cd06812ee1426e42797 Mon Sep 17 00:00:00 2001 From: Francis Gallagher Date: Tue, 19 Mar 2024 15:47:36 +0000 Subject: [PATCH 3/4] fix: Ensure logrus always has the right logfile before logging --- logger/logger.go | 80 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/logger/logger.go b/logger/logger.go index 4cdf895..8fb3090 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -21,6 +21,7 @@ const ( var ( Log *logrus.Logger + LogFile string debugFlagSet bool ) @@ -56,6 +57,7 @@ func ConfigureLogPath(logFile string) { FullTimestamp: true, }) Log.SetOutput(file) + LogFile = logFile Log.Infof("Logging to file: %s", file.Name()) } @@ -93,58 +95,108 @@ func SetLogLevel(level string) { Log.Infof("Log level set to %s", logrusLevel) } +// Reapply log filepath to logrus logger to avoid log rotation issues +// Truthfully I cant be bothered making windows & unix compatible file descriptor checks as Log.Out is not updated, so this is will do for now +func logRotateHandler() { + if LogFile == "" { + return + } + file, _ := os.OpenFile(LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0755) + Log.SetOutput(file) +} + +func logWithLevel(level logrus.Level, args ...interface{}) { + logRotateHandler() + switch level { + case TraceLevel: + Log.Trace(args...) + case DebugLevel: + Log.Debug(args...) + case InfoLevel: + Log.Info(args...) + case WarnLevel: + Log.Warn(args...) + case ErrorLevel: + Log.Error(args...) + case FatalLevel: + Log.Fatal(args...) + case PanicLevel: + Log.Panic(args...) + } +} + +func logFormattedWithLevel(level logrus.Level, format string, args ...interface{}) { + logRotateHandler() + switch level { + case TraceLevel: + Log.Tracef(format, args...) + case DebugLevel: + Log.Debugf(format, args...) + case InfoLevel: + Log.Infof(format, args...) + case WarnLevel: + Log.Warnf(format, args...) + case ErrorLevel: + Log.Errorf(format, args...) + case FatalLevel: + Log.Fatalf(format, args...) + case PanicLevel: + Log.Panicf(format, args...) + } +} + func Trace(args ...interface{}) { - Log.Trace(args...) + logWithLevel(TraceLevel, args...) } func Debug(args ...interface{}) { - Log.Debug(args...) + logWithLevel(DebugLevel, args...) } func Info(args ...interface{}) { - Log.Info(args...) + logWithLevel(InfoLevel, args...) } func Warn(args ...interface{}) { - Log.Warn(args...) + logWithLevel(WarnLevel, args...) } func Error(args ...interface{}) { - Log.Error(args...) + logWithLevel(ErrorLevel, args...) } func Fatal(args ...interface{}) { - Log.Fatal(args...) + logWithLevel(FatalLevel, args...) } func Panic(args ...interface{}) { - Log.Panic(args...) + logWithLevel(PanicLevel, args...) } func Tracef(format string, args ...interface{}) { - Log.Tracef(format, args...) + logFormattedWithLevel(TraceLevel, format, args...) } func Debugf(format string, args ...interface{}) { - Log.Debugf(format, args...) + logFormattedWithLevel(DebugLevel, format, args...) } func Infof(format string, args ...interface{}) { - Log.Infof(format, args...) + logFormattedWithLevel(InfoLevel, format, args...) } func Warnf(format string, args ...interface{}) { - Log.Warnf(format, args...) + logFormattedWithLevel(WarnLevel, format, args...) } func Errorf(format string, args ...interface{}) { - Log.Errorf(format, args...) + logFormattedWithLevel(ErrorLevel, format, args...) } func Fatalf(format string, args ...interface{}) { - Log.Fatalf(format, args...) + logFormattedWithLevel(FatalLevel, format, args...) } func Panicf(format string, args ...interface{}) { - Log.Panicf(format, args...) + logFormattedWithLevel(PanicLevel, format, args...) } From 08d2e5dce561aecc4d605cc349c49ded56b417ab Mon Sep 17 00:00:00 2001 From: Francis Date: Tue, 19 Mar 2024 15:54:47 +0000 Subject: [PATCH 4/4] chore(main): release 0.1.13 --- CHANGELOG.md | 7 +++++++ version.txt | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 230ef74..d5997db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.1.13](https://github.com/furan917/MageComm/compare/v0.1.12...v0.1.13) (2024-03-19) + + +### Bug Fixes + +* Ensure logrus always has the right logfile before logging ([ba34b51](https://github.com/furan917/MageComm/commit/ba34b51a2266490cf20f9cd06812ee1426e42797)) + ## [0.1.12](https://github.com/furan917/MageComm/compare/v0.1.11...v0.1.12) (2023-11-27) diff --git a/version.txt b/version.txt index 15252c1..2e34396 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v0.1.12 ## x-release-please-version \ No newline at end of file +v0.1.13 ## x-release-please-version \ No newline at end of file