Updates regarding moving to source.pztrn.name and dependencies bundling with golang/dep.

This commit is contained in:
2018-02-02 09:17:40 +05:00
parent e969b7018d
commit 14a19622bc
723 changed files with 251025 additions and 488 deletions

View File

@@ -0,0 +1 @@
*DS_Store*

30
vendor/source.pztrn.name/golibs/mogrus/Gopkg.lock generated vendored Normal file
View File

@@ -0,0 +1,30 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
name = "github.com/sirupsen/logrus"
packages = ["."]
revision = "d682213848ed68c0a260ca37d6dd5ace8423f5ba"
version = "v1.0.4"
[[projects]]
branch = "master"
name = "golang.org/x/crypto"
packages = ["ssh/terminal"]
revision = "3d37316aaa6bd9929127ac9a527abf408178ea7b"
[[projects]]
branch = "master"
name = "golang.org/x/sys"
packages = [
"unix",
"windows"
]
revision = "03467258950d845cd1877eab69461b98e8c09219"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "97f3cd8b7a00b2b98fe58f834cf0d2f2c840a89809d15b451fdde156324ba6b1"
solver-name = "gps-cdcl"
solver-version = 1

View File

@@ -0,0 +1,25 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
[[constraint]]
name = "github.com/sirupsen/logrus"
version = "1.0.4"

View File

@@ -0,0 +1,46 @@
# Mogrus
Logger thing built on top of github.com/sirupsen/logrus with ability to
create multiple loggers (e.g. console and file loggers) for one logger
instance.
The reason to create this handler was a need of logging things to both
console and, e.g., file, which is unsupported by logrus itself (you have
to create several loggers for each output).
## Example
```
package main
import (
// stdlib
"os"
// tools
"bitbucket.org/pztrn/mogrus"
)
func main() {
l := mogrus.New()
l.Initialize()
log := l.CreateLogger("helloworld")
log.CreateOutput("stdout", os.Stdout, true)
// File output.
file_output, err := os.Create("/tmp/hellorowld.log")
if err != nil {
log.Errorln("Failed to create file output:", err.Error())
}
log.CreateOutput("file /tmp/hellorowld.log", file_output, false)
log.Println("Starting log experiment tool...")
log.Debugln("Debug here!")
log.Infoln("This is INFO level")
log.Println("This is also INFO level.")
log.Warnln("This is WARN.")
log.Errorln("This is ERROR level.")
log.Fatalln("We will exit here.")
}
```

View File

@@ -0,0 +1,24 @@
package mogrus
// Mogrus is a logger package built on top of Logrus with extended
// (and kinda simplified) approach for multilogging.
//
// Example usage:
//
// TBF
//
// Output functions are splitted in three things:
// * ``Debug`` - simple debug printing
// * ``Debugf`` - debug printing with line formatting
// * ``Debugln`` - debug printing, same as Debug().
//
// It will try to resemble Logrus as much as possible.
//
// About functions.
//
// Info(f,ln) and Print(f,ln) doing same thing - logging to
// INFO log level.
//
// Be careful while using Fatal(f,ln) functions, because
// it will log only to first logger and then will os.Exit(1)!
// There is no guarantee what logger will be first ATM.

View File

@@ -0,0 +1,5 @@
package mogrus
func New() *MogrusLogger {
return &MogrusLogger{}
}

View File

