I know atlassian stash uses logback, not log4j. Using the plugin SDK with jira or other atlassian products, you can do this in your POM:
<log4jProperties>${basedir}/log4j.properties</log4jProperties>
What is the equivalent for stash? How can I control logger levels for my debug instance without having to manually copy files around? How can I bundle logging inside my plugin? (e.g. write a special log to a special file appender?) There are no examples I can find in the atlassian docs.
Community moderators have prevented the ability to post new answers.
I now have a working example of configuring logback in a plugin which utilizes a logback.xml on your classpath. See:
For a code example of how to configure loggers. For an example logback.xml, see:
https://github.com/palantir/stashbot/blob/master/src/main/resources/logback.xml
Thanks!
-Carl
Thanks again to Charles O'Farrell who guided me to correct solution, here I will outline if someone else wants to do that:
You will find the logs under ${PLUGIN_FOLDER}/target/container/tomcat7x/cargo-stash-home/YOUR.log
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Anyone else try this? I tried to follow along but every time I upgrade my plugin I get an additional line in the log. I mean if I install it it logs one line to the file if I then upgrade, it logs two identical lines to the file, upgrade again, three etc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Carl,
There are two options for modifying the logback config:
- Add a logback.xml file to the <stash home> directory, this will be merged with Stash's logback config, however this is not portable; the file will need to added once for every Stash server.
- Configure logback in your plugin Java code. You can use the ApplicationPropertiesService to get the home directory to ensure you are logging in the correct place.
Hope that helps,
Tom.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, this is helpful, but I am still having problems. I don't quite understand what my logging commands should look like, or how I should configure the logging system. I tried to do something like what I found here:
http://stackoverflow.com/questions/7967165/how-to-configure-logback-with-java-code-to-set-log-level
but I still am not seeing log messages. Do you maybe have a code example? What should it look like when my code gets a logger? How do I tell a particular logger to output to the atlassian-stash.log (or console when I run atlas-debug)? Should I use the same logger all across my plugin, or can I have a separate logger for each class? Should I add a dependency on logback to my pom.xml and use it directly? The link above tries to avoid that using reflection and it is a royal pain...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Carl,
I'm curious about exactly what you're trying to do? If you're just trying to set the levels of a logger then you can easily specify the levels in our stash-config.properties file, or at runtime using REST:
https://confluence.atlassian.com/display/STASH/Stash+debug+logging
What are you hoping to use custom appenders for? If you want to define your own customer appenders, as Thomas says you can put an extra logback.xml in the home directory:
<included>
<appender name="myappender"> .... </appender> <!-- I'm assuming you want to output a specific package --> <logger name="my.org.something" level="DEBUG"> <appender-ref ref="myappender" /> </logger>
</included>
http://logback.qos.ch/manual/configuration.html
Cheers,
Charles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Charles,
My goal was to have the plugin log by default, without having to touch stash's configuration at all. I wanted it to be zero-touch, install-the-plugin-and-it-just-works. See my accepted answer for how I ended up doing it.
Thanks!
-Carl
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have trying to create a separate log for my plugin, I looked at your code and replicated these steps, let me know if I missed anything:
Did I miss anything ?
The plugin can be executed but I dont see any log file getting generated through this setup.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Despite Thomas' very helpful answer, I am still having problems figuring out how to configure logback. A working example plugin that uses logback to do logging would be great... failing that, maybe some code samples of what I need to do. I've googled and tried to find logback code examples but that code doesn't seem to be working for me...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.