39460

How to add serveral deletion conditions on log4j2.properties?

Question:

We're using ElasticSearch 6.1.1

This is the default Rolling File on log4j2.properties:

appender.rolling.type = RollingFile appender.rolling.name = rolling appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log appender.rolling.layout.type = PatternLayout appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.-10000m%n appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz appender.rolling.policies.type = Policies appender.rolling.policies.time.type = TimeBasedTriggeringPolicy appender.rolling.policies.time.interval = 1 appender.rolling.policies.time.modulate = true appender.rolling.policies.size.type = SizeBasedTriggeringPolicy appender.rolling.policies.size.size = 1GB appender.rolling.strategy.type = DefaultRolloverStrategy appender.rolling.strategy.fileIndex = nomax appender.rolling.strategy.action.type = Delete appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path} appender.rolling.strategy.action.condition.type = IfFileName appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize **appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB**

There is just one Deletion condition, when the log files overcome 2GB space.

I want to add a second optional condition, when the log files overcome 7 days old.

I have applied next changes:

appender.rolling.strategy.action.type = Delete appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path} appender.rolling.strategy.action.condition.type = IfFileName appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* appender.rolling.strategy.action.condition.nested_condition.type = IfAny appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB **appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified appender.rolling.strategy.action.condition.nested_condition.age = 7D**

But I'm doing something wrong because I'm not able to get the result I want.

Anyone could show me any example how to add two or more Deletion conditions on log4j2.properties?

Thanks and kind regards

Answer1:

Try below configuration for DeleteAction -

appender.rolling.strategy.action.type = Delete appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path} appender.rolling.strategy.action.condition.type = IfFileName appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* appender.rolling.strategy.action.condition.nested_condition.type = IfAny appender.rolling.strategy.action.condition.nested_condition.fileSize.type = IfAccumulatedFileSize appender.rolling.strategy.action.condition.nested_condition.fileSize.exceeds = 2GB appender.rolling.strategy.action.condition.nested_condition.lastMod.type = IfLastModified appender.rolling.strategy.action.condition.nested_condition.lastMod.age = 7D

You can check some more examples in log4j2 <a href="https://logging.apache.org/log4j/2.x/manual/appenders.html#DeleteIfAccumulatedFileSize" rel="nofollow">documentation</a>

Recommend

  • Creating an Expression for an Object Variable?
  • Dimensions getting mixed up when reading .pngs into Matlab
  • Continue flow on certain specific Error in SSIS
  • Java Error NoClassDefFoundError
  • Output values in a certain way using XSLT/XPath 2.0
  • Concat Two Strings then Convert to Date in Java
  • If And Or Multiple Statements in VBA
  • Select all check boxes using button [duplicate]
  • has been compiled by a more recent version of the Java Runtime (class file version 53.0)
  • ISO C forbids empty initializer braces in C
  • ColdFusion - DateTime Format with GMT offset
  • Cluster markers with osmdroid
  • GCC compiler warning flag for zero variadic macro arguments
  • How can I use special characters in angular directives attributes?
  • Convert hex to utf in Python
  • How to use OnMarkerClickListener
  • Year, Month, and Day parameters describe an un-representable DateTime in Persian calender
  • jQuery - how to validate a date of birth using jQuery Validation plugin?
  • jQuery random blockquote
  • A simple datepicker in VueJS
  • How to parsing NSDate to RFC 822 always use in English?
  • Get or convert Week of year to ISO week
  • C++11 variable size POD struct
  • Remove previous Directions Route Google Maps
  • stop execution in Custom validator if it false
  • Javascript: Looping through an array to create listeners, issue with call by reference and value?
  • Get localized short date pattern as String?
  • WPF version of .ScaleControl?
  • Why use database factory in asp.net mvc?
  • Android Activity.onWindowFocusChanged doesn't get called from within TabHost
  • Parse a date string in a specific locale (not timezone!)
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • htaccess add www if not subdomain, if subdomain remove www
  • JSON response opens as a file, but I can't access it with JavaScript
  • Accessing IRQ description array within a module and displaying action names
  • WinForms: two way TextBox problem
  • align graphs with different xlab
  • R: gsub and capture
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize