Comments (4)
This could be obvious but please share a code snipet how you log the errors? Or repo where you experiencing this.
from elogrus.
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.
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.
awesome! thanks
from elogrus.
Related Issues (20)
- Push new tag for the current code HOT 1
- Elastic 6.0 support HOT 4
- go get error from gopkg.in HOT 3
- New Trace log level in logrus HOT 2
- logrus's SetReportCaller invalid in elogrus HOT 3
- I'd like to add a mechanism for keeping track of the async hooks
- Hostname in log is getting saved with the credentials
- Elasticsearch 7.0 support HOT 2
- Build Fail in README example code HOT 2
- Can i set username and password for my elasticsearch hosting ? HOT 2
- Apply for the maintainer HOT 1
- Report Caller missing HOT 5
- How do I modify index dynamically?
- missing Tracelevel from v7.0.0 version
- Unable to log to self defined index
- Mapping types deprecated in Elastic v8 HOT 2
- no active connection found: no Elasticsearch node available HOT 1
- remove github.com module path from pkg.go.dev
- Fields are not compatible with ECS
- Elasticsearch 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elogrus.