Skip to content

Commit

Permalink
Merge pull request #2548 from Cousjava/PAYARA-2612
Browse files Browse the repository at this point in the history
PAYARA-2612 removed underscore from field names in JSON Formatter
  • Loading branch information
Pandrex247 authored Mar 22, 2018
2 parents add5fe0 + 7ac9a52 commit 1b34688
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ fish.payara.enterprise.server.logging.PayaraNotificationFileHandler.rotationLimi
fish.payara.enterprise.server.logging.PayaraNotificationFileHandler.maxHistoryFiles=0
fish.payara.enterprise.server.logging.PayaraNotificationFileHandler.file=${com.sun.aas.instanceRoot}/logs/notification.log

fish.payara.deprecated.jsonlogformatter.underscoreprefix=false

#All log level details
com.sun.enterprise.server.logging.GFFileHandler.level=ALL
com.sun.enterprise.server.logging.SyslogHandler.level=ALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@
import org.jvnet.hk2.config.UnprocessedChangeEvents;

/**
* Reinitialzie the log manager using our logging.properties file.
* Reinitialise the log manager using our logging.properties file.
*
* @author Jerome Dochez
* @author Carla Mott
* @author Naman Mehta
*/

@Service
@RunLevel(InitRunLevel.VAL)
@Rank(Constants.IMPORTANT_RUN_LEVEL_SERVICE)
Expand Down Expand Up @@ -152,6 +151,8 @@ public class LogManagerService implements PostConstruct, PreDestroy, org.glassfi
String payaraNotificationLogRotationInTimeLimitInBytesDetail = "";
String payaraNotificationLogmaxHistoryFilesDetail = "";
String payaraNotificationLogCompressOnRotationDetail = "";

String payaraJsonUnderscorePrefix = "";

private static final String SERVER_LOG_FILE_PROPERTY = "com.sun.enterprise.server.logging.GFFileHandler.file";
private static final String HANDLER_PROPERTY = "handlers";
Expand Down Expand Up @@ -184,6 +185,12 @@ public class LogManagerService implements PostConstruct, PreDestroy, org.glassfi
private static final String PAYARA_NOTIFICATION_LOG_MAXHISTORY_FILES_PROPERTY = "fish.payara.enterprise.server.logging.PayaraNotificationFileHandler.maxHistoryFiles";
private static final String PAYARA_NOTIFICATION_LOG_COMPRESS_ON_ROTATION_PROPERTY = "fish.payara.enterprise.server.logging.PayaraNotificationFileHandler.compressOnRotation";

/**
* @deprecated for backwards compatibility pre-5.182
*/
@Deprecated
private static final String PAYARA_JSONLOGFORMATTER_UNDERSCORE="fish.payara.deprecated.jsonlogformatter.underscoreprefix";

final static String EXCLUDE_FIELDS_PROPERTY = "com.sun.enterprise.server.logging.GFFileHandler.excludeFields";
final static String MULTI_LINE_MODE_PROPERTY = "com.sun.enterprise.server.logging.GFFileHandler.multiLineMode";

Expand All @@ -207,10 +214,10 @@ public class LogManagerService implements PostConstruct, PreDestroy, org.glassfi

private LoggingOutputStream stderrOutputStream=null;

/*
Returns properties based on the DAS/Cluster/Instance
*/

