I have a logging.properties file in my Java AppEngine project (using java.util.logging) that looks like this:
# Set the default logging level for all loggers to WARNING
.level = INFO
# tighten logging on the DataNucleus Categories
DataNucleus.JDO.level=WARN
# - All messages general to JDO
DataNucleus.JPA.level=WARN
# - All messages general to JPA
DataNucleus.Persistence.level=WARN
# - All messages relating to the persistence process
DataNucleus.Query.level=WARN
# - All messages relating to queries
DataNucleus.Lifecycle.level=WARN
# - All messages relating to object lifecycle changes
DataNucleus.Cache.level=WARN
# - All messages relating to the DataNucleus Cache
DataNucleus.ClassLoading.level=WARN
# - All exceptions relating to class loading issues
DataNucleus.MetaData.level=WARN
# - All messages relating to MetaData
DataNucleus.Management.level=WARN
# - All messages relating to Management
DataNucleus.General.level=WARN
# - All general operational messages
DataNucleus.Connection.level=WARN
# - All messages relating to Connections.
DataNucleus.JCA.level=WARN
# - All messages relating to Connector JCA.
DataNucleus.Transaction.level=WARN
# - All messages relating to transactions
DataNucleus.Plugin.level=WARN
# - All messages relating to DataNucleus plug-ins
DataNucleus.ValueGeneration.level=WARN
# - All messages relating to value generation
DataNucleus.Datastore.level=WARN
# - All general datastore messages
DataNucleus.Datastore.Schema.level=WARN
# - All schema related datastore log messages
DataNucleus.Datastore.Persist.level=WARN
# - All datastore persistence messages
DataNucleus.Datastore.Retrieve.level=WARN
# - All datastore retrieval messages
DataNucleus.Datastore.Native.level=WARN
# - Log of all 'native' statements sent to the datastore
DataNucleus.Enhancer.level=WARN
# - All messages from the DataNucleus Enhancer.
DataNucleus.SchemaTool.level=WARN
# - All messages from DataNucleus SchemaTool
DataNucleus.IDE.level=WARN
# - Messages from the DataNucleus IDE.
Sadly, now I am getting log messages such as:
2012-04-17 16:13:45.112
org.datanucleus.plugin.NonManagedPluginRegistry resolveConstraints: Bundle "org.datanucleus.jpa" has an optional dependency to "org.datanucleus.enhancer" but it cannot be resolved
I 2012-04-17 16:13:45.115
org.datanucleus.plugin.NonManagedPluginRegistry resolveConstraints: Bundle "org.datanucleus" has an optional dependency to "org.eclipse.equinox.registry" but it cannot be resolved
I 2012-04-17 16:13:45.719
org.datanucleus.PersistenceConfiguration setProperty: Property datanucleus.rdbms.sql.allowAllSQLStatements unknown - will be ignored
I 2012-04-17 16:13:47.806
org.datanucleus.store.appengine.MetaDataValidator validate: Performing appengine-specific metadata validation for in.animeshpathak.nazdeeq.models.Note
Can someone please tell me how I can properly configure my logging.properties file? I need the general loglevel to INFO in order to see debug messages from my code at this moment, but want to set all DataNucleus loglevels to WARN.
Thanks.
Actually, if you want to see debug messages from your code you need FINEST level, not INFO.
Try replacing your logging.properties with this:
# Set the default logging level for all loggers to FINEST
.level=FINEST
# Set the default logging level for ORM, specifically, to WARNING
DataNucleus.JDO.level=WARNING
DataNucleus.Persistence.level=WARNING
DataNucleus.Cache.level=WARNING
DataNucleus.MetaData.level=WARNING
DataNucleus.General.level=WARNING
DataNucleus.Utility.level=WARNING
DataNucleus.Transaction.level=WARNING
DataNucleus.Datastore.level=WARNING
DataNucleus.ClassLoading.level=WARNING
DataNucleus.Plugin.level=WARNING
DataNucleus.ValueGeneration.level=WARNING
DataNucleus.Enhancer.level=WARNING
DataNucleus.SchemaTool.level=WARNING
Per DataNucleus's suggestion, this is much more concise:
# Set the default logging level for all loggers to FINEST
.level=FINEST
# Set the default logging level for ORM, specifically, to WARNING
DataNucleus.level=WARNING
Related
I have a number of questions here (and I'm new to Spring Boot).
Our project's existing codebase uses YAML but no .properties file that I can see anywhere. My reading of usual Spring Boot tutorial uses .properties file.
(1) Is it possible to use application.yml as replacement for application.properties?
(2) Where is the default directory/file where the Spring Boot's embedded Tomcat server dumps its logs?
I need to modify the configuration such that we have custom directory to dump embedded Tomcat server logs. According to here, it should be
server.tomcat.basedir=my-tomcat
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)
That is how it's done if using application.properties way.
(3) Assuming YAML can replace the .properties file entirely, how can I do the above configuration in YAML? Do I need to edit something in the Java source files in order for the configuration in YAML to take effect (that is Tomcat logs going into specific directory that I want)?
Yes. Completely
Spring boot doesn't log to a file by default (as far I know).
Whether you use yaml or properties file, spring boot uses this configuration to bootstrap the application. The below from here
# LOGGING
logging.config= # Location of the logging configuration file. For instance `classpath:logback.xml` for Logback
logging.exception-conversion-word=%wEx # Conversion word used when logging exceptions.
logging.file= # Log file name. For instance `myapp.log`
logging.level.*= # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG`
logging.path= # Location of the log file. For instance `/var/log`
logging.pattern.console= # Appender pattern for output to the console. Only supported with the default logback setup.
logging.pattern.file= # Appender pattern for output to the file. Only supported with the default logback setup.
logging.pattern.level= # Appender pattern for log level (default %5p). Only supported with the default logback setup.
logging.register-shutdown-hook=false # Register a shutdown hook for the logging system when it is initialized.
server.tomcat.accept-count= # Maximum queue length for incoming connection requests when all possible request processing threads are in use.
server.tomcat.accesslog.buffered=true # Buffer output such that it is only flushed periodically.
server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be relative to the tomcat base dir or absolute.
server.tomcat.accesslog.enabled=false # Enable access log.
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd # Date format to place in log file name.
server.tomcat.accesslog.pattern=common # Format pattern for access logs.
server.tomcat.accesslog.prefix=access_log # Log file name prefix.
server.tomcat.accesslog.rename-on-rotate=false # Defer inclusion of the date stamp in the file name until rotate time.
server.tomcat.accesslog.request-attributes-enabled=false # Set request attributes for IP address, Hostname, protocol and port used for the request.
server.tomcat.accesslog.rotate=true # Enable access log rotation.
server.tomcat.accesslog.suffix=.log # Log file name suffix.
server.tomcat.additional-tld-skip-patterns= # Comma-separated list of additional patterns that match jars to ignore for TLD scanning.
server.tomcat.background-processor-delay=30 # Delay in seconds between the invocation of backgroundProcess methods.
server.tomcat.basedir= # Tomcat base directory. If not specified a temporary directory will be used.
server.tomcat.internal-proxies=10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\
192\\.168\\.\\d{1,3}\\.\\d{1,3}|\\
169\\.254\\.\\d{1,3}\\.\\d{1,3}|\\
127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\
172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses.
server.tomcat.max-connections= # Maximum number of connections that the server will accept and process at any given time.
server.tomcat.max-http-post-size=0 # Maximum size in bytes of the HTTP post content.
server.tomcat.max-threads=0 # Maximum amount of worker threads.
server.tomcat.min-spare-threads=0 # Minimum amount of worker threads.
server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value.
server.tomcat.protocol-header= # Header that holds the incoming protocol, usually named "X-Forwarded-Proto".
server.tomcat.protocol-header-https-value=https # Value of the protocol header that indicates that the incoming request uses SSL.
server.tomcat.redirect-context-root= # Whether requests to the context root should be redirected by appending a / to the path.
server.tomcat.remote-ip-header= # Name of the http header from which the remote ip is extracted. For instance `X-FORWARDED-FOR`
server.tomcat.uri-encoding=UTF-8 # Character encoding to use to decode the URI.
Yes. You can change these to YML. All you need is to replace properties file with yml file. You could even have both in your workspace (spring looks at both application.properties and application.yml)
You can manually do the conversion or even with plugins.
A simple line like
logging.level.netpl.com = DEBUG
changes to
logging:
level:
netpl.com: DEBUG
How do I turn on SQL query logging for a Dropwizard application? I would like it to only log SQL in certain environments.
In your application YAML file add a "logging:" definition like the following:
# Logging settings.
logging:
# The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
level: INFO
# Logger-specific levels.
loggers:
# Overrides the levels of certain packages or files.
"org.skife.jdbi.v2": TRACE
Are you using jdbi?, if so, this is working for me:
Set a logger when you create the DBI instance:
DBI dbi = new DBI(dataSource);
dbi.setSQLLog(new SLF4JLog());
Add this configuration to your config file:
logging:
level: INFO
loggers:
"org.skife": TRACE
I guess this idea should be also valid for Hibernate or any other DB access framework.
Please have a look at the image below.
I am running Log4J but using the TimeAndSizeRollingFileAppender provided from http://www.simonsite.org.uk/ .
According to the site it should be a good version that is used by many companies.
What could be the cause for all these processes running independently?
I am running a WAR file, and I have this configuration:
# DEBUG < INFO < WARN < ERROR < FATAL ==> DEBUG SHOWS ALL, WARN will show WARN, ERROR and FATAL
# Variable
momomo.log.pattern=%n================================%n%d{yyyy-MM-dd-HH-mm-ss}%n%c%n%m %x%n--------------------------------%n
momomo.log.datepattern='.'yyyy-MM-dd
momomo.log.maxfilesize=5MB
# Root logger option logs all to file
log4j.rootLogger=debug, error, info, console
# global info 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=${momomo.log.pattern}
log4j.appender.console.Threshold=INFO
# global debug to file
log4j.appender.debug=uk.org.simonsite.log4j.appender.TimeAndSizeRollingAppender
log4j.appender.debug.File=/momomo/Generated/Logs/debug.log
log4j.appender.debug.DatePattern=${momomo.log.datepattern}
log4j.appender.debug.MaxFileSize=${momomo.log.maxfilesize}
log4j.appender.debug.Append=true
log4j.appender.debug.layout=org.apache.log4j.PatternLayout
log4j.appender.debug.layout.ConversionPattern=${momomo.log.pattern}
log4j.appender.debug.Threshold=DEBUG
# global error to file
log4j.appender.error=uk.org.simonsite.log4j.appender.TimeAndSizeRollingAppender
log4j.appender.error.File=/momomo/Generated/Logs/error.log
log4j.appender.error.DatePattern=${momomo.log.datepattern}
log4j.appender.error.MaxFileSize=${momomo.log.maxfilesize}
log4j.appender.error.Append=true
log4j.appender.error.layout=org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern=${momomo.log.pattern}
log4j.appender.error.Threshold=ERROR
# This logger just logs for the package momomo.com
log4j.logger.momomo.com=momomo, momomofatal
# momomo debug logger
log4j.appender.momomo=uk.org.simonsite.log4j.appender.TimeAndSizeRollingAppender
log4j.appender.momomo.File=/momomo/Generated/Logs/momomo.log
log4j.appender.momomo.DatePattern=${momomo.log.datepattern}
log4j.appender.momomo.MaxFileSize=${momomo.log.maxfilesize}
log4j.appender.momomo.Append=true
log4j.appender.momomo.layout=org.apache.log4j.PatternLayout
log4j.appender.momomo.layout.ConversionPattern=${momomo.log.pattern}
log4j.appender.momomo.Threshold=DEBUG
# momomo fatal logger
log4j.appender.momomofatal=uk.org.simonsite.log4j.appender.TimeAndSizeRollingAppender
log4j.appender.momomofatal.File=/momomo/Generated/Logs/momomo.fatal.log
log4j.appender.momomofatal.DatePattern=${momomo.log.datepattern}
log4j.appender.momomofatal.MaxFileSize=${momomo.log.maxfilesize}
log4j.appender.momomofatal.Append=true
log4j.appender.momomofatal.layout=org.apache.log4j.PatternLayout
log4j.appender.momomofatal.layout.ConversionPattern=${momomo.log.pattern}
log4j.appender.momomofatal.Threshold=FATAL
Yes, quite many, but there is still many more processes for logging that is declared above.
The server is running really slow now, and that isn't the case when it was just started up. It has gone slower and slower for every hour.
I've developed a new Java(1.4) Stored Procedure in Oracle (10g). I've never done this before, I usually keep Java and the DB separated but this was a requisite. So I developed a Java code that can be deployed in Tomcat as well as a Stored Procedure in Oracle. For this I used the Java Logging API.
I can execute the stored procedure in Oracle, but I can't find the logs. I would like to know what should I do in order to print the logs, it can be to Oracle logs or trc files, or even, if possible, configure it to print the logs to another specific folder.
Does anyone know how to achieve this?
As appointed by PeskyGnat in this answer you have to create a logging.properties file in the folder:
$ORACLE_HOME/javavm/lib
After you configure this file, you can see the logs in:
$ORACLE_BASE/admin/$INSTANCE/udump
In my case, this was Solaris so the first path was:
/export/home/oracle/app/oracle/product/10.2.0/Db_1/javavm/lib
And the second one:
/export/home/oracle/app/oracle/admin/
As extra information, in order to make easy to find the log file you can type in Bash shell the following:
ls -altr
And this is an example of how the logging.properties file:
############################################################
# Default Logging Configuration File
#
# You can use a different file by specifying a filename
# with the java.util.logging.config.file system property.
# For example java -Djava.util.logging.config.file=myfile
############################################################
############################################################
# Global properties
############################################################
# "handlers" specifies a comma separated list of log Handler
# classes. These handlers will be installed during VM startup.
# Note that these classes must be on the system classpath.
# By default we only configure a ConsoleHandler, which will only
# show messages at the INFO and above levels.
handlers= java.util.logging.ConsoleHandler
# To also add the FileHandler, use the following line instead.
#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
# Default global logging level.
# This specifies which kinds of events are logged across
# all loggers. For any given facility this global level
# can be overriden by a facility specific level
# Note that the ConsoleHandler also has a separate level
# setting to limit messages printed to the console.
.level= INFO
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
# default file output is in user's home directory.
java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
# Limit the message that are printed on the console to INFO and above.
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
# For example, set the com.xyz.foo logger to only log SEVERE
# messages:
**<your.class.logger>.level = <level> (i.e.: INFO)**
When my logger is set to "all", i am seeing messages that my code does not explicitly place. I am using a jar a friend of mine gave me to do some things (and i suspect he is logging stuff himself)
I would like to ONLY log stuff I ask to be logged by issuing the
logger.info ("something clever"); command
Below is my log4j.properties
please advise.
# ***** Set root logger level to WARN and its two appenders to stdout and R.
log4j.rootLogger=all, R
# ***** R is set to be a RollingFileAppender.
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=log/something.log
# ***** Max file size is set to 100KB
log4j.appender.R.MaxFileSize=100KB
# ***** Keep one backup file
log4j.appender.R.MaxBackupIndex=1
# ***** R uses PatternLayout.
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
Take a look at this excellent log4j cheatsheet:
http://www.johnmunsch.com/projects/Presentations/docs/Log4J/log.properties
Basically, you need to set something like this:
log4j.rootCategory=error, R
log4j.category.com.your.package=debug
or, alternatively:
log4j.category.com.your.friends.package=error
Replace the package names as necessary.
These would make the root logger set to error (so any package - including other libraries you might be using, like Hibernate, Spring, etc.) will not log anything low-level (debug, info, warn), but log only errors.
It will also set your package (include your top level package or packages) to log on a debug level, so all your loggers will log normally. It will also set your friend's package to error, so it doesn't output anything.
If you have a common root package, just use it. E.g. if you have packages:
com.example
com.example.a
com.example.a.aa
com.example.b
com.example.c.d
just include com.example and it will inherit for the packages below by default.
You could, of course, override it, e.g. specify:
com.example - warn
com.example.a.aa - debug
or something similar. Take a look here for a detailed explanation:
http://logging.apache.org/log4j/1.2/manual.html