I have a Spring Boot 2.7.2 web application. The Tomcat access log properties are defined as
server.tomcat.accesslog.enabled=TRUE
server.tomcat.accesslog.directory=log
server.tomcat.accesslog.pattern=%h %l %u [%t] "%r" %s %b "%{Referer}i" "%{User-Agent}i" %D [%I] "%{Host}i"
I'm not using any logback configuration files (like logback.xml or logback-spring.xml).
Locally, when using embedded Tomcat, the access logs are logged as configured. However, when I deploy the application to an external Tomcat, the used access log pattern seems to be a default pattern with less information and looks like this:
%h %l %u [%t] "%r" %s %b
How can I configure the access log pattern in a way that it works for embedded and external Tomcat?
A Spring Boot application can configure the embedded Tomcat regarding the access log pattern, but it can't configure the access log pattern of a standalone Tomcat it is deployed to.
In order to apply a custom access log pattern, you need to edit Tomcat's conf/server.xml file and need to adapt the existing AccessLogValve configuration, like this (relevant is the pattern attribute):
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" %D [%I] "%{Host}i"" />
Afterwards you need to restart Tomcat to apply this change. The access log files should then include the additional information of each request.
Note that this change affects the access logging of all applications deployed to the standalone Tomcat.
Related
I need, for performance reasons, get rid of org.jooq.tools.LoggerListener DEBUG log messages in Spring Boot application running inside Docker. None of the Spring Boot options like (Docker) env variable LOGGING_LEVEL_ORG_JOOQ=INFO in docker-compose.yml or Java system property -Dlogging.level.org.jooq=INFO passed to docker container in entry.sh do not remove these DEBUG messages reporting query execution details. Both option have been checked at Docker container level.
Even custom logback-perf.xml conf file, as in https://github.com/jOOQ/jOOQ/blob/master/jOOQ-examples/jOOQ-spring-boot-example/src/main/resources/logback.xml with DEBUG->INFO, pointed by LOGGING_CONFIG env var from docker-compose.yml does not prevent these debug messages. I have verified that the custom logback-perf.xml conf file is in use by changing appender patterns.
The best way to remove those messages in jOOQ directly, is to specify Settings.executeLogging = false, see here.
Obviously, there are also ways to set up loggers correctly, but I cannot see what you did from your description, or why that failed.
In our projects we have a strange problem with duplicate log entries in the log file.
We have multiple appenders but a single logger.
If the spring boot application is started on local machine using java -jar the problem is not reproducible.
The problem occurs only when the application started as a service.
How can i solve the problem.
The problem occurs only if a file appender configured and if the spring boot application started using /etc/init.d/ symlink.
The spring boot's default start script redirects all console logs into the configured log file.
As a result both the logback logger and start scripts writes in the same file, thus we see duplicate entries in the log file.
Using systemctl (or setting the LOG_FILE or LOG_FOLDER environment variables) will solve this problem.
If you cannot switch to systemd you can set the environment variables so that all stdout&stderr messages redirected to /dev/null:
export LOG_FOLDER=/dev
export LOG_FILENAME=null
I've a set of applications installed on a server that I want to start sending logs thru syslog to a remote Logstash server. For that, I've created a single external Logback configuration file containing a SyslogAppender pointing to the desired remote server.
As multiple applications will log to the same server, I've changed the log pattern to be the following:
<suffixPattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [${server_instance}] [${application_name}] %p ${PID:- } --- [%15.15t] %logger : %m%n</suffixPattern>
Where server_instance and application_name are command-line option arguments provided at startup.
Now I just simply set the logging.config property of all my apps pointing to the same Logback config file, and all the applications start sending the logs using the specified pattern to the desired server. That part works like a charm.
But the only problem I've is that Logback isn't able to determine the server_instance and the application_name properties and they appear as [server_instance_IS_NOT_DEFINED] and [application_name_IS_NOT_DEFINED] respectively.
Can I achieve this somehow using a single external configuration file?
Logback isn't able to see command-line arguments; those are seen by Spring alone.
Moved those command-line options arguments to system properties (i.e. "-Dserver_instance" and "-Dapplication_name" instead of "--server_instance" and "--application_name") and now everything's working as expected.
When I use intellijs' (12.1.4) built-in tomcat the logs are being written to the output tab of the debug panel and not to a the normal localhost log tab.
I followed this document and added my log4j.properties which works fine in the output tab but it still does write the logs to right tab.
When I pack the project and deploy it on standalone tomcat I can see the logs.
Normally I would not care but the problem with the output tab is that you can not search in it.
This is my log4j and I have tired it both with ConsoleAppender and RollingFileAppender.
log4j.rootLogger=TRACE, A1
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=${catalina.home}/logs/algo_js.log
log4j.appender.A1.MaxFileSize=500KB
log4j.appender.A1.MaxBackupIndex=5
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
Any ideas what I am missing?
Just clarify I added a pic.
In the application server Run/Debug configuration open the Logs tab and specify the full log file path there.
You can just search your disk for algo_js.log file and specify its location.
I can't get the configuration for Tomcat right to allow access to the Manager Webapp. We have configured tomcat-users.xml, manager.xml etc. When we allow access based on the IP address it works, but based on the hostname it doesn't. This is the configuration we use:
<Context privileged="true"
docBase="/path/to/tomcat_home/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteHostValve"
allow="localhost|otherhostname" deny="" />
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="172\.30\.\d+\.\d+|127\.0\.0\.1"/>
</Context>
When I remove the RemoteHostValve we can access the manager app (jmxproxy).
Any ideas?
Regards,
Johan-Kees
Check for the exact hostname that host is sending via http (for example with Wireshark), put the hostname with a prefix . into the config and make sure that the hostname is resolvable (i.e. via DNS and/or hosts)...
For reference see:
http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Remote%20Host%20Filter
http://tomcat.apache.org/tomcat-7.0-doc/config/engine.html
http://tomcat.apache.org/migration.html#Manager_application