Comments (8)
Hi, You can always use getAdditonalFields().put(key, object). The additonalFields map is HashMap<String, Object> so you can put anything there. I've uploaded v0.9.1 with updated addField(String, Object) method.
Anton
from gelfj.
I just tried that, passing in a Long object. It still passes back a string in the gelf message, unless I'm missing something.
from gelfj.
Hi,
May I ask you to provide the scenario (sourcecode) to look at? Generated JSON looks correct to me. Are you seeing strings instead of numbers in the target Graylog instance?
Anton
from gelfj.
No, you are correct. when I formatted the gelf message and printed it to the console with msg.toJson(), it showed it as a string, (with quotes around it), "_abc":"123", but when I sent it to the graylog2 server, it was formatted as a number. Thanks for your patience.
from gelfj.
No problem, but for me even after msg.toJson() looks correct i.e. {"_abc":123}. Could you please check again an tell if you see different results. Together with addField() changes I've commited the GelfMessageTest which should ensure it works correct.
from gelfj.
I don't know what I saw this morning (maybe not enough caffeine yet, and I was seeing illusions) but a further test showed that binary numbers loaded to Additional Fields are not coming through to MongoDB as a binary.
My groovy test script:
import org.graylog2.GelfMessage
import org.graylog2.GelfSender
def gelf = new GelfMessage("CSV entry", "Long Message",
new Date(), '6')
gelf.setHost ('myHostname')
gelf.setFacility ('myFacility')
gelf.setFile('fileName')
gelf.setAdditonalFields(["source": "GET", "requestSizeBytes":325L])
println "Integer Class: " + gelf.getAdditonalFields()["requestSizeBytes"].class
printf "Gelf Msg: " + gelf.toJson()
def gelfSender = new GelfSender("10.16.35.205")
gelfSender.sendMessage(gelf)
gelfSender.close()
The output to stdout:
Integer Class: class java.lang.Long
Gelf Msg: {"timestamp":1317840852,"level":"6","host":"myHostname","_source":"GET","facility":"myFacility","_requestSizeBytes":325,"file":"fileName","full_message":"Long Message","short_message":"CSV entry","line":null,"version":"1.0"}
The information in the DB:
{ "_id" : ObjectId("4e8ca7d492ae5b46e962079e"), "gelf" : true, "version" : "1.0", "message" : "CSV entry", "full_message" : "Long Message", "file" : "fileName", "line" : -1, "host" : "myHostname", "facility" : "myFacility", "level" : 6, "timestamp" : 0, "_source" : "GET", "_requestSizeBytes" : "325", "created_at" : 1317840852, "deleted" : false, "streams" : [ ] }
As you can see, the internal field, "created_at", yields a binary number, but even though we passed in a "Long" object, the Additional Field, "_requestSizeBytes" contains a string.
from gelfj.
Hi, thanks a lot for sharing the code but unfortunately it looks like a Graylog2 problem. The produced JSON is correct, so if you convert it back. I'll try to reproduce and get back to you.
Anton
Edit: Typo
from gelfj.
Hi,
Completely forgot to update the issue. After all that was a Graylog2 problem, not a library problem.
Anton
from gelfj.
Related Issues (20)
- Please publish sources to maven central HOT 5
- regular jar also contains dependencies HOT 3
- GelfAppender does not support JSON message parsing into additional fields HOT 5
- Add context to gelf message? HOT 2
- problem with send log from log4j2 to graylog2 via gelfj
- GelfHandler does not implement Handler interface correctly
- Curly Braces around Position parameter String leads to exception in GelfHandler
- log4j method not found HOT 1
- Invalid timestamp HOT 11
- 1.1.15 causes "Invalid Bundle-ManfestVersion 1" in Karaf 4 HOT 2
- Support arrays HOT 2
- [question] Which build tool is recommended for this project?
- [need_help] graylog2 appender not send data to host:port. HOT 3
- Missing setter on GelfHandler for multiple additional fields
- NullPointerException if only amqp is defined
- [MacOsX] compilation fails both for master and v1.1.16 on OpenJDK v.11
- log4j:ERROR Error during sending GELF message. Error code: 11.
- is GELF J affected via log4j 2 vulnerability? HOT 2
- Gelf chunk message ID is not unique HOT 4
- Couldn't send message to graylog HOT 4
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 gelfj.