logback-logsense

A simple Logback appender for LogSense output

License

License

Categories

Categories

Logback Application Layer Libs Logging
GroupId

GroupId

com.logsense
ArtifactId

ArtifactId

logback-logsense
Last Version

Last Version

1.1.6
Release Date

Release Date

Type

Type

jar
Description

Description

logback-logsense
A simple Logback appender for LogSense output
Project URL

Project URL

http://logsense.com
Source Code Management

Source Code Management

http://github.com/collectivesense/logback-logsense/tree/master

Download logback-logsense

How to add to project

<!-- https://jarcasting.com/artifacts/com.logsense/logback-logsense/ -->
<dependency>
    <groupId>com.logsense</groupId>
    <artifactId>logback-logsense</artifactId>
    <version>1.1.6</version>
</dependency>
// https://jarcasting.com/artifacts/com.logsense/logback-logsense/
implementation 'com.logsense:logback-logsense:1.1.6'
// https://jarcasting.com/artifacts/com.logsense/logback-logsense/
implementation ("com.logsense:logback-logsense:1.1.6")
'com.logsense:logback-logsense:jar:1.1.6'
<dependency org="com.logsense" name="logback-logsense" rev="1.1.6">
  <artifact name="logback-logsense" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.logsense', module='logback-logsense', version='1.1.6')
)
libraryDependencies += "com.logsense" % "logback-logsense" % "1.1.6"
[com.logsense/logback-logsense "1.1.6"]

Dependencies

compile (4)

Group / Artifact Type Version
com.sndyuk : logback-more-appenders jar 1.5.5
org.komamitsu : fluency-core jar 2.2.1
org.komamitsu : fluency-fluentd jar 2.2.1
ch.qos.logback : logback-classic jar 1.2.3

provided (2)

Group / Artifact Type Version
com.logsense » logsense-opentracing jar 1.1.7
io.opentracing : opentracing-util jar 0.32.0

Project Modules

There are no modules declared in this project.

Logback appender for LogSense

The project includes a simple Logback appender that pushes data to LogSense using logback-more-appenders and Fluency underneath.

Setup

Using logback.xml

Step 1 - Add LogSense-Logback to your dependencies

In case you are using Maven, this typically means a dependency like:

<dependency>
 <groupId>com.logsense</groupId>
 <artifactId>logback-logsense</artifactId>
 <version>1.1.5</version>
</dependency>

Using log4j instead of logback

If your project is already using log4j, a migration dependency can be simply added:


<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>log4j-over-slf4j</artifactId>
	<version>1.7.25</version>
</dependency>

Step 2 - Setup Logback appender

Create src/resources/logback.xml in your project and put following data:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>

    <!-- LogSense appender. Use the correct accessToken value, as provided by the LogSense app -->
    <appender name="LOGSENSE" class="com.logsense.logback.Appender" >
        <logsenseToken>YOUR_LOGSENSE_TOKEN</logsenseToken>
        <!--<remoteHost>logs.logsense.com</remoteHost>-->
        <!--<useLocalIpAddress>true</useLocalIpAddress>-->
        <!--<sourceIp>10.12.1.1</sourceIp>-->
        <!--<patternKey>message</patternKey>-->
        <!--<sourceName>some name</sourceName>-->
    </appender>

   <!-- This is just a standard STDOUT appender - keep it (and others) if you intend to use those -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern><![CDATA[%date{HH:mm:ss.SSS} [%thread] %-5level %logger{15}#%line %X{req.requestURI} %msg\n]]></pattern>
        </encoder>
    </appender>

    <root>
        <level value="DEBUG" />
        <appender-ref ref="STDOUT" />
        <appender-ref ref="LOGSENSE" />
    </root>

</configuration>

There are several optional settings:

  • useLocalIpAddress - when set to true, the local IP address is determined and sent as the log source IP
  • sourceIp - any address can be put here which will override any other method of determining the log source IP
  • patternKey - set to message by default; the provided key of structured log is used for LogSense automatic pattern recognition
  • sourceName - not set by default; if provided, adds "source_name" field with the entered value

Alternative methods of providing the token

The token could be also provided using environment variable, e.g.:

$ LOGSENSE_TOKEN=aaa-111-bbb-222 java ....

or via property, e.g.

$ java -Dlogsense.token=aaa-111-bbb-222 ...
com.logsense

Versions

Version
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0