====== File log4j2.properties ====== Il file **log4j2.properties**, è utilizzato per configurare le modalità di logging in geoweb. Questa è la **versione 2** di [[https://logging.apache.org/log4j/2.x/index.html|log4j]], che è **introdotta a partire dalla versione 4.6.X** del framework. L'introduzione è stata forzata in seguito alla scoperta di un rilevante bug di sicurezza. info [[https://www.lffl.org/2021/12/approfondimento-bug-log4shell-e-log4j.html|qui]]. Non sono affette dal bug le versioni 1.x di log4j, precedentemente utilizzate da Geoweb, ma la richiesta di aggiornamento da parte di certi clienti è stata pressante, ed è statao deciso di passare comunque all'ultima versione rilasciata. Si possono specificare, tra l'altro, i //logging level// selettivamente e su quali file verranno salvati i log. Per una guida completa fare riferimento a quella ufficiale [[https://logging.apache.org/log4j/2.x/manual/configuration.html|qui]]. ===== Logging Level ===== Impostando un logging level, si avrà come effetto quello di visualizzare loggati solo i messaggi di pari livello o superiore. Ecco la lista dei logging level, in ordine crescente dal meno al più restrittivo: * **all** All levels including custom levels. * **trace** Designates finer-grained informational events than the debug. * **debug** Designates fine-grained informational events that are most useful to debug an application. * **info** Designates informational messages that highlight the progress of the application at coarse-grained level. * **warn** Designates potentially harmful situations. * **error** Designates error events that might still allow the application to continue running. * **fatal** Designates very severe error events that will presumably lead the application to abort. * **off** The highest possible rank and is intended to turn off logging. Per quanto riguarda in Geoweb, è buona prassi impostare il logging level a //debug// in fase di sviluppo/dispiegamento in ambiente di test/collaudo, ed ad //warn// od //error// in produzione. Log generati da librerie di terze parti, come //Activti// e //MongoDB// vengono in genere tenuti sempre con logging level più restrittivi, come //error//, a meno di specifiche necessità di debugging. I log relativi al //GwMailService// sono in genere configurati per essere loggati su un file separato. ===== Note sulla configurazione log4j2 ===== * Ora si può configurare un lasso di tempo alla fine del quale il file di configurazione viene ricaricato e valutato. **Questo senza più necessità di stoppare il server**. Questo si imposta tramite il parametro, in secondi: monitorInterval= * Dentro i template, in alto, sono state portate delle //property// da cui si può più facilmente settare il log level per le varie componenti: ... ###################################################################### # log threshold levels ###################################################################### property.globalLogLevel = debug property.geowebLogLevel = debug property.securityLogLevel = info property.emailLogLevel = debug property.activitiLogLevel = error property.mongodbLogLevel = error property.httpclientLogLevel = info ... * il riferimento a variabili d'ambiente va ora fatto usando il prefisso sys:, per esempio ${sys:catalina.home} * le property contenenti appenders= e appenderRefs= sono opzionali e sono obbligatorie solo in caso di nomi con caratteri speciali degli appender. Sono volutamente lasciate per capire più facilmente le correlazioni fra i vari elementi della configurazione * per ogni **logger** va fatta una riga separata per ogni **appender** che si intende collegare ad esso * inoltre valgono in generale le seguenti correlazioni determinate dai colori: ###################################################################### # geoweb logger ###################################################################### logger.geoweb.name = com.geowebframework logger.geoweb.level = ${geowebLogLevel} logger.geoweb.additivity = false logger.geoweb.appenderRefs = stdout,rolling logger.geoweb.appenderRef.stdout.ref = STDOUT logger.geoweb.appenderRef.rolling.ref = RollingFile ###################################################################### # appenders ###################################################################### #appenders definition can be optional, but it's useful to undestand properties syntax correlation appenders = console,rolling ###################################################################### # STDOUT (Console) appender ###################################################################### appender.console.type = Console appender.console.name = STDOUT appender.console.layout.type = PatternLayout appender.console.layout.pattern = %d [%t] %-5p %c - %m%n appender.console.filter.threshold.type = ThresholdFilter appender.console.filter.threshold.level = ${globalLogLevel} ###################################################################### # RollingFile (RollingFile) appender ###################################################################### appender.rolling.type = RollingFile appender.rolling.name = RollingFile appender.rolling.fileName = ${sys:catalina.home}/logs/geoweb_client.log #appender.rolling.filePattern = ${sys:catalina.home}/logs/geoweb_client-%d{yyyy-MM-dd}-%i.log appender.rolling.filePattern = ${sys:catalina.home}/logs/geoweb_client-%i.log appender.rolling.layout.type = PatternLayout appender.rolling.layout.pattern = %d [%t] %-5p %c - %m%n 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 = 20MB appender.rolling.strategy.type = DefaultRolloverStrategy appender.rolling.strategy.max = 10 appender.rolling.strategy.fileIndex = min ===== Template log4j2.properties (Webclient) ===== Nel caso si voglia usare anche la **TimeBasedTriggeringPolicy**, per far creare un nuovo file ogni giorno, oltre che superati i limiti di size: - Elenco numeratodecommentare (**togliendo #**) le parti //appender.rolling.policies.time.// - nel **filePattern** degli **appender** assicurarsi che ci sia un costrutto **%d{}** //(Es: %d{yyyy-MM-dd})// # documentation here: # https://logging.apache.org/log4j/2.x/manual/configuration.html ###################################################################### # log threshold levels ###################################################################### property.globalLogLevel = debug property.geowebLogLevel = debug property.securityLogLevel = info property.emailLogLevel = debug property.activitiLogLevel = error property.mongodbLogLevel = error property.httpclientLogLevel = info ###################################################################### # global settings ###################################################################### name = GwPropertiesConfig # status # The level of internal Log4j events that should be logged to the console. # Valid values for this attribute are "off", "trace", "debug", "info", "warn", "error", "fatal", and "all". # Log4j will log details about initialization, rollover and other internal actions to the status logger. # Setting status="trace" is one of the first tools available to you if you need to troubleshoot log4j. # (Alternatively, setting system property log4j2.debug will also print internal Log4j2 logging to the console, # including internal logging that took place before the configuration file was found.) status = info # dest # Either "err" for stderr, "out" for stdout, a file path, or a URL. dest = out # monitorInterval # The minimum amount of time, in seconds, that must elapse before the file configuration is checked for changes. monitorInterval=60 filter.threshold.type = ThresholdFilter filter.threshold.level = ${globalLogLevel} ###################################################################### # root logger ###################################################################### rootLogger.level = ${globalLogLevel} rootLogger.appenderRefs = stdout,rolling rootLogger.appenderRef.stdout.ref = STDOUT rootLogger.appenderRef.rolling.ref = RollingFile ###################################################################### # geoweb logger ###################################################################### logger.geoweb.name = com.geowebframework logger.geoweb.level = ${geowebLogLevel} logger.geoweb.additivity = false logger.geoweb.appenderRefs = stdout,rolling logger.geoweb.appenderRef.stdout.ref = STDOUT logger.geoweb.appenderRef.rolling.ref = RollingFile ###################################################################### # security logger ###################################################################### logger.security.name = com.geowebframework.webclient.security logger.security.level = ${securityLogLevel} logger.security.additivity = false logger.security.appenderRefs = stdout,rolling logger.security.appenderRef.stdout.ref = STDOUT logger.security.appenderRef.rolling.ref = RollingFileAccess ###################################################################### # email logger ###################################################################### logger.email.name = com.geowebframework.calendar.service.GwMailService logger.email.level = ${emailLogLevel} logger.email.additivity = false logger.email.appenderRefs = stdout,rolling logger.email.appenderRef.stdout.ref = STDOUT logger.email.appenderRef.rolling.ref = RollingFileEmail ###################################################################### # activiti logger ###################################################################### logger.activiti.name = org.activiti logger.activiti.level = ${activitiLogLevel} logger.activiti.additivity = false logger.activiti.appenderRefs = stdout,rolling logger.activiti.appenderRef.stdout.ref = STDOUT logger.activiti.appenderRef.rolling.ref = RollingFile ###################################################################### # mongodb logger ###################################################################### logger.mongodb.name = org.mongodb.driver.cluster logger.mongodb.level = ${mongodbLogLevel} logger.mongodb.additivity = false logger.mongodb.appenderRefs = stdout,rolling logger.mongodb.appenderRef.stdout.ref = STDOUT logger.mongodb.appenderRef.rolling.ref = RollingFile ###################################################################### # httpclient logger ###################################################################### logger.httpclient.name=org.apache.http logger.httpclient.level = ${httpclientLogLevel} logger.httpclient.additivity = false logger.httpclient.appenderRefs = stdout,rolling logger.httpclient.appenderRef.stdout.ref = STDOUT logger.httpclient.appenderRef.rolling.ref = RollingFile ###################################################################### # appenders ###################################################################### #appenders definition can be optional, but it's useful to understand properties syntax correlation appenders = console,rolling,rollingEmail,rollingAccess ###################################################################### # STDOUT (Console) appender ###################################################################### appender.console.type = Console appender.console.name = STDOUT appender.console.layout.type = PatternLayout appender.console.layout.pattern = %d [%t] %-5p %c - %m%n appender.console.filter.threshold.type = ThresholdFilter appender.console.filter.threshold.level = ${globalLogLevel} ###################################################################### # RollingFile (RollingFile) appender ###################################################################### appender.rolling.type = RollingFile appender.rolling.name = RollingFile appender.rolling.fileName = ${sys:catalina.home}/logs/geoweb_client.log #appender.rolling.filePattern = ${sys:catalina.home}/logs/geoweb_client-%d{yyyy-MM-dd}-%i.log appender.rolling.filePattern = ${sys:catalina.home}/logs/geoweb_client-%i.log appender.rolling.layout.type = PatternLayout appender.rolling.layout.pattern = %d [%t] %-5p %c - %m%n 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 = 20MB appender.rolling.strategy.type = DefaultRolloverStrategy appender.rolling.strategy.max = 10 appender.rolling.strategy.fileIndex = min ###################################################################### # RollingFileEmail (RollingFile) appender ###################################################################### appender.rollingEmail.type = RollingFile appender.rollingEmail.name = RollingFileEmail appender.rollingEmail.fileName = ${sys:catalina.home}/logs/gwMail.log #appender.rollingEmail.filePattern = ${sys:catalina.home}/logs/gwMail-%d{yyyy-MM-dd}-%i.log appender.rollingEmail.filePattern = ${sys:catalina.home}/logs/gwMail-%i.log appender.rollingEmail.layout.type = PatternLayout appender.rollingEmail.layout.pattern = %d [%t] %-5p %c - %m%n appender.rollingEmail.policies.type = Policies #appender.rollingEmail.policies.time.type = TimeBasedTriggeringPolicy #appender.rollingEmail.policies.time.interval = 1 #appender.rollingEmail.policies.time.modulate = true appender.rollingEmail.policies.size.type = SizeBasedTriggeringPolicy appender.rollingEmail.policies.size.size = 20MB appender.rollingEmail.strategy.type = DefaultRolloverStrategy appender.rollingEmail.strategy.max = 10 appender.rollingEmail.strategy.fileIndex = min ###################################################################### # RollingFileAccess (RollingFile) appender ###################################################################### appender.rollingAccess.type = RollingFile appender.rollingAccess.name = RollingFileAccess appender.rollingAccess.fileName = ${sys:catalina.home}/logs/gwAccess.log #appender.rollingAccess.filePattern = ${sys:catalina.home}/logs/gwAccess-%d{yyyy-MM-dd}-%i.log appender.rollingAccess.filePattern = ${sys:catalina.home}/logs/gwAccess-%i.log appender.rollingAccess.layout.type = PatternLayout appender.rollingAccess.layout.pattern = %d [%t] %-5p %c - %m%n appender.rollingAccess.policies.type = Policies #appender.rollingAccess.policies.time.type = TimeBasedTriggeringPolicy #appender.rollingAccess.policies.time.interval = 1 #appender.rollingAccess.policies.time.modulate = true appender.rollingAccess.policies.size.type = SizeBasedTriggeringPolicy appender.rollingAccess.policies.size.size = 20MB appender.rollingAccess.strategy.type = DefaultRolloverStrategy appender.rollingAccess.strategy.max = 10 appender.rollingAccess.strategy.fileIndex = min ===== Template log4j2.properties (Webadmin) ===== Nel caso si voglia usare anche la **TimeBasedTriggeringPolicy**, per far creare un nuovo file ogni giorno, oltre che superati i limiti di size: - Elenco numeratodecommentare (**togliendo #**) le parti //appender.rolling.policies.time.// - nel **filePattern** degli **appender** assicurarsi che ci sia un costrutto **%d{}** //(Es: %d{yyyy-MM-dd})// # documentation here: # https://logging.apache.org/log4j/2.x/manual/configuration.html ###################################################################### # log threshold levels ###################################################################### property.globalLogLevel = debug property.geowebLogLevel = debug property.activitiLogLevel = error ###################################################################### # global settings ###################################################################### name = GwPropertiesConfig # status # The level of internal Log4j events that should be logged to the console. # Valid values for this attribute are "off", "trace", "debug", "info", "warn", "error", "fatal", and "all". # Log4j will log details about initialization, rollover and other internal actions to the status logger. # Setting status="trace" is one of the first tools available to you if you need to troubleshoot log4j. # (Alternatively, setting system property log4j2.debug will also print internal Log4j2 logging to the console, # including internal logging that took place before the configuration file was found.) status = info # dest # Either "err" for stderr, "out" for stdout, a file path, or a URL. dest = out # monitorInterval # The minimum amount of time, in seconds, that must elapse before the file configuration is checked for changes. monitorInterval=60 filter.threshold.type = ThresholdFilter filter.threshold.level = ${globalLogLevel} ###################################################################### # root logger ###################################################################### rootLogger.level = ${globalLogLevel} rootLogger.appenderRefs = stdout,rolling rootLogger.appenderRef.stdout.ref = STDOUT rootLogger.appenderRef.rolling.ref = RollingFile ###################################################################### # geoweb logger ###################################################################### logger.geoweb.name = com.geowebframework logger.geoweb.level = ${geowebLogLevel} logger.geoweb.additivity = false logger.geoweb.appenderRefs = stdout,rolling logger.geoweb.appenderRef.stdout.ref = STDOUT logger.geoweb.appenderRef.rolling.ref = RollingFile ###################################################################### # activiti logger ###################################################################### logger.activiti.name = org.activiti logger.activiti.level = ${activitiLogLevel} logger.activiti.additivity = false logger.activiti.appenderRefs = stdout,rolling logger.activiti.appenderRef.stdout.ref = STDOUT logger.activiti.appenderRef.rolling.ref = RollingFile ###################################################################### # appenders ###################################################################### #appenders definition can be optional, but it's useful to understand properties syntax correlation appenders = console,rolling ###################################################################### # STDOUT (Console) appender ###################################################################### appender.console.type = Console appender.console.name = STDOUT appender.console.layout.type = PatternLayout appender.console.layout.pattern = %d [%t] %-5p %c - %m%n appender.console.filter.threshold.type = ThresholdFilter appender.console.filter.threshold.level = ${globalLogLevel} ###################################################################### # RollingFile (RollingFile) appender ###################################################################### appender.rolling.type = RollingFile appender.rolling.name = RollingFile appender.rolling.fileName = ${sys:catalina.home}/logs/geoweb_admin.log #appender.rolling.filePattern = ${sys:catalina.home}/logs/geoweb_admin-%d{yyyy-MM-dd}-%i.log appender.rolling.filePattern = ${sys:catalina.home}/logs/geoweb_admin-%i.log appender.rolling.layout.type = PatternLayout appender.rolling.layout.pattern = %d [%t] %-5p %c - %m%n 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 = 20MB appender.rolling.strategy.type = DefaultRolloverStrategy appender.rolling.strategy.max = 10 appender.rolling.strategy.fileIndex = min