-
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.
- Loading branch information
Showing
11 changed files
with
521 additions
and
128 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
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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/airenas/go-app/pkg/goapp" | ||
) | ||
|
||
func main() { | ||
goapp.StartWithDefault() | ||
|
||
goapp.Log.Debug("Now will be printing: Hello world") | ||
goapp.Log.Info("Hello world!") | ||
goapp.Log.Debug().Msg("Now will be printing: Hello world") | ||
goapp.Log.Info().Msg("Hello world!") | ||
goapp.Log.Error().Err(fmt.Errorf("Ops")).Send() | ||
} |
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 |
---|---|---|
@@ -1,35 +1,35 @@ | ||
module github.com/airenas/go-app | ||
|
||
go 1.17 | ||
go 1.18 | ||
|
||
require ( | ||
github.com/heralight/logrus_mate v1.0.1 | ||
github.com/pkg/errors v0.9.1 | ||
github.com/sirupsen/logrus v1.8.1 | ||
github.com/spf13/viper v1.10.1 | ||
github.com/stretchr/testify v1.7.1 | ||
github.com/rs/zerolog v1.28.0 | ||
github.com/spf13/viper v1.14.0 | ||
github.com/stretchr/testify v1.8.1 | ||
) | ||
|
||
require ( | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.16 // indirect | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/fsnotify/fsnotify v1.5.1 // indirect | ||
github.com/gogap/env_json v0.0.0-20150503135429-86150085ddbe // indirect | ||
github.com/gogap/env_strings v0.0.1 // indirect | ||
github.com/fsnotify/fsnotify v1.6.0 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/heirko/go-contrib v0.0.0-20200825160048-11fc5e2235fa | ||
github.com/hoisie/redis v0.0.0-20160730154456-b5c6e81454e0 // indirect | ||
github.com/magiconair/properties v1.8.5 // indirect | ||
github.com/mitchellh/mapstructure v1.4.3 // indirect | ||
github.com/pelletier/go-toml v1.9.4 // indirect | ||
github.com/magiconair/properties v1.8.6 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/pelletier/go-toml v1.9.5 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.5 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/spf13/afero v1.6.0 // indirect | ||
github.com/spf13/cast v1.4.1 // indirect | ||
github.com/spf13/afero v1.9.2 // indirect | ||
github.com/spf13/cast v1.5.0 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/subosito/gotenv v1.2.0 // indirect | ||
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
gopkg.in/ini.v1 v1.66.2 // indirect | ||
github.com/subosito/gotenv v1.4.1 // indirect | ||
golang.org/x/sys v0.2.0 // indirect | ||
golang.org/x/text v0.4.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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 |
---|---|---|
@@ -1,42 +1,27 @@ | ||
package goapp | ||
|
||
import ( | ||
"github.com/heirko/go-contrib/logrusHelper" | ||
"github.com/heralight/logrus_mate" | ||
"github.com/sirupsen/logrus" | ||
"strings" | ||
|
||
"github.com/rs/zerolog" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
//Log is applications logger | ||
var Log = logrus.New() | ||
var Log = log.Logger | ||
|
||
func initLog() { | ||
initDefaultLogConfig() | ||
c := logrusHelper.UnmarshalConfiguration(Config.Sub("logger")) | ||
initLogFromEnv(&c) | ||
err := logrusHelper.SetConfig(Log, c) | ||
if err != nil { | ||
Log.Error("Can't init log ", err) | ||
} | ||
} | ||
|
||
//initLogFromEnv tries to set level from environment | ||
func initLogFromEnv(c *logrus_mate.LoggerConfig) { | ||
ll := Config.GetString("logger.level") | ||
if ll != "" { | ||
c.Level = ll | ||
sl := Config.GetString("logger.level") | ||
if sl == "" { | ||
sl = "info" | ||
} | ||
out := Config.GetString("logger.out.name") | ||
if out != "" { | ||
c.Out.Name = out | ||
l, err := zerolog.ParseLevel(strings.ToLower(sl)) | ||
if err != nil { | ||
Log.Error().Err(err).Msgf("can't parse %s", sl) | ||
} else { | ||
Log = log.Logger.Level(l).Output(zerolog.NewConsoleWriter()) | ||
} | ||
} | ||
|
||
func initDefaultLogConfig() { | ||
defaultLogConfig := map[string]interface{}{ | ||
"level": "info", | ||
"formatter.name": "text", | ||
"formatter.options.full_timestamp": true, | ||
"formatter.options.timestamp_format": "2006-01-02T15:04:05.000", | ||
if strings.ToLower(Config.GetString("logger.out")) == "console" { | ||
Log = log.Logger.Level(l).Output(zerolog.NewConsoleWriter(func(w *zerolog.ConsoleWriter) { w.TimeFormat = "2006-01-02T15:04:05.000" })) | ||
} | ||
Config.SetDefault("logger", defaultLogConfig) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
commit_count=$(shell git rev-list --count HEAD) | ||
|
||
version=v0.4.$(commit_count) | ||
version=v1.0.$(commit_count) |