Adding dates in alfresco.log

By default, Alfresco’s log4j configuration specifies that only the current system time, and no date, are output as the first entry in log messages output in alfresco.log, producing output such as the following.
12:21:23,658 INFO [org.alfresco.config.JndiPropertiesFactoryBean] Loading properties file from URL [file:/home/wabson/Downloads/alfresco-enterprise-tomcat-3.3.1/tomcat/shared/classes/alfresco-global.properties]
12:21:24,009 INFO [org.alfresco.config.JndiPropertyPlaceholderConfigurer] Loading properties file from class path resource [alfresco/alfresco-shared.properties]
12:22:40,726 INFO [org.springframework.extensions.webscripts.TemplateProcessorRegistry] Registered template processor Repository Template Processor for extension ftl
12:22:40,747 INFO [org.springframework.extensions.webscripts.ScriptProcessorRegistry] Registered script processor Repository Script Processor for extension js
12:23:09,470 INFO [org.alfresco.repo.domain.schema.SchemaBootstrap] Schema managed by database dialect org.hibernate.dialect.MySQLInnoDBDialect.
12:23:11,774 INFO [org.alfresco.repo.domain.schema.SchemaBootstrap] No changes were made to the schema.

This is the line responsible for setting the configuration in log4j.properties (found in the root of the classpath in the alfresco webapp)
log4j.appender.File.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
That’s fine in theory, since the configuration also specifies that the log file should roll over using a date-based suffix on a nightly basis. However, in practice the log rotation can sometimes fail on running systems, leaving log entries spanning more than one day in a single log file and ambiguity over which day a particular message was output on.
Fortunately, log4j’s PatternLayout is quite flexible, and allows you to specify a date-time format instead (in fact, this is the default if no date format specifier is given.
To print the date in ISO-8601 format, e.g. “1999-11-27 15:49:37,459”, use
log4j.appender.File.layout.ConversionPattern=%d{ISO8601} %-5p [%c] %m%n
For classic date format, e.g. “06 Nov 1994 15:49:37,459”, use
log4j.appender.File.layout.ConversionPattern=%d{DATE} %-5p [%c] %m%n
To also add dates into the console logging output (which is redirected into Tomcat’s stdout logs when running as a service), update the property log4j.appender.Console.layout.ConversionPattern.