I want to write logging-messages to a defined file into the tomcat's log-folder, using eclipse, maven, tinylog.
Problem: There is no webapp.log as soon as I run the app in tomcat.
In eclipse everything works fine.
What I did:
add Maven-dependency tinylog-1.2.jar
set configuration-parameter in Run Configuration (Main-Tab) so the tinylog-properties can be found for the build-process:
name: -Dtinylog.configuration
value: C:\Program
Files\Tomcat\apache-tomcat-9.0.0.M13\webapps\folder\subfolder\tinylog.properties
in Java-Class:
import org.pmw.tinylog.Logger;
...
Logger.info(message);
tinylog.properties looks like:
tinylog.writer = file
tinylog.writer.filename = webapp.log
tinylog.writer.buffered = true
tinylog.writer.append = true
tinylog.level = info
I also tried different file-references but none of them worked:
tinylog.writer.file = C:\Program Files\Tomcat\apache-tomcat-9.0.0.M13\logs\webapp.log
tinylog.writer.file= "C:\Program Files\Tomcat\apache-tomcat-9.0.0.M13\logs\webapp.log"
Does anybody know how to write the logs into the named path-file?
Thanks for any valuable hint.
I propose to use the tinylog-jul artifact instead of the usual tinylog artifact. tinylog-jul provides the tinylog API, but uses the Tomcat logging back end. So, you don't need to configure tinylog. All log entries will be automatically output as you are used to with other logging APIs on Tomcat.
Related
I'm trying to do some Logging modification on My Standard AppEngine Java 11 app using a logging.properties file, My app is a Jetty web-server which I run by adding the following entry-point to my app.yaml file
runtime: java11
entrypoint: 'java -cp "*" com.jettymain.Main webapp.war'
Now Google documentation here suggests that in order to use logging.properties. The path to the configuration file must be provided to your application as a system property: -Djava.util.logging.config.file=/path/to/logging.properties
I have tried setting that in the code, first thing in the com.jettymain.Main class which starts the Jetty embedded web-server by doing the following
System.setProperty("java.util.logging.config.file", "WEB-INF/logging.properties")
But that didn't work, modifying the entry-point in app.yaml did make the web-server load those configurations but it was failing to load the Google cloud logging handler class com.google.cloud.logging.LoggingHandler, which I need to write those logs to Google Stackdriver, I have the Google cloud logging dependency added to both my app and the web-server but that didn't help.
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging</artifactId>
<version>3.0.1</version>
</dependency>
modified entry-pint
runtime: java11
entrypoint: 'java -cp "*" com.jettymain.Main webapp.war -Djava.util.logging.config.file=WEB-INF/logging.properties'
logging.properties file, it is the sample file which can be found here plus few extra things
# To use this configuration, add to system properties : -Djava.util.logging.config.file="/path/to/file"
.level = INFO
# it is recommended that io.grpc and sun.net logging level is kept at INFO level,
# as both these packages are used by Cloud internals and can result in verbose / initialization problems.
io.grpc.netty.level=INFO
sun.net.level=INFO
handlers=com.google.cloud.logging.LoggingHandler
# default : java.log
com.google.cloud.logging.LoggingHandler.log=custom_log
# default : INFO
com.google.cloud.logging.LoggingHandler.level=FINE
# default : ERROR
com.google.cloud.logging.LoggingHandler.flushLevel=EMERGENCY
# default : auto-detected, fallback "global"
com.google.cloud.logging.LoggingHandler.resourceType=container
# custom formatter
com.google.cloud.logging.LoggingHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%3$s: %5$s%6$s
# Level for all logs coming from GWT client (can't filter by specific classes on client)
com.google.gwt.logging.server.RemoteLoggingServiceUtil.level = WARNING
com.beoui.geocell.level=WARNING
It might be an old question, but this answer still might help to someone having same issue.
I've managed to add custom logging.properties using Gradle for Java 11 Standard Environment:
First of all, you have to add dependency to the Cloud logging as it's no longer provided by the environment:
dependencies {
runtimeOnly("com.google.cloud:google-cloud-logging:3.11.3")
// your other dependencies
}
Then you need to specify a folder containing your logging.properties file to be uploaded by Gradle com.google.cloud.tools.appengine plugin:
configure<AppEngineAppYamlExtension> {
stage {
setArtifact("build/libs/server.jar")
// can be some other folder of your choice where logging.properties is located
setExtraFilesDirectories("src/main/resources")
}
deploy {
version = "GCLOUD_CONFIG"
projectId = "GCLOUD_CONFIG"
}
}
Then specify an entrypoint in app.yaml. The trick here is that properties file can be found in /workspace/ directory of the GAE container:
runtime: java11
entrypoint: 'java -jar -Djava.util.logging.config.file=/workspace/logging.properties server.jar'
Deploy application using
./gradlew appengineDeploy
My logging.properties file:
.level = INFO
# it is recommended that io.grpc and sun.net logging level is kept at INFO level,
# as both these packages are used by Cloud internals and can result in verbose / initialization problems.
io.grpc.netty.level=INFO
sun.net.level=INFO
handlers=com.google.cloud.logging.LoggingHandler
com.google.cloud.logging.LoggingHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%3$s: %5$s%6$s
Get the System.setProperty into any method. It can be the main method also. I think the problem is "the logging.properties must go in WEB-INF/classes directory" as per this link and not WEB-INF/ directory as mentioned in your code.
System.setProperty("java.util.logging.config.file", "WEB-INF/classes/logging.properties")
I'm running my Spring Boot application with Kubernetes. Part of the architecture involves mounting secrets as file volumes under /opt/config.
$ ls -l
SECRET_1
SECRET_2
SECRET_3
Each file contains a .properties like syntax. (key=value)
I've been attemtping to make Spring Boot load these as per the documentation spring.config.import=file:/etc/config/myconfig[.yaml]
However I just can't get this to work, my full command is: java -Dspring.config.location=file:./opt/application.properties -Dspring.config.additional-location=file:./opt/config/*[.properties] -jar target/test.war --debug --server.port=8080
The ./opt/application.properties file is loaded correctly.
I have also attempted to rename all the files to include .properties:
$ ls -l
SECRET_1.properties
SECRET_2.properties
SECRET_3.properties
And load it via java -Dspring.config.location=file:./opt/application.properties -Dspring.config.import=file:./opt/config/*/ -jar target/test.war --debug --server.port=8080, however this also did not import any of the properties under ./opt/config.
I've read through the documentation dozens of times now, and this should be working, but it's not. Did I miss something obvious? Why is it not loading any of the files under ./opt/config?
I think the problem is that the locations you specify are where spring looks for application.properties, application.yml and profile variants (application-prod.properties, etc). I think you are better off loading all the files in a configured location programmatically, this might provide some ideas.
I'm new to Tomcat, Fuseki and the Shiro.ini file, so forgive me for asking silly questions.
System:
MacMini ==> OS.X 10.13 (acts as dev-server)
Java ==> 8
Tomcat ==> 9.0.10
Workflow:
Via a Plist file, the Tomcat instance gets started on each boot of the server.
in /Users/username/tomcat/webapps I've put the fuseki.war file which got extracted successfully.
I inserted a custom made RDF-file, which gets loaded after reboots and served
(this is where the good things end)
Problem:
I can access the RDF file through: http://localhost:8080/fuseki, I can perform SPARQL-queries and everything else I need to get done. However, when connecting the dev-server to a PC and accessing it through it's IP: e.g.http://192.168.0.112:8080/fuseki; I end up seeing the server which has a green status, and the entire web-interface works except for the datasets. When I go to http://192.168.0.112:8080/fuseki/dataset and press 'query' (or any other button) it displays: "Please select a database"
**Cause:
I found this thread fuseki webinterface does not show datasets (SO), which lead me to investigate the shiro.ini file. As it turns out I don't have one.
I then searched for shiro.ini and found a reference in /Users/username/tomcat/webapps/fuseki/WEB-INF/web.xml:
<context-param>
<param-name>shiroConfigLocations</param-name>
<!-- Try a path in: FUSEKI_BASE, FUSEKI_HOME, war resource
If a "file:" then look there and there only.
-->
<param-value>shiro.ini</param-value>
</context-param>
This made me think that I'd need to put the shiro.ini file in my root folder (Users/username/tomcat/webapps/fuseki/shiro.ini) and not in (Users/username/tomcat/webapps/fuseki/run/shiro.ini). However neither work.
I also looked in a logfile: catalina.out, based from that it seems that the shiro.ini file gets loaded (or at least there are no indiciations that there's an error with it.)
Here's the relevant extract from that log:
[2018-07-31 09:18:54] Config INFO FUSEKI_HOME=unset
[2018-07-31 09:18:54] Config INFO FUSEKI_BASE=/etc/fuseki
[2018-07-31 09:18:54] Config INFO Shiro file: file:///etc/fuseki/shiro.ini
[2018-07-31 09:18:55] Config INFO Context path = /fuseki
[2018-07-31 09:18:55] Config INFO Configuration file: /etc/fuseki/config.ttl
I can't find however any folder etc/fuseki/? So what's up with this to start with?
Here is the shiro.ini file:
[users]
admin=passXXX #non-default
[main]
#localhost=org.apache.jena.fuseki.authz.LocalhostFilter
[roles]
[urls]
##control open to anyone
/$/status = anon
/$/ping = anon
##rest restricted to Localhost
## see above for localhost
#/$/** = localhost
/**=anon
I'm not sure what's going on at this point, so any pointers are more than welcome.
Turns out the issue had more to do with my unfamiliarity with the MAC OS, than with Tomcat or Fuseki.
The folder /etc/fuseki which was referenced in the catalina.out file is tightly locked and it's actual path is /private/etc/fuseki (though this doesn't seem to matter)
By default you can't enter the fuseki folder due to no rights at all. Even doing:
sudo cd /private/etc/fuseki
or
sudo cd /etc/fuseki
won't work. I needed to give myself read/write access to the folder via getinfo (though I think you could achieve this as well via chown.
Now I could view that folder's content, yet all files and folders in there had the same issue and required the same solution. So now I could customize the shiro.ini and configuration/rdf.ttl file.
If I do
sudo cd /private/etc/fuseki
or
sudo cd /etc/fuseki
now, then I can successfully view the content.
I am trying to log all my slow queries in a separate file. Until now I have to following Tomcat context configuration:
<Resource name="jdbc/paymentDB" auth="Container" type="org.apache.tomcat.jdbc.pool.DataSource"
driverClassName="...oracle..."
...
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.QueryTimeoutInterceptor(queryTimeout=2);org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport(threshold=1000,maxQueries=200)"
</Context>
This works as long as I do not set another kind logger and it prints to the console. One thing that I believe should be added is that I run this test in IntelliJ Idea using default IDE configuration.
The next thing I wanted to do was to log into a separate file. So I opened logging.properties and did the following changes:
handlers = ..., 5slowqueries.org.apache.juli.FileHandler, ...
.handlers =..., 5slowqueries.org.apache.juli.FileHandler, ...
5slowqueries.org.apache.juli.FileHandler.level = ALL
5slowqueries.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
5slowqueries.org.apache.juli.FileHandler.prefix = slow-queries.
org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport.level = ALL
org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport.handlers = 5slowqueries.org.apache.juli.FileHandler
The problem is that executing the same slow queries and have been printed earlier in console, this time, using this configuration, no slow-queries.* file is created. (I ran this from IntelliJ Idea)
I can't figure out how to make this work. Maybe it has something to do with IDE? I have noticed that IDEA has a Logs category in Run/Debug Configurations, I tried to play with these options too but didn't have any luck.
I found the problem. It was the IDE. When IDEA starts the server it prints something like this in the console:
Using CATALINA_BASE: "C:\Users\..."
Using CATALINA_HOME: "C:\..."
another few variables
The logs are created, by default, if not changed, in CATALINA_BASE/logs.
I will like to setup performance monitoring on an application running on Railo 4 using New Relic. I have consulted the java docs on Railo, Railo google groups, etc but no one seems to have a perfect step by step.
Here is what I have done so far:
Extracted newrelic into Railo's install folder.
Added this line to setenv.sh
export JAVA_OPTS="$JAVA_OPTS -javaagent:c/railo/newrelic/newrelic.jar"
Restarted the Railo-Tomcat service
Added this line to the onapplicationstart function
application.NewRelic = createObject( "java", "com.newrelic.api.agent.NewRelic" );
Added this line to the onrequeststart function
if ( structKeyExists( application, "NewRelic" ) ) {
application.NewRelic.setTransactionName( "CFML", CGI.SCRIPT_NAME );
}
My application is still not sending metrics to New Relic. I will appreciate a step by step instruction of what to do as I can't seem to find that anywhere else and I have no idea what to do.
You can't use setenv.sh on Windows. Instead modify the catalina.bat file, or use the Configure Tomcat utility in the Start Menu to set the javaagent option. These steps can be found in more detail in the New Relic documentation
We have more detailed instructions for installing with our supported platforms and frameworks in our documentation. To see a list of the supported frameworks we are compatible with check out https://docs.newrelic.com/docs/java/new-relic-for-java#h2-compatibility
We may be able to work with the Tomcat portion of your environment and you can find helpful installation information at https://docs.newrelic.com/docs/java/java-agent-manual-installation
Should you run into any obstacles, I suggest opening a ticket at http://support.newrelic.com