Giter Site home page Giter Site logo

Comments (4)

sohlich avatar sohlich commented on June 11, 2024

This could be obvious but please share a code snipet how you log the errors? Or repo where you experiencing this.

from elogrus.

macnibblet avatar macnibblet commented on June 11, 2024

Configuration

	baseLogger := &logrus.Logger{
		Out:       os.Stderr,
		Hooks:     make(logrus.LevelHooks),
		Level:     logrus.DebugLevel,
		Formatter: &logrus.TextFormatter{},
	}

	logger = baseLogger.WithField("application", "encoder")

	services, _, err := consul.Catalog().Service("elasticsearch", "", &consulapi.QueryOptions{})
	if err != nil {
		logger.WithError(err).Fatal("Failed to retrieve elasticsearch")
	}

	if len(services) == 0 {
		logger.Warn("Elasticsearch not available in consul for logging")
		return
	}

	var addresses []string
	for _, service := range services {
		addresses = append(addresses, fmt.Sprintf("http://%s:%d", service.ServiceAddress, service.ServicePort))
	}

	client, err := elastic.NewClient(elastic.SetURL(addresses...))
	if err != nil {
		logger.WithError(err).Fatal("Failed to construct elasticsearch client")
	}

	hook, err := elogrus.NewElasticHook(client, getHostname(), logrus.DebugLevel, "logs")
	if err != nil {
		logger.WithError(err).Fatal("Failed to create elasticsearch hook for logger")
	}

	baseLogger.Hooks.Add(hook)

Catching a random error

err := errors.New("hello world")
err2 := errors.Wra(err, "Wrapping previous error")

logger.WithError(err2).Error("Failed to handle invalid api response")

from elogrus.

sohlich avatar sohlich commented on June 11, 2024

I've stringified the error field:

{
"_index": "errorlog",
"_type": "log",
"_id": "AVuZIRPrwfM22V5jPxNV",
"_score": null,
"_source": {
"Host": "localhost",
"@timestamp": "2017-04-23T04:45:33.544389772Z",
"Message": "Failed to handle invalid api response",
"Data": {
"error": "This is error"
},
"Level": "ERROR"
},
"fields": {
"@timestamp": [
1492922733544
]
},
"sort": [
1492922733544
]
}

from elogrus.

macnibblet avatar macnibblet commented on June 11, 2024

awesome! thanks

from elogrus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.