forked from t0xa/gelfj
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolved issue t0xa#105: Added GelfLogRecord class. Class allows passing
custom fields to gelf messages
- Loading branch information
Showing
2 changed files
with
55 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.graylog2.logging; | ||
|
||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.LogRecord; | ||
|
||
public class GelfLogRecord extends LogRecord { | ||
private static final long serialVersionUID = 43242341L; | ||
private Map<String, Object> fields; | ||
|
||
public GelfLogRecord(Level level, String msg) { | ||
super(level, msg); | ||
} | ||
|
||
public void setField(String key, Object value) { | ||
if (fields == null) { | ||
fields = new LinkedHashMap<String, Object>(); | ||
} | ||
fields.put(key, value); | ||
} | ||
|
||
public Object getField(String key) { | ||
return fields != null ? fields.get(key) : null; | ||
} | ||
|
||
public Map<String, Object> getFields() { | ||
if (fields == null) { | ||
return Collections.emptyMap(); | ||
} | ||
return Collections.unmodifiableMap(fields); | ||
} | ||
} |