@@ -0,0 +1,249 @@
package mogrus
import (
// stdlib
"io"
"strings"
"sync"
// github
"github.com/sirupsen/logrus"
)
type LoggerHandler struct {
// Logrus instances
instances map[string]*logrus.Logger
instancesMutex sync.Mutex
}
// Adds output for logger handler.
// This actually creates new Logrus's Logger instance and configure
// it to write to given writer.
// To configure debug level you should pass it's name as debugLvl.
// Valid values: "", "debug" (the default), "info", "warn", "error"
func (lh *LoggerHandler) CreateOutput(name string, writer io.Writer, colors bool, debugLvl string) {
// Formatter.
logrus_formatter := new(logrus.TextFormatter)
logrus_formatter.DisableTimestamp = false
logrus_formatter.FullTimestamp = true
logrus_formatter.QuoteEmptyFields = true
logrus_formatter.TimestampFormat = "2006-01-02 15:04:05.000000000"
if colors {
logrus_formatter.DisableColors = false
logrus_formatter.ForceColors = true
} else {
logrus_formatter.DisableColors = true
logrus_formatter.ForceColors = false
}
logrus_instance := logrus.New()
logrus_instance.Out = writer
// Defaulting to debug.
logrus_instance.Level = logrus.DebugLevel
if debugLvl == "info" {
logrus_instance.Level = logrus.InfoLevel
} else if debugLvl == "warn" {
logrus_instance.Level = logrus.WarnLevel
} else if debugLvl == "error" {
logrus_instance.Level = logrus.ErrorLevel
}
logrus_instance.Formatter = logrus_formatter
lh.instancesMutex.Lock()
lh.instances[name] = logrus_instance
for _, logger := range lh.instances {
logger.Debugln("Added new logger output:", name)
}
lh.instancesMutex.Unlock()
}
// Formats string by replacing "{{ var }}"'s with data from passed map.
func (lh *LoggerHandler) FormatString(data string, replacers map[string]string) string {
for k, v := range replacers {
data = strings.Replace(data, "{{ "+k+" }}", v, -1)
}
return data
}
// Initializes logger handler.
// It will only initializes LoggerHandler structure, see CreateOutput()
// for configuring output for this logger handler.
func (lh *LoggerHandler) Initialize() {
lh.instances = make(map[string]*logrus.Logger)
}
// Removes previously created output.
// If output isn't found - doing nothing.
func (lh *LoggerHandler) RemoveOutput(output_name string) {
lh.instancesMutex.Lock()
_, found := lh.instances[output_name]
if found {
delete(lh.instances, output_name)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Debug() function.
func (lh *LoggerHandler) Debug(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Debug(args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Debugf() function.
func (lh *LoggerHandler) Debugf(format string, args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Debugf(format, args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Debugln() function.
func (lh *LoggerHandler) Debugln(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Debugln(args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Error() function.
func (lh *LoggerHandler) Error(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Error(args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Errorf() function.
func (lh *LoggerHandler) Errorf(format string, args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Errorf(format, args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Errorln() function.
func (lh *LoggerHandler) Errorln(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Errorln(args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Fatal() function.
func (lh *LoggerHandler) Fatal(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Fatal(args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Fatalf() function.
func (lh *LoggerHandler) Fatalf(format string, args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Fatalf(format, args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Fatalln() function.
func (lh *LoggerHandler) Fatalln(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Fatalln(args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Info() function.
func (lh *LoggerHandler) Info(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Info(args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Infof() function.
func (lh *LoggerHandler) Infof(format string, args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Infof(format, args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Infoln() function.
func (lh *LoggerHandler) Infoln(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Infoln(args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Print() function.
func (lh *LoggerHandler) Print(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Print(args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Printf() function.
func (lh *LoggerHandler) Printf(format string, args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Printf(format, args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Println() function.
func (lh *LoggerHandler) Println(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Println(args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Warn() function.
func (lh *LoggerHandler) Warn(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Warn(args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Warnf() function.
func (lh *LoggerHandler) Warnf(format string, args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Warnf(format, args...)
}
lh.instancesMutex.Unlock()
}
// Proxy for Logrus's Logger.Warnln() function.
func (lh *LoggerHandler) Warnln(args ...interface{}) {
lh.instancesMutex.Lock()
for _, logger := range lh.instances {
logger.Warnln(args...)
}
lh.instancesMutex.Unlock()
}

View File

@@ -0,0 +1,23 @@
package mogrus
type MogrusLogger struct {
// Initialized loggers.
// Key is a name of logger.
loggers map[string]*LoggerHandler
}
// Creates new logger handler, adds it to list of known loggers and
// return it to caller.
// Note that logger handler will be "just initialized", to actually
// use it you should add output with LoggerHandler.CreateOutput().
func (ml *MogrusLogger) CreateLogger(name string) *LoggerHandler {
lh := &LoggerHandler{}
lh.Initialize()
ml.loggers[name] = lh
return lh
}
func (ml *MogrusLogger) Initialize() {
ml.loggers = make(map[string]*LoggerHandler)
}