Get org.springframework to stop polluting my logs - java

I am using Payara 4.1 and Netbeans 8.1.
When I run my application, these four lines are among the first to be logged:
#!## LogManagerService.postConstruct : rootFolder=/opt/payara41/glassfish
#!## LogManagerService.postConstruct : templateDir=/opt/payara41/glassfish/lib/templates
#!## LogManagerService.postConstruct : src=/opt/payara41/glassfish/lib/templates/logging.properties
#!## LogManagerService.postConstruct : dest=/opt/payara41/glassfish/domains/domain1/config/logging.properties
I added the line org.springframework=WARNING at the end of the last logging.properties file given above, and restarted my server. That didn't seem to have an effect. When I open the asadmin shell /opt/payara41/bin/asadmin and run list-log-attributes, here is what I get:
asadmin> list-log-attributes
com.sun.enterprise.server.logging.GFFileHandler.excludeFields <>
com.sun.enterprise.server.logging.GFFileHandler.file <${com.sun.aas.instanceRoot}/logs/server.log>
com.sun.enterprise.server.logging.GFFileHandler.flushFrequency <1>
com.sun.enterprise.server.logging.GFFileHandler.formatter <com.sun.enterprise.server.logging.ODLLogFormatter>
com.sun.enterprise.server.logging.GFFileHandler.logtoConsole <false>
com.sun.enterprise.server.logging.GFFileHandler.maxHistoryFiles <0>
com.sun.enterprise.server.logging.GFFileHandler.multiLineMode <true>
com.sun.enterprise.server.logging.GFFileHandler.retainErrorsStasticsForHours <0>
com.sun.enterprise.server.logging.GFFileHandler.rotationLimitInBytes <2000000>
com.sun.enterprise.server.logging.GFFileHandler.rotationOnDateChange <false>
com.sun.enterprise.server.logging.GFFileHandler.rotationTimelimitInMinutes <0>
com.sun.enterprise.server.logging.SyslogHandler.useSystemLogging <false>
handlerServices <com.sun.enterprise.server.logging.GFFileHandler,com.sun.enterprise.server.logging.SyslogHandler>
handlers <java.util.logging.ConsoleHandler>
java.util.logging.ConsoleHandler.formatter <com.sun.enterprise.server.logging.UniformLogFormatter>
java.util.logging.FileHandler.count <1>
java.util.logging.FileHandler.formatter <java.util.logging.XMLFormatter>
java.util.logging.FileHandler.limit <50000>
java.util.logging.FileHandler.pattern <%h/java%u.log>
log4j.logger.org.hibernate.validator.util.Version <warn>
org.springframework <WARNING>
Command list-log-attributes executed successfully.
I have tried the suggestions given in this SO question but that didn't work. I'm stumped. :( I really do not want to see all those INFO logging lines printed by the spring framework.
=== EDIT ===
Here is what is in my log4j.properties (copied from SO):
# Define the root logger with appender file
log4j.rootLogger = DEBUG, stdout
# Define the file appender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
# Set the name of the logs destination
log4j.appender.stdout.target=System.out
# Set the immediate flush to true (default)
log4j.appender.stdout.ImmediateFlush=true
# Set the threshold to debug mode
log4j.appender.stdout.Threshold=debug
# Set the append to false, overwrite
log4j.appender.stdout.Append=false
# Define the layout for appender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.conversionPattern=%d{yyyy-MM-dd}:%m%n
log4j.logger.org.springframework=WARNING
Here are all the places I have copied that file to:
$PROJECT_DIR/src/log4j.properties
$PROJECT_DIR/src/main/resources/META-INF/log4j.properties
$PROJECT_DIR/src/main/webapp/WEB-INF/log4j.properties
$PROJECT_DIR/src/main/webapp/WEB-INF/classes/log4j.properties
$PROJECT_DIR/target/$PROJECT-1.0/WEB-INF/log4j.properties
$PROJECT_DIR/target/$PROJECT-1.0/WEB-INF/classes/log4j.properties
$PROJECT_DIR/target/$PROJECT-1.0/WEB-INF/classes/META-INF/log4j.properties
$PROJECT_DIR/target/classes/META-INF/log4j.properties
/opt/payara41/glassfish/domains/domain1/config/log4j.properties
In addition, I have added log4j.logger.org.springframework=WARNING and org.springframework=WARNING to Configurations > server-config > Logger Settings > Module Log Levels in the Payara UI. Nothing is working. Payara's server log still has INFO lines for the spring framework.

I tried everything that has been suggested so far, to no avail. So I ended up doing something pretty hacky. I wrote my own log handler and installed it to domain1/lib/ext:
package org.springsuppressor;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
public class MyHandler extends ConsoleHandler {
public MyHandler() {
super();
setLevel(Level.WARNING);
}
}
The handler above sets the log level for all loggers to WARNING. I could suppress messages for just the spring framework, but I don't yet need to do that.

Related

I need to change the log level dynamically at runtime as per the log level set

I am using to invoke the below Java code in Mule 4.3 to try to set the level to debug but still printing INFO and other levels except Trace level. Basically its not updating all the loggers. Its working fine in Mule 3.8 with the below code in Expression component.
Java Code
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig("org.mule.runtime.core.internal.processor.LoggerMessageProcessor");
loggerConfig.setLevel(Level.DEBUG);
context.updateLoggers(config);
Console Output :
DEBUG 2022-08-17 22:33:50,499 [[MuleRuntime].uber.02: [dynamiclogger].dynamicloggerFlow1.CPU_LITE #112f86df] [processor: dynamicloggerFlow1/processors/0; event: 90dbce00-1e4e-11ed-a2e8-646e69d7e195] org.mule.runtime.core.internal.processor.LoggerMessageProcessor:
*********************DEBUG LEVEL*************************************
INFO 2022-08-17 22:33:50,499 [[MuleRuntime].uber.02: [dynamiclogger].dynamicloggerFlow1.CPU_LITE #112f86df] [processor: dynamicloggerFlow1/processors/1; event: 90dbce00-1e4e-11ed-a2e8-646e69d7e195] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: *************** INFO LEVEL ***************************

Log file not generated in dropwizard

I have following log scheme. I want to rotate logs every 4 hours. But when I start application with these settings, ./logs/mylogs.log file is not generated. I have logs directory created in application's directory.
It works fine if I change filename pattern to include minute as well like -
archivedLogFilenamePattern: ./logs/mylogs-%d{yyyy-MM-dd-hh-mm}.log.gz
I am confused why it does not work for hourly pattern?
logging:
level: WARN
appenders:
- type: console
threshold: WARN
- type: file
threshold: WARN
logFormat: "%-6level [%d{HH:mm:ss.SSS}] [%t] %logger{5} - %X{code} %msg %n"
currentLogFilename: ./logs/mylogs.log
archive: true
archivedLogFilenamePattern: ./logs/mylogs-%d{yyyy-MM-dd-hh}.log.gz
archivedFileCount: 4
Using dropwizard 1.3.7
Dropwizard uses Logback for logging. The rolling policy used here is TimeBasedRollingPolicy.
The fileNamePattern to rollover at the beginning of every hour:
archivedLogFilenamePattern: ./logs/mylogs-%d{yyyy-MM-dd_HH}.log.gz
Not sure if there is a way to rollover every n hours. You might want to consider using FixedWindowRollingPolicy, which dropwizard supports. This will allow you to rollover based on size. Eg -
- type: file
threshold: ALL
maxFileSize: 100MB
currentLogFilename: ./logs/max-file-size-example.log
archivedLogFilenamePattern: ./logs/max-file-size-example-%i.log.gz
archivedFileCount: 5

Java log4j No appenders could be found for logger

I am trying to make a custom logger and appender in log4j, but I am geting confusing error messages.
Here's the error:
[n.a.:n.a.] 19.Apr.2016 15:54 81 [ preRegister] ERROR stderr - log4j:WARN No appenders could be found for logger (datenImportLogger).
[n.a.:n.a.] 19.Apr.2016 15:54 81 [ preRegister] ERROR stderr - log4j:WARN Please initialize the log4j system properly.
[n.a.:n.a.] 19.Apr.2016 15:54 81 [ preRegister] ERROR stderr - log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Here's my config:
# datenImportLogger
log4j.logger.datenImportLogger=datenImportFileAppender
log4j.additivity.datenImportLogger=false
log4j.appender.datenImportFileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.datenImportFileAppender.File=java/log/datenimport.log
log4j.appender.datenImportFileAppender.MaxBackupIndex=5
log4j.appender.datenImportFileAppender.MaxFileSize=5MB
log4j.appender.datenImportFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.datenImportFileAppender.layout.ConversionPattern=[%X{USER_CODE}:%X{CALLER_ID}] %d{dd.MMM.yyyy HH:mm:ss,SSS} - %m%n
Have I missed something?
Are there any debug Abilities which provide debug on runtime,
because -Dlog4j.debug is not posible.
Logger should be called in code like :
private static final Logger logger = Logger.getLogger("datenImportLogger");
Root Logger is already configured.
The line
log4j.logger.datenImportLogger=datenImportFileAppender is problematic, it miss the level definition
The logger definition should be:
log4j.logger.loggerName=[level|INHERITED|NULL], [appenderName1, appenderName2,...]
source: The Complete Log4j Manual
e.g.
log4j.logger.datenImportLogger=INFO, datenImportFileAppender
try placing log4j.debug=true in top of the log4.propeties file it should provide additional logging information (although it will have affect only after the configurations are parsed )

multiple log levels in same log file in log4j

How can multiple log levels added to the same log file in log4j?
For example:
log4j.rootLogger=INFO,WARN,stdout,file
It gives the log4j error when application start as:
Could not instantiate appender named WARN.
The purpose of the threshold is to tell log4j to ignore all logging requests with a priority lower than what you specify. Specifying a given threshold does not limit you to logging with that threshold.
FileAppender fa = new FileAppender();
fa.setThreshold(Level.INFO);
fa.setAppend(true);
Logger.getRootLogger().addAppender(fa);
In the above code, the appender has been configured to operate with a threshold of INFO. This means that the following code will not log, because DEBUG is a lower priority than INFO:
Logger logger = Logger.getLogger(SomeClass.class);
logger.debug("This will not log");
But this code will log:
logger.warn("This debug message will log.");
logger.error("And this error message will also log.");
In this case, both WARN and ERROR have a higher priority than INFO.

log4j not logging to file

I've got a simple Tomcat web service that I'd like to see the logs for. I figured log4j would be the easiest solution. So far it will log to the in my dev environment, but it won't log to a file.
Here is my log4j.properties file (located in the src/ folder):
#Add these properties to all CallRouter-->data-->ddlog4j.properties files at the bottom to configure the Transactions.jar logging for DB and WS messaging.
log4j.rootCategory=ALL, MAIN_LOG
log4j.rootLogger=DEBUG,console
#Defines the <logging level>, <appender> for custom logging.
log4j.category.com.ddvc.android.resource=INFO, SupportWebServices
#### Transactions.jar appender INFO setup
log4j.logger.com.ddvc.android.resource=INFO
log4j.appender.ResourceInfo=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ResourceInfo.File=C:/test/SupportWebServices.log
log4j.appender.ResourceInfo.Append=true
log4j.appender.ResourceInfo.DatePattern='.' yyyy-MM-dd HH-mm
log4j.appender.ResourceInfo.layout=org.apache.log4j.PatternLayout
log4j.appender.ResourceInfo.layout.ConversionPattern=%d{[yyyy-MM-dd HH:mm:ss:SSS]} %p %c{1} (%M: %L) - %m%n
log4j.appender.ResourceInfo.Threshold=INFO
# Output to Console
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{[yyyy-MM-dd HH:mm:ss]} %p %c{1} (%M: %L) - %m%n
log4j.appender.CONSOLE.Threshold=CONSOLE
And in my java files I have (located in src/com/ddvc/android/resource):
import org.apache.log4j.Logger;
#Path("/pulse")
#Component
#Scope("request")
public class PulseResource {
private final static Logger LOGGER = Logger.getLogger(PulseResource.class.getName());
#GET
#Path("list")
#Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<Pulse> postXML() {
LOGGER.info("Start: list");
}
}
Like I said I can see the logs to the Console:
INFO [2015-02-19 15:19:34,961] [http-bio-8080-exec-3] [PulseResource] [] - Start: list
But I don't see any file created or logged to in the C:\test folder. (plan to change it to ${catalina.base}\logs\SupportWebServices.log)
Try changing
log4j.rootLogger=DEBUG,console
to
log4j.rootLogger=DEBUG,console,ResourceInfo
remove this line:
log4j.rootCategory=ALL, MAIN_LOG
edit this line:
log4j.rootLogger=DEBUG,console,ResourceInfo

Categories