This repository was archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Added support for logging in JSON format to a file. #20
Merged
markxnelson
merged 2 commits into
oracle:master
from
NickWemekamp:weblogic-json-logging
Nov 29, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
# turn off the elasticsearch output | ||
weblogicLoggingExporterEnabled: false | ||
|
||
# configure json logging output | ||
writeToFileEnabled: true | ||
# %g is necessary for rollback of log files. | ||
outputFile: '/var/log/oracle/json-logging%g.log' | ||
# Max open files | ||
maxRollbackFiles: 3 | ||
# Max file size in bytes, this is 50 MB | ||
maxFileSize: 52428800 | ||
# Should the log file be appended to when the new logger is created | ||
appendToFile: true | ||
# Optional configuration for specifying which levels get logged to the json log file. | ||
# fileLoggingLogLevel: INFO |
This file contains hidden or 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
55 changes: 55 additions & 0 deletions
55
src/main/java/weblogic/logging/exporter/WebLogicLogFormatter.java
This file contains hidden or 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,55 @@ | ||
package weblogic.logging.exporter; | ||
|
||
import co.elastic.logging.jul.EcsFormatter; | ||
import org.slf4j.MDC; | ||
import weblogic.logging.WLLogRecord; | ||
|
||
import java.util.logging.LogRecord; | ||
|
||
public class WebLogicLogFormatter extends EcsFormatter { | ||
public static final String FIELDS_MESSAGE_ID = "fields.messageID"; | ||
public static final String FIELDS_SERVER_NAME = "fields.serverName"; | ||
public static final String FIELDS_USER_ID = "fields.userId"; | ||
public static final String FIELDS_SUB_SYSTEM = "fields.subSystem"; | ||
public static final String FIELDS_MACHINE_NAME = "fields.machineName"; | ||
public static final String FIELDS_TRANSACTION_ID = "fields.transactionId"; | ||
public static final String FIELDS_DIAGNOSTIC_CONTEXT_ID = "fields.diagnosticContextId"; | ||
public static final String FIELDS_SEQUENCE_NUMBER = "fields.sequenceNumber"; | ||
public static final String FIELDS_DOMAIN_UID = "fields.domainUID"; | ||
|
||
private final String domainUID; | ||
|
||
public WebLogicLogFormatter(String domainUID) { | ||
this.domainUID = domainUID; | ||
} | ||
|
||
@Override | ||
public String format(final LogRecord record) { | ||
WLLogRecord wlLogRecord = (WLLogRecord) record; | ||
|
||
MDC.put(FIELDS_MESSAGE_ID, wlLogRecord.getId()); | ||
MDC.put(FIELDS_SERVER_NAME, wlLogRecord.getServerName()); | ||
MDC.put(FIELDS_USER_ID, wlLogRecord.getUserId()); | ||
MDC.put(FIELDS_SUB_SYSTEM, wlLogRecord.getSubsystem()); | ||
MDC.put(FIELDS_MACHINE_NAME, wlLogRecord.getMachineName()); | ||
MDC.put(FIELDS_TRANSACTION_ID, wlLogRecord.getTransactionId()); | ||
MDC.put(FIELDS_DIAGNOSTIC_CONTEXT_ID, wlLogRecord.getDiagnosticContextId()); | ||
MDC.put(FIELDS_SEQUENCE_NUMBER, String.valueOf(wlLogRecord.getSequenceNumber())); | ||
MDC.put(FIELDS_DOMAIN_UID, domainUID); | ||
|
||
String result = super.format(wlLogRecord); | ||
|
||
// Can't clear the whole MDC HashMap as there might be other records in there. | ||
MDC.remove(FIELDS_MESSAGE_ID); | ||
MDC.remove(FIELDS_SERVER_NAME); | ||
MDC.remove(FIELDS_USER_ID); | ||
MDC.remove(FIELDS_SUB_SYSTEM); | ||
MDC.remove(FIELDS_MACHINE_NAME); | ||
MDC.remove(FIELDS_TRANSACTION_ID); | ||
MDC.remove(FIELDS_DIAGNOSTIC_CONTEXT_ID); | ||
MDC.remove(FIELDS_SEQUENCE_NUMBER); | ||
MDC.remove(FIELDS_DOMAIN_UID); | ||
|
||
return result; | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@russgold, @marinakog, I'm not as familiar with the logging exporter code base. I'm guessing that we are using System.out.println for logging from the exporter because the Java logging system is being used for messages bridged from WebLogic, correct? Is it possible to structure this so that we can still use logging for the exporter's messages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with this code base at all, actually. And Huiling is the one who was testing this exporter, not Marina.