Class Log4j2PropertiesEditor
java.lang.Object
org.wso2.carbon.logging.service.util.Log4j2PropertiesEditor
-
Method Summary
Modifier and TypeMethodDescriptiongetKeyValuesOfAppender(File file, String appenderName) Returns a map of key-value pairs for all properties belonging to the given appender.static StringgetProperty(File file, String key) Return the property value for a given key (first occurrence) or null if not found.readAllLines(File file) Reads all lines from the specified file using UTF-8 encoding.static voidUpdates the properties for the given appender in the log4j2.properties file.
-
Method Details
-
readAllLines
Reads all lines from the specified file using UTF-8 encoding.- Parameters:
file- the properties file to read- Returns:
- an ArrayList containing all lines from the file
- Throws:
IOException- if an I/O error occurs reading from the file
-
getKeyValuesOfAppender
public static Map<String,String> getKeyValuesOfAppender(File file, String appenderName) throws IOException Returns a map of key-value pairs for all properties belonging to the given appender.- Parameters:
file- the log4j2.properties file to readappenderName- the name of the appender whose properties should be extracted- Returns:
- a LinkedHashMap containing all key-value pairs for the specified appender
- Throws:
IOException- if an I/O error occurs reading from the file
-
getProperty
Return the property value for a given key (first occurrence) or null if not found.- Throws:
IOException
-
writeUpdatedAppender
public static void writeUpdatedAppender(File file, String appenderName, Map<String, String> newProps, boolean merge) throws IOExceptionUpdates the properties for the given appender in the log4j2.properties file.The
newPropsmap specifies the properties to apply to the appender. If a property value is"__REMOVE__"(the literal string) ornull, that property will be removed from the appender's configuration in the file.The
mergeparameter controls how the update is performed:- If
mergeistrue, the properties innewPropsare merged with the existing properties for the appender. Properties with values of"__REMOVE__"ornullare deleted. All other properties innewPropsare added or updated, while properties not mentioned innewPropsare left unchanged. - If
mergeisfalse, the entire appender block is replaced with only the properties specified innewProps(except those with values of"__REMOVE__"ornull, which are omitted).
- Parameters:
file- the log4j2.properties file to updateappenderName- the name of the appender to updatenewProps- map of properties to apply; values of"__REMOVE__"ornullmark properties for deletionmerge- if true, merges new properties with existing ones; if false, replaces the entire appender block- Throws:
IOException- if an I/O error occurs reading from or writing to the file
- If
-