forked from jmartin82/mmock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jmartin82:master' into master
- Loading branch information
Showing
23 changed files
with
374 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
go-version: [1.21] | ||
|
||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build | ||
run: make test | ||
|
||
- name: Test with coverage | ||
run: make coverage | ||
|
||
- name: Upload coverage to Codecov | ||
run: bash <(curl -s https://codecov.io/bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ debug.test | |
data/* | ||
/vendor | ||
coverage.txt | ||
.github | ||
dist | ||
.vscode | ||
.idea |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package logger | ||
|
||
import ( | ||
"github.com/op/go-logging" | ||
"os" | ||
"strings" | ||
) | ||
|
||
var Log *logging.Logger | ||
|
||
func init() { | ||
var log = logging.MustGetLogger("initialization") | ||
var level logging.Level | ||
var format = logging.MustStringFormatter( | ||
`%{time:15:04:05.000} %{color}%{level:.6s} ▶%{color:reset} %{message}`, | ||
) | ||
|
||
var prebackend = logging.NewLogBackend(os.Stdout, "", 0) | ||
var formattedBackend = logging.NewBackendFormatter(prebackend, format) | ||
var backend = logging.AddModuleLevel(formattedBackend) | ||
|
||
logLevelEnv, ok := os.LookupEnv("LOG_LEVEL") | ||
|
||
if !ok || logLevelEnv == "" { | ||
log.Info("No LOG_LEVEL environment variable found, defaulting to INFO") | ||
level = logging.INFO | ||
} else { | ||
level, ok = ParseStringToLevel(logLevelEnv) | ||
if !ok { | ||
log.Errorf("Invalid log level: %s Defaulting to INFO", logLevelEnv) | ||
level = logging.INFO | ||
} else { | ||
log.Infof("Setting log level to: %s", strings.ToUpper(logLevelEnv)) | ||
} | ||
} | ||
|
||
backend.SetLevel(level, "mmock") | ||
logging.SetBackend(backend) | ||
|
||
Log = logging.MustGetLogger("mmock") | ||
log.Infof("Logger initialized with level: %s", strings.ToUpper(logging.GetLevel("mmock").String())) | ||
} | ||
|
||
var levelMap = map[string]logging.Level{ | ||
"CRITICAL": logging.CRITICAL, | ||
"ERROR": logging.ERROR, | ||
"WARNING": logging.WARNING, | ||
"NOTICE": logging.NOTICE, | ||
"INFO": logging.INFO, | ||
"DEBUG": logging.DEBUG, | ||
} | ||
|
||
func ParseStringToLevel(str string) (logging.Level, bool) { | ||
level, ok := levelMap[strings.ToUpper(str)] | ||
return level, ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.