Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
IamTheFij | dd88246d86 | |
IamTheFij | f632b1c477 | |
IamTheFij | 902c397641 | |
IamTheFij | 7b1a0ac5f8 | |
IamTheFij | f79002168e | |
IamTheFij | eb305d5e40 | |
IamTheFij | 548575b4a7 | |
IamTheFij | 1744abb8b4 |
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
kind: pipeline
|
||||
name: test
|
||||
|
||||
steps:
|
||||
|
||||
- name: check
|
||||
image: iamthefij/drone-pre-commit:personal
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: notify
|
||||
|
||||
depends_on:
|
||||
- test
|
||||
|
||||
trigger:
|
||||
status:
|
||||
- failure
|
||||
|
||||
steps:
|
||||
|
||||
- name: notify
|
||||
image: drillster/drone-email
|
||||
settings:
|
||||
host:
|
||||
from_secret: SMTP_HOST # pragma: whitelist secret
|
||||
username:
|
||||
from_secret: SMTP_USER # pragma: whitelist secret
|
||||
password:
|
||||
from_secret: SMTP_PASS # pragma: whitelist secret
|
||||
from: drone@iamthefij.com
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.4.0
|
||||
rev: v3.4.0
|
||||
hooks:
|
||||
- id: check-added-large-files
|
||||
- id: trailing-whitespace
|
||||
|
@ -12,5 +12,4 @@ repos:
|
|||
hooks:
|
||||
- id: go-fmt
|
||||
- id: go-imports
|
||||
# - id: gometalinter
|
||||
# - id: golangci-lint
|
||||
- id: golangci-lint
|
||||
|
|
50
README.md
50
README.md
|
@ -22,33 +22,51 @@ Also provided are a few simple methods for handling returned `error` variables,
|
|||
var (
|
||||
// DebugLevel indicates if we should log at the debug level
|
||||
DebugLevel = true
|
||||
|
||||
// LoggerInfo is the slog Info logger
|
||||
LoggerInfo = log.New(os.Stderr, "INFO ", defaultFlags)
|
||||
// LoggerWarning is the slog Warning logger
|
||||
LoggerWarning = log.New(os.Stderr, "WARNING ", defaultFlags)
|
||||
// LoggerError is the slog Error logger
|
||||
LoggerError = log.New(os.Stderr, "ERROR ", defaultFlags)
|
||||
// LoggerDebug is the slog Debug logger
|
||||
LoggerDebug = log.New(os.Stderr, "DEBUG ", defaultFlags)
|
||||
)
|
||||
|
||||
FUNCTIONS
|
||||
|
||||
func Debug(format string, v ...interface{})
|
||||
Debug will log with a DEBUG prefix if DebugLevel is se
|
||||
func Debugf(format string, v ...interface{})
|
||||
Debugf will log with a DEBUG prefix if DebugLevel is se
|
||||
|
||||
func Error(format string, v ...interface{})
|
||||
Error will log with a ERROR prefix
|
||||
func Errorf(format string, v ...interface{})
|
||||
Errorf will log with a ERROR prefix
|
||||
|
||||
func FatalOnErr(err error, format string, v ...interface{})
|
||||
FatalOnErr if error provided, will log out details of an error and exi
|
||||
func Fatalf(format string, v ...interface{})
|
||||
Fatalf will log with a ERROR prefix followed by exit(1)
|
||||
|
||||
func Info(format string, v ...interface{})
|
||||
Info formats logs with an INFO prefix
|
||||
func Infof(format string, v ...interface{})
|
||||
Infof formats logs with an INFO prefix
|
||||
|
||||
func Log(format string, v ...interface{})
|
||||
Log formats logs directly to the main logger
|
||||
func Logf(format string, v ...interface{})
|
||||
Logf formats logs directly to the main logger
|
||||
|
||||
func PanicOnErr(err error, format string, v ...interface{})
|
||||
PanicOnErr if error provided, will log out details of an error and exi
|
||||
func OnErrFatalf(err error, format string, v ...interface{})
|
||||
OnErrFatalf if error provided, will log out details of an error and exi
|
||||
|
||||
func OnErrPanicf(err error, format string, v ...interface{})
|
||||
OnErrPanicf if error provided, will log out details of an error and exi
|
||||
|
||||
func OnErrWarnf(err error, format string, v ...interface{})
|
||||
OnErrWarnf if error provided, will provide a warning if an error is provided
|
||||
|
||||
func Panicf(format string, v ...interface{})
|
||||
Panicf will log with a ERROR prefix followed by panic()
|
||||
|
||||
func SetFlags(flag int)
|
||||
SetFlags allows changing the logger flags using flags found in `log`
|
||||
|
||||
func WarnOnErr(err error, format string, v ...interface{})
|
||||
WarnOnErr if error provided, will provide a warning if an error is provided
|
||||
func SetOutput(w io.Writer)
|
||||
SetOutput allows changing the output of all loggers
|
||||
|
||||
func Warning(format string, v ...interface{})
|
||||
Warning will log with a WARNING prefix
|
||||
func Warningf(format string, v ...interface{})
|
||||
Warningf will log with a WARNING prefix
|
||||
|
|
81
slog.go
81
slog.go
|
@ -4,6 +4,7 @@
|
|||
package slog
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
@ -25,66 +26,86 @@ var (
|
|||
LoggerError = log.New(os.Stderr, "ERROR ", defaultFlags)
|
||||
// LoggerDebug is the slog Debug logger
|
||||
LoggerDebug = log.New(os.Stderr, "DEBUG ", defaultFlags)
|
||||
)
|
||||
|
||||
// SetFlags allows changing the logger flags using flags found in `log`
|
||||
func SetFlags(flag int) {
|
||||
for _, logger := range []*log.Logger{
|
||||
allLoggers = []*log.Logger{
|
||||
LoggerInfo,
|
||||
LoggerWarning,
|
||||
LoggerError,
|
||||
LoggerDebug,
|
||||
} {
|
||||
}
|
||||
)
|
||||
|
||||
// SetFlags allows changing the logger flags using flags found in `log`
|
||||
func SetFlags(flag int) {
|
||||
for _, logger := range allLoggers {
|
||||
logger.SetFlags(flag)
|
||||
}
|
||||
}
|
||||
|
||||
// Log formats logs directly to the main logger
|
||||
func Log(format string, v ...interface{}) {
|
||||
// SetOutput allows changing the output of all loggers
|
||||
func SetOutput(w io.Writer) {
|
||||
for _, logger := range allLoggers {
|
||||
logger.SetOutput(w)
|
||||
}
|
||||
}
|
||||
|
||||
// Logf formats logs directly to the main logger
|
||||
func Logf(format string, v ...interface{}) {
|
||||
log.Printf(format, v...)
|
||||
}
|
||||
|
||||
// Info formats logs with an INFO prefix
|
||||
func Info(format string, v ...interface{}) {
|
||||
LoggerInfo.Printf(format, v...)
|
||||
}
|
||||
|
||||
// Warning will log with a WARNING prefix
|
||||
func Warning(format string, v ...interface{}) {
|
||||
LoggerWarning.Printf(format, v...)
|
||||
}
|
||||
|
||||
// Error will log with a ERROR prefix
|
||||
func Error(format string, v ...interface{}) {
|
||||
LoggerError.Printf(format, v...)
|
||||
}
|
||||
|
||||
// Debug will log with a DEBUG prefix if DebugLevel is set
|
||||
func Debug(format string, v ...interface{}) {
|
||||
// Debugf will log with a DEBUG prefix if DebugLevel is set
|
||||
func Debugf(format string, v ...interface{}) {
|
||||
if !DebugLevel {
|
||||
return
|
||||
}
|
||||
|
||||
LoggerDebug.Printf(format, v...)
|
||||
}
|
||||
|
||||
// WarnOnErr if error provided, will provide a warning if an error is provided
|
||||
func WarnOnErr(err error, format string, v ...interface{}) {
|
||||
// Infof formats logs with an INFO prefix
|
||||
func Infof(format string, v ...interface{}) {
|
||||
LoggerInfo.Printf(format, v...)
|
||||
}
|
||||
|
||||
// Warningf will log with a WARNING prefix
|
||||
func Warningf(format string, v ...interface{}) {
|
||||
LoggerWarning.Printf(format, v...)
|
||||
}
|
||||
|
||||
// Errorf will log with a ERROR prefix
|
||||
func Errorf(format string, v ...interface{}) {
|
||||
LoggerError.Printf(format, v...)
|
||||
}
|
||||
|
||||
// Fatalf will log with a ERROR prefix followed by exit(1)
|
||||
func Fatalf(format string, v ...interface{}) {
|
||||
LoggerError.Fatalf(format, v...)
|
||||
}
|
||||
|
||||
// Panicf will log with a ERROR prefix followed by panic()
|
||||
func Panicf(format string, v ...interface{}) {
|
||||
LoggerError.Panicf(format, v...)
|
||||
}
|
||||
|
||||
// OnErrWarnf if error provided, will provide a warning if an error is provided
|
||||
func OnErrWarnf(err error, format string, v ...interface{}) {
|
||||
if err != nil {
|
||||
LoggerWarning.Printf(format, v...)
|
||||
LoggerError.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
// FatalOnErr if error provided, will log out details of an error and exit
|
||||
func FatalOnErr(err error, format string, v ...interface{}) {
|
||||
// OnErrFatalf if error provided, will log out details of an error and exit
|
||||
func OnErrFatalf(err error, format string, v ...interface{}) {
|
||||
if err != nil {
|
||||
LoggerError.Printf(format, v...)
|
||||
LoggerError.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// PanicOnErr if error provided, will log out details of an error and exit
|
||||
func PanicOnErr(err error, format string, v ...interface{}) {
|
||||
// OnErrPanicf if error provided, will log out details of an error and exit
|
||||
func OnErrPanicf(err error, format string, v ...interface{}) {
|
||||
if err != nil {
|
||||
LoggerError.Printf(format, v...)
|
||||
LoggerError.Panic(err)
|
||||
|
|
Loading…
Reference in New Issue