Help Docs

Log4j Logs

Log4j is a widely used logging framework in java application. Site24x7 agent automatically detects Log4j logs in your machine and identifies the log fields such as date & time, log level, source file name, line, and message. With default support for Log4j logs one can search, view, collect and analyze the data with the help of our intuitive web client. Site24x7 AppLogs is a one of a kind cloud-based log management service that helps you manage logs with ease. Learn more about log management with Site24x7.

Getting started

  1. Log in to your Site24x7 account.
  2. Download and install the Site24x7 Server Monitoring agent (Windows | Linux). 
  3. Go to Admin > AppLogs > Log Profile and Add Log Profile.

Logs file path

Each application writes logs in different folders and files. Log4j logs will be sourced from the below mentioned folder path for the respective Operating System. If you have logs in a different folder, you can mention it under the File Path to source them from that particular folder while creating a log profile.

Linux icon: /var/log/java/*.log*
Windows icon: C:\\*java*\\logs\\*.log
Note

Log file path given here is for reference ONLY. By default Site24x7 runs a script to find the specific file path.

Log pattern

DateTime:date$ $LogLevel$ $SourceFileName$ $Line:number$ - $Message$

This is the default pattern defined by Site24x7 for parsing Log4J Logs based on the sample log mentioned below.

Sample log

2017-07-02 20:52:39,342 DEBUG className 200 - This is debug message

The above sample log can be separated into 5 fields, each of which will take its respective value from here and will then be uploaded to Site24x7.

 Field name  Field value
Date Time  2017-07-02 20:52:39, 342
Log Level DEBUG
Source File Name   className
Line 200
Message This is debug message

Log4j logs dashboard

AppLogs creates an exclusive dashboard for every Log Type, and shows a few widgets by default. Here's a list of the widgets available in the Log4J logs dashboard:

  • Exceptions
  • Most Log Generato
Note

In addition to the default widgets, your saved searches will also be added to the dashboard automatically.

Log4j appender 

Site24x7 provides a Log4j appender that allows Java applications to send logs directly to the Site24x7 platform without requiring an agent. This approach simplifies the log forwarding process by enabling applications to push logs via an API, bypassing the need to write them to local log files.

This solution is ideal for customers looking for a lightweight, agentless log forwarding method from Java-based applications.

How it works 

Site24x7 provides a custom appender for direct log shipping to support this logging framework In the case of Java, the Log4j2 custom appender is used to enrich, batch, and securely transmit logs to Site24x7 using an API token. Instead of writing logs to a file, the appender streams them to Site24x7's log management service.

Prerequisites

Before configuring the Site24x7 Log4j2 appender, ensure the following dependencies are included in your application:

  1. If you're using Maven, add the following dependency in your pom.xml file:
    <dependency>
      <groupId>com.site24x7</groupId>
      <artifactId>custom-log4j2-appender</artifactId>
      <version>1.3.0</version>
    </dependency>
    
  2. If you're not using Maven, you can manually download and add the required JAR files to your application's class path:

Configuring Log4j appender

  1. Navigate to Admin > AppLogs > Log Types (+).
  2. In the Sample Logs field, you can use the below sample JSON logs to create a new log type:
    {
    "@timestamp":"2025-06-10T18:39:14.017Z",
    "LogLevel":"ERROR",
    "message":"Error #1",
    "logger":"org.zylker.Main",
    "thread":"main",
    "exception":"java.lang.NullPointerException: Generated NullPointerException\n\tat org.example.Main.generateRandomError(Main.java:71)\n\tat org.example.Main.main(Main.java:56)\n",
    "app":"test",
    "hostname":"zylker",
    "env":"local",
    "type":"test-logs"
    }
  3. In the Log Pattern field, you can use the sample log pattern below to extract the relevant fields:
    json $exception$ $@timestamp as timestamp:date:yyyy-MM-dd'T'HH:mm:ss.SSS'Z'$ $logger$ $thread$ $message$ $LogLevel$
  4. Click on the Save and proceed to Log Profile button.
  5. In the Add Log Profile window, fill in the required details.
  6. Next to the Choose the Log Type field, click the pencil icon  Edit icon to edit.
  7. On clicking it, will open the Edit Log Type form
  8. Toggle to Enable the API Upload field.
  9. Click Save to apply the changes.
Note

The API key will be permanently associated only after the log type form is enabled and saved. Until then, the key remains temporary and may change.

  1. Update your log4j2.xml configuration file to use the Site24x7 appender, Here is a sample code:
    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="WARN">
      <Appenders>
        <Site24x7Appender name="Site24x7" site24x7Token="YOUR_API_TOKEN_HERE" 
            logParsingEnabled="false">
        </Site24x7Appender>
      </Appenders>
      <Loggers>
        <Root level="info">
          <AppenderRef ref="Site24x7" />
        </Root>
      </Loggers>
    </Configuration>
    

Parameters

Appender elements

Attribute

Description

Default value

name

Logical name of the appender; referenced in the logger section to attach this appender to log events.

"Site24x7"

site24x7Token

The API token is used to authenticate and send logs to Site24x7. "YOUR_API_TOKEN_HERE " Replace with your actual token.

Nil

batchSize

Number of log events to collect before sending them in a single batch to Site24x7. Helps optimize network usage.

"500"

drainTimeoutSec

Maximum time (in seconds) the appender waits before flushing and sending logs, even if the batch size isn't reached.

"15"

addHostname

Appends the host machine name to each log entry. Useful in distributed environments for identifying the log source.

"true"

logParsingEnabled

Disables automatic log parsing. If set to true , Site24x7 attempts to parse structured log formats (e.g., JSON). Set to false if you're sending plain text logs.

"false"

Loggers elements

Attribute

Description

<Root level="info">

Defines the logging level (INFO in this case) for the root logger. All log events of level INFO and above will be captured.

<AppenderRef ref="Site24x7" />

Attaches the Site24x7 appender (defined above) to the root logger so that it handles log output.

The configuration above allows you to seamlessly forward logs from your Java application to Site24x7 using a custom Log4j2 appender. Once configured and authenticated with a valid API token, your application logs will be efficiently streamed to Site24x7 for monitoring and analysis—without the need for additional agents or manual exports.

Was this document helpful?

Would you like to help us improve our documents? Tell us what you think we could do better.


We're sorry to hear that you're not satisfied with the document. We'd love to learn what we could do to improve the experience.


Thanks for taking the time to share your feedback. We'll use your feedback to improve our online help resources.

Shortlink has been copied!