public final class Log4j2PropertiesEditor extends Object
| Modifier and Type | Method and Description |
|---|---|
static Map<String,String> |
getKeyValuesOfAppender(File file,
String appenderName)
Returns a map of key-value pairs for all properties belonging to the given appender.
|
static String |
getProperty(File file,
String key)
Return the property value for a given key (first occurrence) or null if not found.
|
static ArrayList<String> |
readAllLines(File file)
Reads all lines from the specified file using UTF-8 encoding.
|
static void |
writeUpdatedAppender(File file,
String appenderName,
Map<String,String> newProps,
boolean merge)
Updates the properties for the given appender in the log4j2.properties file.
|
public static ArrayList<String> readAllLines(File file) throws IOException
file - the properties file to readIOException - if an I/O error occurs reading from the filepublic static Map<String,String> getKeyValuesOfAppender(File file, String appenderName) throws IOException
file - the log4j2.properties file to readappenderName - the name of the appender whose properties should be extractedIOException - if an I/O error occurs reading from the filepublic static String getProperty(File file, String key) throws IOException
IOExceptionpublic static void writeUpdatedAppender(File file, String appenderName, Map<String,String> newProps, boolean merge) throws IOException
The newProps map specifies the properties to apply to the appender. If a property value is
"__REMOVE__" (the literal string) or null, that property will be removed from the appender's
configuration in the file.
The merge parameter controls how the update is performed:
merge is true, the properties in newProps are merged with the existing
properties for the appender. Properties with values of "__REMOVE__" or null are deleted.
All other properties in newProps are added or updated, while properties not mentioned in
newProps are left unchanged.merge is false, the entire appender block is replaced with only the properties
specified in newProps (except those with values of "__REMOVE__" or null, which
are omitted).file - the log4j2.properties file to updateappenderName - the name of the appender to updatenewProps - map of properties to apply; values of "__REMOVE__" or null mark properties for deletionmerge - if true, merges new properties with existing ones; if false, replaces the entire appender blockIOException - if an I/O error occurs reading from or writing to the fileCopyright © 2026 WSO2. All rights reserved.