Moved package log to logging
This commit is contained in:
1 parent
da81e6ccd9
commit
dd26976f76
3 files changed
+13
-11
No files matched your search
@@ -19,23 +19,23 @@ package cli
|
||||
import (
|
||||
"log/slog"
|
||||
|
||||
"git.avsdev.uk/Go/job-search/internal/log"
|
||||
"git.avsdev.uk/Go/job-search/internal/logging"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func SetupIntialLogging(cmd *cobra.Command) {
|
||||
// Start logging to terminal first - any commands that want to use file
|
||||
// logging should activate it themselves
|
||||
log.LogToTerminal()
|
||||
logging.LogToTerminal()
|
||||
|
||||
// Check for quiet flag
|
||||
if quiet, _ := cmd.Flags().GetBool("quiet"); quiet {
|
||||
log.SetLevel(slog.LevelError)
|
||||
logging.SetLevel(slog.LevelError)
|
||||
}
|
||||
|
||||
// Check for debug logging enabled (overrides quiet flag)
|
||||
debugEnabled, _ := cmd.Flags().GetBool("debug")
|
||||
if debugEnabled {
|
||||
log.EnableDebug()
|
||||
logging.EnableDebug()
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"log/slog"
|
||||
|
||||
"git.avsdev.uk/Go/job-search/internal/config"
|
||||
"git.avsdev.uk/Go/job-search/internal/log"
|
||||
"git.avsdev.uk/Go/job-search/internal/logging"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -66,8 +66,8 @@ func (o *Options) RunSetup(
|
||||
}
|
||||
|
||||
// Change logging level based off newly loaded config
|
||||
if conf.Logging.LogLevel() <= slog.LevelDebug && !log.IsDebugEnabled() {
|
||||
log.EnableDebug()
|
||||
if conf.Logging.LogLevel() <= slog.LevelDebug && !logging.IsDebugEnabled() {
|
||||
logging.EnableDebug()
|
||||
}
|
||||
|
||||
// Check if the logging should be switched to file
|
||||
@@ -75,7 +75,7 @@ func (o *Options) RunSetup(
|
||||
if len(conf.Logging.File) == 0 {
|
||||
slog.Warn("No log file configured, remaining in console logging mode!")
|
||||
} else {
|
||||
log.LogToFile(conf.Logging.File)
|
||||
logging.LogToFile(conf.Logging.File)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,8 +85,8 @@ func (o *Options) RunSetup(
|
||||
|
||||
// Finish shuts down any open file logger
|
||||
func (o *Options) Finish() error {
|
||||
if log.IsFileLogger() {
|
||||
log.Shutdown()
|
||||
if logging.IsFileLogger() {
|
||||
logging.Shutdown()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -14,7 +14,7 @@ GNU Lesser General Public License for more details.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package log
|
||||
package logging
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
@@ -25,6 +25,8 @@ import (
|
||||
"github.com/lmittmann/tint"
|
||||
)
|
||||
|
||||
// ---------- Standard log handling (terminal or file based) ----------
|
||||
|
||||
var logLevel slog.LevelVar
|
||||
var fileLogger *os.File
|
||||
|
||||
Reference in new issue
Block a user