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 (
|
import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
"git.avsdev.uk/Go/job-search/internal/log"
|
"git.avsdev.uk/Go/job-search/internal/logging"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetupIntialLogging(cmd *cobra.Command) {
|
func SetupIntialLogging(cmd *cobra.Command) {
|
||||||
// Start logging to terminal first - any commands that want to use file
|
// Start logging to terminal first - any commands that want to use file
|
||||||
// logging should activate it themselves
|
// logging should activate it themselves
|
||||||
log.LogToTerminal()
|
logging.LogToTerminal()
|
||||||
|
|
||||||
// Check for quiet flag
|
// Check for quiet flag
|
||||||
if quiet, _ := cmd.Flags().GetBool("quiet"); quiet {
|
if quiet, _ := cmd.Flags().GetBool("quiet"); quiet {
|
||||||
log.SetLevel(slog.LevelError)
|
logging.SetLevel(slog.LevelError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for debug logging enabled (overrides quiet flag)
|
// Check for debug logging enabled (overrides quiet flag)
|
||||||
debugEnabled, _ := cmd.Flags().GetBool("debug")
|
debugEnabled, _ := cmd.Flags().GetBool("debug")
|
||||||
if debugEnabled {
|
if debugEnabled {
|
||||||
log.EnableDebug()
|
logging.EnableDebug()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
"git.avsdev.uk/Go/job-search/internal/config"
|
"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"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -66,8 +66,8 @@ func (o *Options) RunSetup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Change logging level based off newly loaded config
|
// Change logging level based off newly loaded config
|
||||||
if conf.Logging.LogLevel() <= slog.LevelDebug && !log.IsDebugEnabled() {
|
if conf.Logging.LogLevel() <= slog.LevelDebug && !logging.IsDebugEnabled() {
|
||||||
log.EnableDebug()
|
logging.EnableDebug()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the logging should be switched to file
|
// Check if the logging should be switched to file
|
||||||
@@ -75,7 +75,7 @@ func (o *Options) RunSetup(
|
|||||||
if len(conf.Logging.File) == 0 {
|
if len(conf.Logging.File) == 0 {
|
||||||
slog.Warn("No log file configured, remaining in console logging mode!")
|
slog.Warn("No log file configured, remaining in console logging mode!")
|
||||||
} else {
|
} 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
|
// Finish shuts down any open file logger
|
||||||
func (o *Options) Finish() error {
|
func (o *Options) Finish() error {
|
||||||
if log.IsFileLogger() {
|
if logging.IsFileLogger() {
|
||||||
log.Shutdown()
|
logging.Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
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
|
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/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package log
|
package logging
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@@ -25,6 +25,8 @@ import (
|
|||||||
"github.com/lmittmann/tint"
|
"github.com/lmittmann/tint"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ---------- Standard log handling (terminal or file based) ----------
|
||||||
|
|
||||||
var logLevel slog.LevelVar
|
var logLevel slog.LevelVar
|
||||||
var fileLogger *os.File
|
var fileLogger *os.File
|
||||||
|
|
||||||
Reference in new issue
Block a user