Get back to docs

Java

Create a log

Be sure to check out the Get Started section for information on how to register for an account and create your first log. While creating your log choose “Java Log4J” or "Java Logback" option in “Language and framework” select field.

Below you will find integration instructions for Log4j and Logback.



Log4j integration

To integrate Muscula with Log4j add dependency to POM file using this code:

<dependency> <groupId>com.muscula</groupId> <artifactId>muscula-log4j</artifactId> <version>1.0.2</version> </dependency>

Then configure Log4j in file src/main/resources/log4j2.xml.

<?xml version="1.0" encoding="UTF-8"?> <Configuration status="INFO"> <Appenders> <MusculaAppender name="MusculaAppender" logId="LOG_ID"/> </Appenders> <Loggers> <Root level="error"> <AppenderRef ref="MusculaAppender"/> </Root> </Loggers> </Configuration>

Remember to replace LOG_ID with your current LOG ID. If you place code directly from Muscula Application LOG ID will be filled. Click here to see instructions on how to find your LOG ID in Mucula App.

To see a working example of log4j integration of Muscula check out our demo project at https://gitlab.com/muscula-public/muscula-java-log4j-demo.



Logback integration

To integrate Muscula with Logback add dependency to POM file using this code:

<dependency> <groupId>com.muscula</groupId> <artifactId>muscula-logback</artifactId> <version>1.0.2</version> </dependency>

Then configure logback in file src/main/resources/logback.xml.

<configuration> <appender name="muscula" class="com.muscula.logback.appender.MusculaAppender"> <logId>LOG_ID</logId> </appender> <root level="info"> <appender-ref ref="muscula"/> </root> </configuration>

Remember to replace LOG_ID with your current LOG ID. If you place code directly from Muscula Application LOG ID will be filled. Click here to see instructions on how to find your LOG ID in Mucula App.

You can use it like any other logger. Here is an example:

public class Main { private static final Logger logger = LoggerFactory.getLogger(Main.class); public static void main(String[] args) { for(int i=0; i<10; i++) logger.error("test", new RuntimeException("logback error test")); } }

To see a working example of logback integration check out our demo project at https://gitlab.com/muscula-public/muscula-java-logback-demo.

If you can’t find what you're looking for, contact us and we will update the documentation. Thanks, and enjoy Muscula!