I have developed a SpringBoot 2.1.3 WebApp with Thymeleaf 3. For quick testing purpose I create a fat jar with two SQL Procedure which automatically create the DB if it is not present and fill typological table if they are empty.
Now I put my .jar in a CentOS server and launch it by the command:
java -jar mywebapp.jar
All works perfectly but I find a bug in a form submit and I would like to examine the server (embedded) logs.
Which logging level I have to use in the below configuration inside the application.properties:
logging.level.org.apache.tomcat=?
logging.level.org.apache.catalina=?
And where I can find the log text file inside a Unix machine?
Thank you
First of all with embedded tomcat you have to enable log by adding to you application.properties
server.tomcat.accesslog.enabled=true
to specify base directory if you want to save log other then temp folder , also folder that will contain logs
server.tomcat.basedir=tomcat
server.tomcat.accesslog.directory=logs
you can also specify suffix and prefix for logs file
server.tomcat.accesslog.suffix=.log
server.tomcat.accesslog.prefix=access_log
for more properties see here list of common properties , search for tomcat and logging
Also adding logging level as mentioned by the PO in the comment add
logging.level.org.apache.tomcat=ALL
Related
I need your help on two issues :
1// I have a spring batch app that has this application.properties file :
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.url=jdbc:oracle:xxxxxxxx
ClassApp=xxxx
Country=xxxxx
spring.batch.initialize-schema=always
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
CRON_EXPRESSION=xxxxx
I want to externalize this configuration to an external file in a specific location and pass it then in the jvm when i run the final jar generated by my application.
Because the jar will be run on a centos machine later and all the variables in the properties file should get their values from that external file !!
How can i do this ?
2// Also, i have some log feature in my app like this one :
log.debug("CreateQuartzJob is running......");
But i want to externalize application logs to an external file also with all execution details too.
How can i make these two features pleaaase ?
Thank you for help :)
As for external configuration, you can use the "additional-location" argument when running your application. Just create a properties or yaml file, e.g., application.yml, and run your jar like this:
java -jar myJar.jar
--spring.config.additional-location=file:/some/directory/application.yml
I know this question has answered many a time with most useful answer as below,
Where to place and how to read configuration resource files in servlet based application?
However, We have some special requirement as below,
Webapp will be deployed to tomcat.
Normal java app in form of .jar will be placed under folder /myapp
myappConfig.property file will be placed under /myapp
Directory Structure on client machine
/myapp
/myapp.jar
/assests/myappConfig.property
/tomcat/webapps/myapp.war
Basically myapp.jar and myapp.war will access sql db connection values for MySql database connection and db operations.
Accessing myappConfig.property from myapp.jar --> Working fine
File jarPath = new File(Myapp.class.getProtectionDomain().getCodeSource().getLocation().getPath());
String propertiesPath = jarPath.getParent();
System.out.println(" propertiesPath-" + propertiesPath);
mainProperties.load(new FileInputStream(propertiesPath + "\\assets\\myapp.property"));
Can anyone help/suggest how to implement,
Accessing myappConfig.property file from mywebapp,
provided run time change in myappConfig.property file does not required myapp.war to be redeployed
Thanks for your help in advance.
edit
Below is the steps in which we want to deliver the project to client.
Below is my app directory
/myapp
/myapp.jar
/assests/myappConfig.property
/tomcat/webapps/myapp.war
pack everything in one package with some packaging tool.
Run this package in client machine at any location and it will have same directory structure as above
Here, I do not want to hard code any location in webapp or tomcat for "/assests/myappConfig.property"
Normal Java app I can read property file but for wepapp I am not getting clear idea for how to do that?
You can add a <context> to tomcat/conf/server.xml (in this example, linux path):
<Context docBase="/home/yourusername/tomcat/assests" path="/assets" />
If you are using Windows:
<Context docBase="C:\path\to\myapp\assets" path="/assets" />
And then you can access it like any other resource within your webapp (e.g.: /assets/myappConfig.property).
If you are using JDBC for example, you could store the connection properties in a Singleton and request it from there, and that class could take care of change checks on that file.
i want developers to be able to locally override some configuration properties. (let's say we work on google drive and everyone should test it on its own account).
i don't want to override properties using command line (because it has to be set inside every IDE configuration and on every CLI run).
what i want is: application should use all the standard spring boot config files (application.yml etc) and also look for e.g. local.yml (on the classpath) or some file inside user.home. and those additional files should override other settings.
how to add new yml resources and order them correctly?
edit: i know spring's default orders and locations. question is about adding new ones
If you look in the Spring Boot documentation about the locations for configuration files (http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config), you can see, that they are loaded from the following places (amongst others):
Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
Application properties outside of your packaged jar (application.properties and YAML variants).
There are two default locations where they are loaded from ( see http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-application-property-files):
A /config subdirectory of the current directory.
The current directory
Current directory in this case means the working directory for the Java process (Usually the directory where the JAR is located, or in case of running with in the IDE, usually the project root folder). So the developers just can place their own configuration files in that places and they are automatically loaded (and will override properties within the JARs). Add that files to .gitignore (or .svnignore or ...) and they won't accidentally committed into your repository.
There's a new way to do this, after Spring Boot v2.4, by using spring.config.import: https://spring.io/blog/2020/08/14/config-file-processing-in-spring-boot-2-4#importing-additional-configuration
By adding this part to your application.yml file, you should be able to import the additional configuration:
spring:
config:
import: local.yml
The article also has this section:
Imports can be considered as additional documents inserted just below the document that declares them. They follow the same top-down ordering as regular multi-document files: An import will only be imported once, no matter how many times it is declared.
So the contents of local.yml should be handled as if they were appended to the end of application.yml, thereby allowing you to override any property in application.yml.
From Spring Boot Documentation : Application property files:
SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment:
A /config subdirectory of the current directory.
The current directory
A classpath /config package
The classpath root
The list is ordered by precedence (properties defined in locations higher in the list override those defined in lower locations).
This also goes for yaml, so you everyone can add application.yml under config directory, under the directory you run the spring boot jar from.
You can also customize the extra configuration file to be local.yml if you'd like by using spring.config.location:
--spring.config.location=classpath:/application.yml,classpath:/local.yml
Note however:
spring.config.name and spring.config.location are used very early to determine which files have to be loaded so they have to be defined as an environment property (typically OS env, system property or command line argument).
To provide the configuration from external config file in spring-boot application -
-Dspring.config.location=file:/home/vfroot/Workspace/project/MODULE_HOME/application.yaml
this command can be run with terminal:
mvn clean install -Dspring.config.location
= file:/home/vfroot/Workspace/MODULE_HOME/application.yaml
or need to set in Eclipse VM argument.
Also to set the active profiles :
-Dspring.profiles.active=dev
Well, since i am new in Spring Boot & Restfull Web Services. However, i managed to add a new .yml file to mange database and server port.
Instructions that i followed:
Project File.
Other Sources
src/main/resources
default package
right click on "default package"
add new YAML FILE
Or of YAML File option not available
5. right click on "default package"
6. then in categories: other --> File Types: YAML File
I have setup Solr 4.7 before and I had configured solrconfig.xml file in my core for dataimport requestHandler and it was working fine.
But when I setup Solr 5.1.0, what is the location of solrconfig.xml file for particular core? Where is it located?
When you try SolrCloud for the first time using the bin/solr -e cloud, the related configset gets uploaded to zookeeper automatically and is linked with the newly created collection.
The below command would start SolrCloud with the default collection name (gettingstarted) and default configset (data_driven_schema_configs) uploaded and linked to it.
here is the path for the config files
../solr-5.1.0/server/solr/configsets
if you don't mention the configset, the default is "data_driven_schema_configs".
So you will find your config files here
../solr-5.1.0/server/solr/configsets/data_driven_schema_configs
If you run a hadoop flume node, as default it generates logs under /var/log/flume using log4j. The files will look like
/var/log/flume/flume-$FLUME_IDENT_STRING-$command-$HOSTNAME.log
According to the flume user guide here, the only way to change the flume log configuration is via flume-daemon.sh which runs flume node using the Flume Environment Variables like:
export FLUME_LOGFILE=flume-$FLUME_IDENT_STRING-$command-$HOSTNAME.log
export FLUME_ROOT_LOGGER="INFO,DRFA"
export ZOOKEEPER_ROOT_LOGGER="INFO,zookeeper"
export WATCHDOG_ROOT_LOGGER="INFO,watchdog"
The questions are:
if I want to change the log level from INFO to DEBUG, this is the only place to do it?
Is there a configuration somewhere I can do this?
what about I want to set some packages' log level to DEBUG while others stay INFO?
Check if the log4j.properties or log* related files exist to set the variables -- which will also allow you to check and have some components of the logging part do excessive/DEBUG while other do INFO.
Noticed that under /etc/flume/conf.empty, there is a log4j.properties. Copied it to /etc/flume/conf, restart the flume node service, the log4j.properties file starts taking effect.
The overriding order is like flume-env.sh->flume-daemon.sh->log4j.properties.
eg. if you set up your flume_root_logger to DEBUG in flue-daemon.sh, it will override whatever setting you have for root_logger in your log4j.properties.