2

What I have now in my config file

{
    "type":"RollingFile",
    "name": "machineLog",
    "ThresholdFilter": { "level": "debug" },
    "JsonLayout":{"complete":"true"},
    "Policies":
    {
        "SizeBasedTriggeringPolicy": {"size":"100M"}
    },
    "fileName": "${sys:my.logging.directory}/machine.json",
    "filePattern":"${sys:my.logging.directory}/RolledLogs/$${date:yyyy}/$${date:MM}/%d{yyyy-MM-dd-HH}-machine.json.gz"
}

I want the rolled file (filePattern entry) to contain a UNIX timestamp. Since this is legal I tried changing that line to be

"filePattern":"${sys:my.logging.directory}/RolledLogs/$${date:yyyy}/$${date:MM}/%d{UNIX}-machine.json.gz"

Figuring that since %d{UNIX} was mentioned in the Layout documentation page for log4j2 it would work.

The result is that it creates the unrolled machine.json file but seems to not be able to append to it. It remains at zero bytes even when I flood the system with things that normally generates a ton of logs with the original config.

What's going on here? How can I achieve the effect I want?

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
Carson Wilcox
  • 351
  • 1
  • 2
  • 8

1 Answers1

1

I'm not sure you can use all options of the PatternLayout %d date converter in the RollingFile filePattern.

However, if the ${sys:someKey... system properties lookup works, then a custom lookup will also work. So one idea is to write a custom lookup plugin that generates the unix timestamp, and configure the RollingFile filePattern like this: "filePattern":"${sys:my.logging.directory}/RolledLogs/$${date:yyyy}/$${date:MM}/$${mylookup:UNIX}-machine.json.gz"

Here is an example of how to write a custom Log4j 2 lookup plugin: https://stackoverflow.com/a/27418802/1446916

Community
  • 1
  • 1
Remko Popma
  • 35,130
  • 11
  • 92
  • 114