/**
* Returns properties based on the DAS/Cluster/Instance
*/
@Override
public Map<String, String> getLoggingProperties() throws IOException {

Server targetServer = domain.getServerNamed(env.getInstanceName());
Expand All @@ -234,10 +241,10 @@ public Map<String, String> getLoggingProperties() throws IOException {
return props;
}

/*
Returns logging file to be monitor during server is running.
/**
* Returns logging file to be monitor during server is running.
*/

@Override
public File getLoggingFile() throws IOException {

File file = null;
Expand Down Expand Up @@ -271,6 +278,7 @@ public File getLoggingFile() throws IOException {
/**
* Initialize the loggers
*/
@Override
public void postConstruct() {

// if the system property is already set, we don't need to do anything
Expand Down Expand Up @@ -304,7 +312,7 @@ public void postConstruct() {
System.out.println("#!## LogManagerService.postConstruct : dest=" +dest);

if (!logging.exists()) {
LOGGER.log(Level.FINE, logging.getAbsolutePath() + " not found, creating new file from template.");
LOGGER.log(Level.FINE, "{0} not found, creating new file from template.", logging.getAbsolutePath());
FileUtils.copy(src, dest);
logging = new File(env.getConfigDirPath(), ServerEnvironmentImpl.kLoggingPropertiesFileName);
}
Expand Down Expand Up @@ -440,6 +448,8 @@ public void postConstruct() {
payaraNotificationLogRotationInTimeLimitInBytesDetail = props.get(PAYARA_NOTIFICATION_LOG_ROTATIONLIMITINBYTES_PROPERTY);
payaraNotificationLogmaxHistoryFilesDetail = props.get(PAYARA_NOTIFICATION_LOG_MAXHISTORY_FILES_PROPERTY);
payaraNotificationLogCompressOnRotationDetail = props.get(PAYARA_NOTIFICATION_LOG_COMPRESS_ON_ROTATION_PROPERTY);

payaraJsonUnderscorePrefix = props.get(PAYARA_JSONLOGFORMATTER_UNDERSCORE);

} catch (Exception e) {
LOGGER.log(Level.SEVERE, LogFacade.ERROR_APPLYING_CONF, e);
Expand Down Expand Up @@ -511,6 +521,7 @@ public void postConstruct() {
// finally listen to changes to the logging.properties file
if (logging != null) {
fileMonitoring.monitors(logging, new FileMonitoring.FileChangeListener() {
@Override
public void changed(File changedFile) {
synchronized (gfHandlers) {
try {
Expand Down Expand Up @@ -679,6 +690,7 @@ public void changed(File changedFile) {

}

@Override
public void deleted(File deletedFile) {
LOGGER.log(Level.WARNING, LogFacade.CONF_FILE_DELETED, deletedFile.getAbsolutePath());
}
Expand Down Expand Up @@ -767,6 +779,7 @@ public void generateAttributeChangeEvent(String property, String propertyDetail,
ucl.unprocessedTransactedEvents(b);
}

@Override
public void addHandler(Handler handler) {
Logger rootLogger = Logger.getLogger("");
if (rootLogger != null) {
Expand All @@ -779,6 +792,7 @@ public void addHandler(Handler handler) {
}


@Override
public void preDestroy() {
//destroy the handlers
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,12 @@
import org.jvnet.hk2.config.UnprocessedChangeEvent;
import org.jvnet.hk2.config.UnprocessedChangeEvents;


/**
* Created by IntelliJ IDEA.
* User: naman mehta
* Date: Oct 21, 2010
* Time: 11:48:20 AM
* To change this template use File | Settings | File Templates.
*/

/*
* Set Log Attributes Command
*
* Updates one or more loggers' attributes
*
*
* @author naman mehta
* @since 3.1
*/
@ExecuteOn({RuntimeType.DAS, RuntimeType.INSTANCE})
@TargetType({CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CONFIG})
Expand All @@ -103,7 +94,7 @@
})
public class SetLogAttributes implements AdminCommand {

private static final String LINE_SEP = System.getProperty("line.separator");
private static final String LINE_SEP = System.lineSeparator();
private static final String ROTATION_LIMIT_IN_BYTES = "com.sun.enterprise.server.logging.GFFileHandler.rotationLimitInBytes";
private static final String ROTATION_TIMELIMIT_IN_MINUTES = "com.sun.enterprise.server.logging.GFFileHandler.rotationTimelimitInMinutes";
private static final String PAYARA_NOTIFICATOIN_ROTATION_LIMIT_IN_BYTES = "fish.payara.enterprise.server.logging.PayaraNotificationFileHandler.rotationLimitInBytes";
Expand Down Expand Up @@ -172,14 +163,16 @@ public class SetLogAttributes implements AdminCommand {
"fish.payara.enterprise.server.logging.PayaraNotificationFileHandler.rotationOnDateChange",
PAYARA_NOTIFICATOIN_ROTATION_LIMIT_IN_BYTES,
"fish.payara.enterprise.server.logging.PayaraNotificationFileHandler.maxHistoryFiles",
"fish.payara.enterprise.server.logging.PayaraNotificationFileHandler.compressOnRotation"};
"fish.payara.enterprise.server.logging.PayaraNotificationFileHandler.compressOnRotation",
"fish.payara.deprecated.jsonlogformatter.underscoreprefix"};

final private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(SetLogLevel.class);

@Override
public void execute(AdminCommandContext context) {

final ActionReport report = context.getActionReport();
StringBuffer sbfSuccessMsg = new StringBuffer(LINE_SEP);
StringBuilder sbfSuccessMsg = new StringBuilder(LINE_SEP);
boolean success = false;
boolean invalidAttribute = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class JSONLogFormatter extends Formatter implements LogEventBroadcaster {
private static boolean RECORD_NUMBER_IN_KEY_VALUE = false;

private FormatterDelegate _delegate = null;

// Static Initialiser Block
static {
String logSource = System.getProperty(
Expand All @@ -104,8 +104,7 @@ public class JSONLogFormatter extends Formatter implements LogEventBroadcaster {
LOG_SOURCE_IN_KEY_VALUE = true;
}

String recordCount = System.getProperty(
"com.sun.aas.logging.keyvalue.recordnumber");
String recordCount = System.getProperty("com.sun.aas.logging.keyvalue.recordnumber");
if ((recordCount != null)
&& (recordCount.equals("true"))) {
RECORD_NUMBER_IN_KEY_VALUE = true;
Expand All @@ -116,37 +115,63 @@ public class JSONLogFormatter extends Formatter implements LogEventBroadcaster {
private String recordDateFormat;

// Event separator
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private static final String LINE_SEPARATOR = System.lineSeparator();

// String values for field keys
private static final String TIMESTAMP_KEY = "_Timestamp";
private static final String LOG_LEVEL_KEY = "_Level";
private static final String PRODUCT_ID_KEY = "_Version";
private static final String LOGGER_NAME_KEY = "_LoggerName";
private String TIMESTAMP_KEY = "Timestamp";
private String LOG_LEVEL_KEY = "Level";
private String PRODUCT_ID_KEY = "Version";
private String LOGGER_NAME_KEY = "LoggerName";
// String values for exception keys
private static final String EXCEPTION_KEY = "_Exception";
private static final String STACK_TRACE_KEY = "_StackTrace";
private String EXCEPTION_KEY = "Exception";
private String STACK_TRACE_KEY = "StackTrace";
// String values for thread excludable keys
private static final String THREAD_ID_KEY = "_ThreadID";
private static final String THREAD_NAME_KEY = "_ThreadName";
private static final String USER_ID_KEY = "_UserId";
private static final String ECID_KEY = "_ECId";
private static final String LEVEL_VALUE_KEY = "_LevelValue";
private static final String TIME_MILLIS_KEY = "_TimeMillis";
private static final String MESSAGE_ID_KEY = "_MessageID";
private static final String LOG_MESSAGE_KEY = "_LogMessage";
private String THREAD_ID_KEY = "ThreadID";
private String THREAD_NAME_KEY = "ThreadName";
private String USER_ID_KEY = "UserId";
private String ECID_KEY = "ECId";
private String LEVEL_VALUE_KEY = "LevelValue";
private String TIME_MILLIS_KEY = "TimeMillis";
private String MESSAGE_ID_KEY = "MessageID";
private String LOG_MESSAGE_KEY = "LogMessage";

private static final String RFC3339_DATE_FORMAT =
"yyyy-MM-dd'T'HH:mm:ss.SSSZ";

private final ExcludeFieldsSupport excludeFieldsSupport = new ExcludeFieldsSupport();
private LogEventBroadcaster logEventBroadcasterDelegate;
private String productId = "";

/**
* For backwards compatibility with log format for pre-182
* @deprecated
*/
@Deprecated
private static final String PAYARA_JSONLOGFORMATTER_UNDERSCORE="fish.payara.deprecated.jsonlogformatter.underscoreprefix";

public JSONLogFormatter() {
super();
loggerResourceBundleTable = new HashMap();
logManager = LogManager.getLogManager();

String underscorePrefix = logManager.getProperty(PAYARA_JSONLOGFORMATTER_UNDERSCORE);
if ((underscorePrefix)!= null && Boolean.valueOf(underscorePrefix)) {
TIMESTAMP_KEY = "_" + TIMESTAMP_KEY;
LOG_LEVEL_KEY = "_" + LOG_LEVEL_KEY;
PRODUCT_ID_KEY = "_" + PRODUCT_ID_KEY;
LOGGER_NAME_KEY = "_" + LOGGER_NAME_KEY;
EXCEPTION_KEY = "_" + EXCEPTION_KEY;
STACK_TRACE_KEY = "_" + STACK_TRACE_KEY;
// String values for thread excludable keys
THREAD_ID_KEY = "_" + THREAD_ID_KEY;
THREAD_NAME_KEY = "_" + THREAD_NAME_KEY;
USER_ID_KEY = "_" + USER_ID_KEY;
ECID_KEY = "_" + ECID_KEY;
LEVEL_VALUE_KEY = "_" + LEVEL_VALUE_KEY;
TIME_MILLIS_KEY = "_" + TIME_MILLIS_KEY;
MESSAGE_ID_KEY = "_" + MESSAGE_ID_KEY;
LOG_MESSAGE_KEY = "_" + LOG_MESSAGE_KEY;
}
}

public JSONLogFormatter(FormatterDelegate delegate) {
Expand Down

0 comments on commit 1b34688

Please sign in to comment.