Google's Closure Compiler has this flag for logging:
--logging_level VAL
The logging level (standard java.util.logging.Level values)
for Compiler progress. Does not control errors or warnings
for the JavaScript code under compilation.
So I can set the logging level to one of: SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST.
But how do I enable logging, and where is the log file?
Create a file called logging.properties with the following contents:
handlers = java.util.logging.FileHandler
java.util.logging.FileHandler.pattern = closure-compiler.log
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
Then set the java.util.logging.config.file Java system property to logging.properties when running the application:
java -Djava.util.logging.config.file=logging.properties \
-jar compiler.jar \
--js script.js \
--logging_level FINEST
The log will be written to closure-compiler.log.
Related
We're trying to debug the behaviour of svnkit during checkout on Linux (Debian) that is related to a JDK/JVM bug described here
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8172578
https://bugs.openjdk.java.net/browse/JDK-8075484
We followed the steps described here
https://wiki.svnkit.com/Troubleshooting
by renaming the file conf/logging.properties.disabled to logging.properties and by also replacing the /usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/logging.properties (which symlinks to /etc/java-8-openjdk/logging.properties)
This produces a log file under Windows (in the bin folder of the svnkit standalone), but has no effect under Linux.
Calling
./jsvn checkout --username XYZ --password ABC http://SVN_SERVER/svn/project/trunk/
makes ps aux tell us
/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java -Djava.util.logging.config.file=/tmp/svnkit-1.8.15/conf/logging.properties -Dsun.io.useCanonCaches=false -classpath /tmp/svnkit-1.8.15/lib/svnkit-1.8.15.jar:/tmp/svnkit-1.8.15/lib/sequence-library-1.0.3.jar:/tmp/svnkit-1.8.15/lib/sqljet-1.1.10.jar:/tmp/svnkit-1.8.15/lib/jna-4.1.0.jar:/tmp/svnkit-1.8.15/lib/jna-platform-4.1.0.jar:/tmp/svnkit-1.8.15/lib/trilead-ssh2-1.0.0-build221.jar:/tmp/svnkit-1.8.15/lib/jsch.agentproxy.connector-factory-0.0.7.jar:/tmp/svnkit-1.8.15/lib/jsch.agentproxy.svnkit-trilead-ssh2-0.0.7.jar:/tmp/svnkit-1.8.15/lib/antlr-runtime-3.4.jar:/tmp/svnkit-1.8.15/lib/jsch.agentproxy.core-0.0.7.jar:/tmp/svnkit-1.8.15/lib/jsch.agentproxy.usocket-jna-0.0.7.jar:/tmp/svnkit-1.8.15/lib/jsch.agentproxy.usocket-nc-0.0.7.jar:/tmp/svnkit-1.8.15/lib/jsch.agentproxy.sshagent-0.0.7.jar:/tmp/svnkit-1.8.15/lib/jsch.agentproxy.pageant-0.0.7.jar:/tmp/svnkit-1.8.15/lib/svnkit-cli-1.8.15.jar org.tmatesoft.svn.cli.SVN checkout --username XYZ --password ABC http://SVN_SERVER/svn/project/trunk/
where
-Djava.util.logging.config.file=/tmp/svnkit-1.8.15/conf/logging.properties
is the part that tells us the renamed logging.properties file is being used to configure the logging.
The content of the logging.properties is
svnkit.level=FINEST
svnkit-network.level=FINEST
svnkit-wc.level=FINEST
svnkit-cli.level=FINEST
handlers = java.util.logging.FileHandler
java.util.logging.FileHandler.pattern = svnkit.%u.log
java.util.logging.FileHandler.limit = 0
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.append = true
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
Any ideas what we are doing wrong?
I currently have multiple web applications deployed in Tomcat which is running as a Windows service. I created/modified most of the logging.properties files to (hopefully) create a separate log file for each web application.
My conf\logging.properties looks like:
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
1catalina.org.apache.juli.AsyncFileHandler.level = FINE 1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
2localhost.org.apache.juli.AsyncFileHandler.level = FINE 2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
3manager.org.apache.juli.AsyncFileHandler.level = FINE 3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs 3manager.org.apache.juli.AsyncFileHandler.prefix
= manager.
java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers
= 2localhost.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level
= INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers
= 3manager.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level
= INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers
= 4host-manager.org.apache.juli.AsyncFileHandler
# For example, set the org.apache.catalina.util.LifecycleBase logger to log
# each component that extends LifecycleBase changing state:
#org.apache.catalina.util.LifecycleBase.level = FINE
# To see debug messages in TldLocationsCache, uncomment the following line:
#org.apache.jasper.compiler.TldLocationsCache.level = FINE
# To see debug messages for HTTP/2 handling, uncomment the following line:
#org.apache.coyote.http2.level = FINE
# To see debug messages for WebSocket handling, uncomment the following line:
#org.apache.tomcat.websocket.level = FINE
Each of my web apps has the following logging.properties file int he WEB-INF\classes folder:
handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
org.apache.juli.FileHandler.level = FINE
org.apache.juli.FileHandler.directory = ${catalina.base}/logs
org.apache.juli.FileHandler.prefix = prefix.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
I am currently logging everything within my web applications on the INFO level like so:
Logger.getLogger("LOG").log(Level.INFO, "Stuff to log");
Things seem to be relatively close to how I was hoping. Stdout seems to be correctly going to the individual web application logs, but EVERYTHING also seems to be going to the tomcat8-stderr log as well.
I tried commenting out the ConsoleHandler from ALL config.properties, but I was still getting the same behavior. How do I prevent everything from also being logged in the stderr log?
I added this to my Context.xml, but that did not seem to change anything:
<Context swallowOutput="true">
I was able to fix this by setting the Level of my web application loggers to FINE and changing the web application ConsoleHandler level in logging.properties to INFO.
As documented in Official Tomcat site, the private package-renamed implementation of Apache Commons Logging namely JULI does have exceptions. the .handlers directive is defining the ROOT logger which in turn is the only possible output for calls that are coming directly from ClassLoader of common jars such as the StandardEngine ones or the java.sql driver ones. Unless a specific handler is assigned by class name after which a method call like java.util.logging.Logger.getLogger() could get potentially get a grip.
To use the so called "Facility specific properties" tomcat-juli features of per Engine, per Host and per Context log, the logging.properties in effect is the global tomcat logging configuration initially loaded at Engine startup :
The calls to javax.servlet.ServletContext.log(...) to write log
messages are handled by internal Tomcat logging. Such messages are
logged to the category named
org.apache.catalina.core.ContainerBase.[${engine}].[${host}].[${context}]
This logging is performed according to the Tomcat logging
configuration. You cannot overwrite it in a web application.
However,
JULI [...] supports per classloader configuration, in addition to the regular global java.util.logging configuration. This means that logging can be configured at the following layers:
Globally. That is usually done in the ${catalina.base}/conf/logging.properties file. The file is specified by the java.util.logging.config.file System property which is set by the startup scripts. If it is not readable or is not configured, the default is to use the ${java.home}/lib/logging.properties file in the JRE.
In the web application. The file will be WEB-INF/classes/logging.properties
So after making some various tests, I realized that I was not able to reproduce your issue, as I successfully logged from an application exclusively and entirely to the prefix.yyyy-mm-dd.log file defined in the per application WEB-INF/classes/logging.properties.
I say "entirely" taking into consideration that if the web application uses System.out.print(), the printed stuff will only show up in the "prefix."-files if swallowOutput is set to true in the context.xml (whether it be from the application's META-INF/context.xml or from the ${CATALINA_BASE}/conf/context.xml file.
Tweaking the logging levels to avoid the situation you where is not to my opinion an elegant bypass and I hope you have not settled down to that and will share your final resolution unless the problem vanished since !
In a spring-boot application I can specify a custom log file with
java -jar spring-boot-app.jar --logging.file=/home/ubuntu/spring-boot-app.log
But if I don't specify one, where does it go?
I couldn't find it in any of the following folders:
/tmp/
/var/log/
~/
I do not have spring-boot-starter-logging or any additional logging dependencies.
I was hoping to have something similar to catalina.out since the default configuration runs an embedded Tomcat:
INFO 10374 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8100 (http)
Spring Boot uses Commons Logging for all internal logging, but leaves the underlying log implementation open.
Default configurations are provided for Java Util Logging, Log4J, Log4J2 and Logback. In each case loggers are pre-configured to use console output with optional file output also available.
From the Spring Boot logging documentation.
The default log configuration will echo messages to the console as they are written.
So until you explicitly specify a file as you described, it stays in the Console.
By default Spring Boot does not output logs to any file. If you want to have logs written in a file (in addition to the console output) then you should use either of logging.file or logging.path properties (not both).
In application.properties, just set:
logging.file=/home/ubuntu/spring-boot-app.log
This will create a spring-boot-app.log file under /home/ubuntu.
By default, Spring Boot logs only to the console and does not write log files. If you want to write log files in addition to the console output, you need to set a logging.file or logging.path property (for example, in your application.properties).
Below codes in your application.properties will write the log into /home/user/my.log:
logging.path = /home/user
logging.file = my.log
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