in my app i can upload files (max size is 10MB). I created an exception handler for too big files, but console still shows warning that there was a try to upload too big file:
2020-09-30 01:38:59.306 WARN 2476 --- [nio-8080-exec-3] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException: the request was rejected because its size (26937892) exceeds the configured maximum (10485760)]
Exception handler:
#ExceptionHandler(MaxUploadSizeExceededException.class)
public void oversizedFilesHandler(MaxUploadSizeExceededException e){
accountService.writeExceptionToFile(e);
}
Is it possible to disable these warnings?
You can achieve that by adding log level to your properties file:
RULE : logging.level.xxxx=LEVEL
where:
LEVEL is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF.
xxxx is a package/class.
We apply the rule to your case:
logging.level.org.springframework.web=ERROR
Or even thinner:
logging.level.org.springframework.web.multipart =ERROR
Hence, only ERROR, FATAL and OFF level will be logged to you console.
Related
I am always getting "2019-04-09 07:24:23.389 WARN 11676 --- [nio-9095-exec-5] o.s.c.n.z.filters.post.SendErrorFilter : Error during filtering", for request which takes more than 1 second.
I have already tried to increase the timeout but none of them worked.
2019-04-09 07:24:23.389 WARN 11676 --- [nio-9095-exec-5] o.s.c.n.z.filters.post.SendErrorFilter : Error during filtering
com.netflix.zuul.exception.ZuulException:
at org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter.findZuulException(SendErrorFilter.java:114) ~[spring-cloud-netflix-zuul-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter.run(SendErrorFilter.java:76) ~[spring-cloud-netflix-zuul-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:117) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:157) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.FilterProcessor.error(FilterProcessor.java:105) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.ZuulRunner.error(ZuulRunner.java:112) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.http.ZuulServlet.error(ZuulServlet.java:145) ~[zuul-core-1.3.1.jar:1.3.1]
at com.netflix.zuul.http.ZuulServlet.service(ZuulServlet.java:83) ~[zuul-core-1.3.1.jar:1.3.1]
at org.springframework.web.servlet.mvc.ServletWrappingController.handleRequestInternal(ServletWrappingController.java:165) ~[spring-webmvc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at ava.lang.Thread.run(Thread.java:834) ~[na:na]
You can check my answer:
here
Hystrix readed timeout by default is 1 second, and you can change that in your application.yaml file. It can be done globally or per service.
Above issue is caused due to hysterix timeout.
The above issue can be solved by disabling the hystrix timeout or increasing the hysterix timeout as below :
# Disable Hystrix timeout globally (for all services)
hystrix.command.default.execution.timeout.enabled: false
#To disable timeout foror particular service,
hystrix.command.<serviceName>.execution.timeout.enabled: false
# Increase the Hystrix timeout to 60s (globally)
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000
# Increase the Hystrix timeout to 60s (per service)
hystrix.command.<serviceName>.execution.isolation.thread.timeoutInMilliseconds: 60000
The above solution will work if you are using discovery service for service lookup and routing.
Here is the detailed explaination : spring-cloud-netflix-issue-321
You are timing out on H2 console testing with postman or any other http testers because: Using Zuul...hysterix...you are trying to send the same exact object to the H2 database. This may be happening because you have validators on your models also. To resolve: make sure the json, xml or whatever it is objects are relatively unique by re-edit and then try to send request again.
I am trying to add a logger to one of my programs, mainly to replace the System.out.println(), and it seems to give me some problems.
This is my first time using a logger, so I am a noob at it.
I had a look at a multitude of links over the past days but still haven't managed to make my logger catch an exception; here are some of the links I looked at (some of them are 5 years old and might need updates):
oracle simple formatter
slf4j - interface logger
slf4j - simple logger
slf4j - faq
slf4j - message formatter
stackoverflow 1
stackoverflow 2
I am using:
slf4j-api-1.7.22.jar
slf4j-simple-1.7.22.jar
jdk1.8.0_71
IntelliJ 2016.3.2
The simpleLogger.properties is placed directly in the resources package, this file is loaded before the logger is created, the file is loaded correctly as I can modify the date-time as I need it to be (and other settings work as well).
Part of the Main class:
...
private Logger LOG; //field
...
public static void main(String[] args) {
launch(args);
}
...
#Override
public void start(Stage primaryStage) {
/*Create logger*/
createLogger();
LOG.info("Stage start.");
...
}
...
private void createLogger() {
try {
Properties properties = new Properties();
properties.load(LOGGER_PROPERTIES); //path to prop file
} catch (IOException e) {
e.printStackTrace();
}
LOG = LoggerFactory.getLogger(Main.class);
LOG.info("Logger initialised.");
LOG.trace("test trace"); //not working
LOG.debug("test debug"); //not working
LOG.info("test info");
LOG.warn("test warning");
LOG.error("test error");
}
The simpleLogger.properties file:
org.slf4j.simpleLogger.logFile=System.out
# org.slf4j.simpleLogger.defaultLogLevel=
# org.slf4j.simpleLogger.log.a.b.c=
org.slf4j.simpleLogger.showDateTime=true
org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss:SSS
org.slf4j.simpleLogger.showThreadName=false
org.slf4j.simpleLogger.showLogName=false
org.slf4j.simpleLogger.showShortLogName=true
org.slf4j.simpleLogger.levelInBrackets=true
# org.slf4j.simpleLogger.warnLevelString=
# THE FORMAT TRIED
#org.slf4j.simpleLogger.SimpleFormatter.format = [%1$tc] %4$s: %2$s - %5$s %6$s%n
#java.util.logging.SimpleFormatter.format = [%1$tc] %4$s: %2$s - %5$s %6$s%n
#java.util.logging.SimpleFormatter.format="%1$tc %2$s%n%4$s: %5$s%6$s%n"
#org.slf4j.simpleLogger.format=[%1$tc] %4$s: %2$s - %5$s %6$s%n %7$s
#org.slf4j.helpers.MessageFormatter.format = [%1$tc] %4$s: %2$s - %5$s %6$s%n %7$s
#java.util.logging.SimpleFormatter.format="%1$tc %2$s%n%4$s: %5$s%6$s%n"
Part of the class where I am attempting to create an exception:
LOG.info("Creating window - More info: loading.. .fxml");
try {
BP_INFO = FXMLLoader.load(getClass().getResource("/fxml/ImageInf_.fxml")); //HERE change back to ImageInfo.fxml
LOG.info("Creating window - More info: loaded .fxml successfully.");
} catch (IOException e) {
// HERE not showing anything below
System.out.println("CATCH - From Sys out");
LOG.error("CATCH - EXCEPTION", (Throwable) e);
LOG.error("Creating window - More info: Exception");
LOG.error("Creating window - More info: Exception", e);
LOG.error("Creating window - More info: Exception {}", e);
LOG.error("Creating window - More info: Exception {} {} {}", Level.INFO, e.getMessage(), e);
// e.printStackTrace();
}
Console output:
12:17:08:995 [INFO] Main - Logger initialised.
12:17:08:996 [INFO] Main - test info
12:17:08:997 [WARN] Main - test warning
12:17:08:997 [ERROR] Main - test error
12:17:08:997 [INFO] Main - Stage start.
...
12:17:27:140 [INFO] View - Creating window - More info: loading.. .fxml
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
...
Problem 1:
As you can see trace and debug are not working. I have tried all the properties in the prop. file and some more as well but so far did not manage to catch any exception or apply a specific format.
Problem 2:
As you can see, the exception is also not logged at all.
Additional info: I have reset IntelliJ settings, I have been cleaning the win %temp% folder various times, I have been cleaning caches and restarted Intellij various times; all this in an attempt if the prop. file was not read correctly or kept somewhere in a cache.
Any help is much appreciated. Please respond in a simplistic way.
We may use Slf4j within a JavaFX project by using only these dependencies:
slf4j-api-1.7.22.jar
slf4j-simple-1.7.22.jar
Here's an example Application class:
...
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Todo extends Application {
private static final Logger log = LoggerFactory.getLogger(Todo.class);
...
public static void main(String[] args) {
log.info("launching...");
log.warn("launching...");
log.error("launching...");
log.debug("launching...");
log.trace("launching...");
launch(args);
}
}
Slf4j simple already has default settings that may be fine for various scenarios. That not being the case, the logger may be configured by adding simplelogger.properties to the classpath, which will be automatically picked up by Slf4j on application startup. The javadoc for the SimpleLogger class nicely enlists all the properties that may be configured.
The contents of a simplelogger.properties file that modifies the log level only:
org.slf4j.simpleLogger.defaultLogLevel=trace
And here is the output when running with the log level set to trace:
[main] INFO todo.Todo - launching...
[main] WARN todo.Todo - launching...
[main] ERROR todo.Todo - launching...
[main] DEBUG todo.Todo - launching...
[main] TRACE todo.Todo - launching...
Problem #1 (trace and debug level is not logged)
From the doc of SimpleLogger:
org.slf4j.simpleLogger.defaultLogLevel - Default log level for all
instances of SimpleLogger. Must be one of ("trace", "debug", "info",
"warn", "error" or "off"). If not specified, defaults to "info".
Because the defult level is info, and trace and debug levels are "under" info, they will be filtered out by the logger and will not reach the appender.
So if you add the following line in the properties file:
org.slf4j.simpleLogger.defaultLogLevel = trace
you should see also messages with trace and debug level.
Problem #2 (the error trace is not logged properly)
You are catching IOExceptions, but an InvocationTargetException is actually thrown (which one is not catched), therefore the execution will never enter your catch block. What you see on the console is an unhandled runtime exception printed.
As described here, there could be per user configuration of Maven logging for one installation.
I copied default simplelogger.properties to $M2_HOME/conf/logging and added:
org.slf4j.simpleLogger.log.com.example=trace
and it logs fine.
This is not maybe the best solution, but the one I've found fitting my needs. You can log DEBUG but not TRACE as I remember I've read somewhere.
I'm using mule version 3.5.0. in a Java web application.
I use the mule xml configuration and defined a file:inbound-endpoint:
<file:inbound-endpoint path="${home.dir}/out" moveToDirectory="${home.dir}/out/hist" responseTimeout="10000" connector-ref="input"/>
with the connector being:
<file:connector name="input" fileAge="10000" streaming="false" autoDelete="false">
<service-overrides messageFactory="org.mule.transport.file.FileMuleMessageFactory" />
</file:connector>
Now I have the problem that when I want to move a file to the directory that contains already a file with the same name, an error is thrown in mule and is repeated continuously, generating +1GB logfiles:
[[hip].input.receiver.05] 18:33:55,234 [ERROR] org.mule.exception.AbstractExceptionListener.logException(AbstractExceptionListener.java:307) -
********************************************************************************
Message : Failed to move file "D:\hip\batch\taxiAsService\out\0.A.REQD.00000000000003.xml" to "D:\hip\batch\taxiAsService\out\hist\0.A.REQD.00000000000003.xml". The file might already exist.
Code : MULE_ERROR-11004
--------------------------------------------------------------------------------
Exception stack is:
1. Failed to move file "D:\hip\batch\taxiAsService\out\0.A.REQD.00000000000003.xml" to "D:\hip\batch\taxiAsService\out\hist\0.A.REQD.00000000000003.xml". The file might already exist. (org.mule.api.DefaultMuleException)
org.mule.transport.file.FileMessageReceiver:561 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/DefaultMuleException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.DefaultMuleException: Failed to move file "D:\hip\batch\taxiAsService\out\0.A.REQD.00000000000003.xml" to "D:\hip\batch\taxiAsService\out\hist\0.A.REQD.00000000000003.xml". The file might already exist.
at org.mule.transport.file.FileMessageReceiver.moveAndDelete(FileMessageReceiver.java:561)
at org.mule.transport.file.FileMessageReceiver.access$100(FileMessageReceiver.java:58)
at org.mule.transport.file.FileMessageReceiver$2.process(FileMessageReceiver.java:433)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
[[hip].input.receiver.05] 18:33:55,240 [ERROR] org.mule.exception.AbstractExceptionListener.logException(AbstractExceptionListener.java:307) -
********************************************************************************
Message : Failed to move file "D:\hip\batch\taxiAsService\out\0.A.REQD.00000000000004.xml" to "D:\hip\batch\taxiAsService\out\hist\0.A.REQD.00000000000004.xml". The file might already exist.
Code : MULE_ERROR-11004
--------------------------------------------------------------------------------
Exception stack is:
1. Failed to move file "D:\hip\batch\taxiAsService\out\0.A.REQD.00000000000004.xml" to "D:\hip\batch\taxiAsService\out\hist\0.A.REQD.00000000000004.xml". The file might already exist. (org.mule.api.DefaultMuleException)
org.mule.transport.file.FileMessageReceiver:561 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/DefaultMuleException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.DefaultMuleException: Failed to move file "D:\hip\batch\taxiAsService\out\0.A.REQD.00000000000004.xml" to "D:\hip\batch\taxiAsService\out\hist\0.A.REQD.00000000000004.xml". The file might already exist.
at org.mule.transport.file.FileMessageReceiver.moveAndDelete(FileMessageReceiver.java:561)
at org.mule.transport.file.FileMessageReceiver.access$100(FileMessageReceiver.java:58)
at org.mule.transport.file.FileMessageReceiver$2.process(FileMessageReceiver.java:433)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
[[hip].input.receiver.05] 18:33:55,242 [ERROR] org.mule.exception.AbstractExceptionListener.logException(AbstractExceptionListener.java:307) -
********************************************************************************
Message : Failed to move file "D:\hip\batch\taxiAsService\out\0.A.REQD.00000000000005.xml" to "D:\hip\batch\taxiAsService\out\hist\0.A.REQD.00000000000005.xml". The file might already exist.
Code : MULE_ERROR-11004
--------------------------------------------------------------------------------
Exception stack is:
1. Failed to move file "D:\hip\batch\taxiAsService\out\0.A.REQD.00000000000005.xml" to "D:\hip\batch\taxiAsService\out\hist\0.A.REQD.00000000000005.xml". The file might already exist. (org.mule.api.DefaultMuleException)
org.mule.transport.file.FileMessageReceiver:561 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/DefaultMuleException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.DefaultMuleException: Failed to move file "D:\hip\batch\taxiAsService\out\0.A.REQD.00000000000005.xml" to "D:\hip\batch\taxiAsService\out\hist\0.A.REQD.00000000000005.xml". The file might already exist.
at org.mule.transport.file.FileMessageReceiver.moveAndDelete(FileMessageReceiver.java:561)
at org.mule.transport.file.FileMessageReceiver.access$100(FileMessageReceiver.java:58)
at org.mule.transport.file.FileMessageReceiver$2.process(FileMessageReceiver.java:433)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Is there a way to:
limit the logging? Like that it is only displayed one?
Can I eventually overwrite the existing file?
Thanks for reading.
The problem for the excessive logging is because you have the autoDelete property to false. So, because the move operation is failing (and the source file is not being deleted), the flow is polling the source file recursively.
The workaround would be to set the autoDelete to true and use the file:outbound-endpoint to write the source file content into the out directory (instead of using the moveToDirectory property in the inbound-endpoint). This way you can customize the destination filename to avoid writing existing files.
I have the following log4j configuration
log4j.rootLogger=ERROR, myappender1
log4j.appender.myappender1=org.apache.log4j.RollingFileAppender
log4j.appender.myappender1.File=D:/phase10/myLog1.log
log4j.appender.myappender1.MaxFileSize=10MB
log4j.appender.myappender1.MaxBackupIndex=10
log4j.appender.myappender1.layout=org.apache.log4j.PatternLayout
log4j.appender.myappender1.layout.ConversionPattern=%m%n
log4j.appender.myappender2=org.apache.log4j.RollingFileAppender
log4j.appender.myappender2.File=D:/phase10/myLog2.log
log4j.appender.myappender2.MaxFileSize=10MB
log4j.appender.myappender2.MaxBackupIndex=10
log4j.appender.myappender2.layout=org.apache.log4j.PatternLayout
log4j.appender.myappender2.layout.ConversionPattern=%m%n
log4j.logger.com.my.package=INFO, myappender2
log4j.addivity.com.my.package=false
After this I run app and see in both logs
INFO WARN ERROR messages.
Does my configuration wrong ?
expected result - in myLog1.log only ERROR messages
in myLog2.log INFO WARN ERROR messages.
If to replace log4j.addivity.com.my.package=false with log4j.addivity=false I see same result)
update
thanks #Kevin Tanzer
after replacing 'addivity' with 'additivity' In myLog1 I see no messages. in myLog2 I see all messages
All mesages logged from com.my.package
The last configuration item should be 'additivity' not 'addivity', which may be causing your problems. You've defined two separate appenders.
The myappender1 will have only ERROR (and FATAL) messages.
The myappender2 will get INFO, WARN and ERROR (and FATAL) messages because INFO is a lower severity than the others. That is, the order is:
TRACE,
DEBUG,
INFO,
WARN,
ERROR and
FATAL
I am using log4j properties to capture the logs.i wants to remove error info from INFO file.
**
INFO
** file is below:
5:39:02,068 INFO BluSyncLauncher:156 - Application started
05:39:02,080 INFO BluSyncLauncher:586 - Loading UI
05:39:02,263 INFO BackupCrawlDAOImpl:470 - sqlExeception in CREATE_ACTIVITY_TABLEjava.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (duplicate column name: IsFolder)
05:39:02,264 **
ERROR
** BackupActivityHistoryDAOImpl:706 - sqlExeception in CREATE_ACTIVITY_TABLEjava.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (duplicate column name: restartid)
05:39:03,803 INFO BluSyncLauncher:533 - Started crawl (backup)
05:39:03,827 INFO BluSyncLauncher:543 - Starting Activity Timer
05:39:03,860 INFO BluSyncLauncher:557 - Load SystemTrayUI
05:39:10,612 **
ERROR
** BackupPolicyDAOImpl:280 - SQLException while inserting backup policy details
java.sql.SQLException: [SQLITE_CONSTRAINT] Abort due to constraint violation (BACKUP_POLICY.policyGroupName may not be NULL)
at org.sqlite.DB.newSQLException(DB.java:383)
at org.sqlite.DB.newSQLException(DB.java:387)
at org.sqlite.DB.execute(DB.java:342)
at org.sqlite.PrepStmt.execute(PrepStmt.java:65)
at com.parablu.epa.common.dao.BackupPolicyDAOImpl.insertBackupPolicyDetailsToTable(BackupPolicyDAOImpl.java:273)
at com.parablu.epa.common.service.settings.PolicyManagementServerHelper.createGroupPolicyAndChildDetails(PolicyManagementServerHelper.java:306)
at com.parablu.epa.common.service.settings.PolicyManagementServerHelper.loadBackupPolicyElement(PolicyManagementServerHelper.java:245)
at com.parablu.epa.service.backup.LinuxCheckBackupPolicy.checkGroupPolicy(LinuxCheckBackupPolicy.java:140)
at com.parablu.epa.service.alarm.LinuxPolicyRefreshHelper$1.run(LinuxPolicyRefreshHelper.java:55)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Loggers may be assigned levels. The set of possible levels, that is:
TRACE,
DEBUG,
INFO,
WARN,
ERROR and
FATAL
are defined in the org.apache.log4j.Level class. Although we do not encourage you to do so,
you may define your own levels by sub-classing the Level class.
Level Inheritance
A logging request is said to be enabled if its level is higher than or equal to the level of its logger. Otherwise, the request is said to be disabled. A logger without an assigned level will inherit one from the hierarchy. This rule is summarized below.
Basic Selection Rule
A log request of level p in a logger with (either assigned or
inherited, whichever is appropriate) level q, is enabled if p >= q.
UPDATE:
In Log4j2 version 2.0.2
If you wish to change the root logger level, do something like this :
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(level);
ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig.
I get some information from log4j filter
and read the log4j source code. I found it is possible.
Do like this:
appender.File.type=File
appender.File.name=infolog
appender.File.layout.type=PatternLayout
appender.File.layout.pattern=%d %p %C{1.} [%t] %m%n
appender.File.filename=${infologfilename}
#here! add filter named star, type is ThresholdFilter
appender.File.filter.star.type=ThresholdFilter
#level you want to filter
appender.File.filter.star.level=info
#if mathched the level, the log higher then the level will not output
appender.File.filter.star.onMatch=DENY
#if mismathed,output
appender.File.filter.star.onMisMatch=ACCEPT
May be it can help you.
I suggest you to use xml configuration,easy to read and edit.