|
1 | 1 | <a href="https://opensource.newrelic.com/oss-category/#new-relic-experimental"><picture><source media="(prefers-color-scheme: dark)" srcset="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/dark/Experimental.png"><source media="(prefers-color-scheme: light)" srcset="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/Experimental.png"><img alt="New Relic Open Source experimental project banner." src="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/Experimental.png"></picture></a> |
2 | 2 |
|
3 | 3 |
|
4 | | - |
5 | | - |
6 | | - |
| 4 | + |
| 5 | + |
| 6 | + |
7 | 7 |
|
8 | | - |
9 | | - |
10 | | - |
11 | | - |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
12 | 12 |
|
13 | 13 |
|
14 | | - |
15 | | - |
16 | | - |
17 | | - |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
18 | 18 |
|
| 19 | +# New Relic Log4j2 Appender |
19 | 20 |
|
20 | | -# [Project Name - use format "newrelic-java-<name>"] [build badges go here when available] |
| 21 | +A custom Log4j2 appender that sends logs to New Relic. |
21 | 22 |
|
22 | | ->[Brief description - what is the project and value does it provide? How often should users expect to get releases? How is versioning set up? Where does this project want to go?] |
| 23 | +## Installation |
23 | 24 |
|
24 | | -## Value |
| 25 | +Add the library to your project using Maven Central: |
25 | 26 |
|
26 | | -|Metrics | Events | Logs | Traces | Visualization | Automation | |
27 | | -|:-:|:-:|:-:|:-:|:-:|:-:| |
28 | | -|:x:|:x:|:x:|:white_check_mark:|:x:|:x:| |
| 27 | +```xml |
| 28 | +<dependency> |
| 29 | + <groupId>io.github.newrelic-experimental</groupId> |
| 30 | + <artifactId>custom-log4j2-appender</artifactId> |
| 31 | + <version>0.0.8</version> |
| 32 | +</dependency> |
| 33 | +``` |
29 | 34 |
|
30 | | -### List of Metrics,Events,Logs,Traces |
31 | | -|Name | Type | Description | |
32 | | -|:-:|:-:|:-:| |
33 | | -|*metric.name* | Metric| *description*| |
34 | | -|*event.name* | Event| *description*| |
35 | | -|*log.name* | Log| *description*| |
36 | | -|*trace.name*| Trace| *description* |
37 | | -|---|---|---| |
| 35 | +Or, if using a locally built JAR file: |
38 | 36 |
|
| 37 | +```xml |
| 38 | +<dependency> |
| 39 | + <groupId>io.github.newrelic-experimental</groupId> |
| 40 | + <artifactId>custom-log4j2-appender</artifactId> |
| 41 | + <version>0.0.8</version> |
| 42 | + <scope>system</scope> |
| 43 | + <systemPath>${project.basedir}/src/main/resources/custom-log4j2-appender.jar</systemPath> |
| 44 | +</dependency> |
| 45 | +``` |
39 | 46 |
|
40 | | -## Installation |
| 47 | +## Usage |
41 | 48 |
|
42 | | -> [Include a step-by-step procedure on how to get your code installed. Be sure to include any third-party dependencies that need to be installed separately] |
| 49 | +### Set up New Relic Log4j2 Appender |
43 | 50 |
|
44 | | -## Getting Started |
| 51 | +Follow the instructions for setting up the New Relic Log4j2 Appender. |
45 | 52 |
|
46 | | ->[Simple steps to start working with the software similar to a "Hello World"] |
| 53 | +### Log4J XML Configuration |
47 | 54 |
|
48 | | -## Usage |
| 55 | +Replace `[your-api-key]` with the ingest key obtained from the New Relic platform. |
| 56 | + |
| 57 | +#### log4j2.xml: |
| 58 | + |
| 59 | +```xml |
| 60 | +<?xml version="1.0" encoding="UTF-8"?> |
| 61 | +<Configuration status="DEBUG" name="cloudhub" packages="com.newrelic.labs"> |
| 62 | + <Appenders> |
| 63 | + <!-- Custom New Relic Batching Appender with Pattern Layout --> |
| 64 | + <NewRelicBatchingAppender name="NewRelicAppender" |
| 65 | + apiKey="[your-api-key]" |
| 66 | + apiUrl="https://log-api.newrelic.com/log/v1" |
| 67 | + logType="muleLog" |
| 68 | + applicationName="your-application-name" |
| 69 | + batchSize="5000" |
| 70 | + maxMessageSize="1048576" |
| 71 | + flushInterval="120000"> |
| 72 | + <PatternLayout pattern="[%d{MM-dd HH:mm:ss}] %-5p %c{1} [%t]: %m%n"/> |
| 73 | + </NewRelicBatchingAppender> |
| 74 | + </Appenders> |
| 75 | + |
| 76 | + <Loggers> |
| 77 | + <AsyncRoot level="INFO"> |
| 78 | + <AppenderRef ref="NewRelicAppender"/> |
| 79 | + </AsyncRoot> |
| 80 | + </Loggers> |
| 81 | +</Configuration> |
| 82 | +``` |
| 83 | + |
| 84 | +### Parameters |
| 85 | + |
| 86 | +| Parameter | Required? | Default Value | Description | |
| 87 | +|---------------------|-----------|---------------|-----------------------------------------------------------------------------| |
| 88 | +| name | Yes | | Name used to register Log4j Appender | |
| 89 | +| apiKey | Yes | | API key for authenticating with New Relic's logging service | |
| 90 | +| apiUrl | Yes | | URL for New Relic's log ingestion API | |
| 91 | +| logType | No | "muleLog" | Type of log being sent | |
| 92 | +| applicationName | Yes | | Name of the application generating the logs | |
| 93 | +| batchSize | No | 5000 | Maximum number of log entries to batch together before sending to New Relic | |
| 94 | +| maxMessageSize | No | 1048576 | Maximum size (in bytes) of the payload to be sent in a single HTTP request | |
| 95 | +| flushInterval | No | 120000 | Interval (in milliseconds) at which the log entries are flushed to New Relic| |
| 96 | + |
| 97 | +### TLS 1.2 Requirement |
49 | 98 |
|
50 | | ->[**Optional** - Include more thorough instructions on how to use the software. This section might not be needed if the Getting Started section is enough. Remove this section if it's not needed.] |
| 99 | +New Relic only accepts connections from clients using TLS version 1.2 or greater. Ensure that your execution environment is configured to use TLS 1.2 or greater. |
| 100 | + |
| 101 | +### Create GROK Parsing Rule at New Relic Platform |
| 102 | + |
| 103 | +- **Name**: `NRMuleParser` |
| 104 | +- **Field to parse**: `message` |
| 105 | +- **Filter logs based on NRQL**: `logtype = 'muleLog'` |
| 106 | +- **Parsing rule**: |
| 107 | + ```sh |
| 108 | + %{LOGLEVEL:log.level} %{DATA:log.logger} \[%{DATA:log.thread}\]: %{GREEDYDATA:log.message} |
| 109 | + ``` |
| 110 | + |
| 111 | +## Sample log details at New Relic Platform |
| 112 | + |
| 113 | +<img width="745" alt="image" src="https://github.com/user-attachments/assets/6adff21d-7fdf-4b39-b19e-0ed385ff6ed5"> |
51 | 114 |
|
52 | 115 | ## Building |
53 | 116 |
|
54 | | ->[**Optional** - Include this section if users will need to follow specific instructions to build the software from source. Be sure to include any third party build dependencies that need to be installed separately. Remove this section if it's not needed.] |
| 117 | +### Building the Local JAR File |
| 118 | + |
| 119 | +```sh |
| 120 | +cd custom-log4j2-appender |
| 121 | +./build-local.sh |
| 122 | +``` |
55 | 123 |
|
56 | | -## Testing |
| 124 | +### Copying the Local JAR File to the Destination |
57 | 125 |
|
58 | | ->[**Optional** - Include instructions on how to run tests if we include tests with the codebase. Remove this section if it's not needed.] |
| 126 | +Example: |
| 127 | + |
| 128 | +```sh |
| 129 | +cp build/libs/custom-log4j2-appender.jar /Users/gsidhwani/AnypointStudio/studio-workspace/samplemuleapp/src/main/resources/ |
| 130 | +``` |
| 131 | + |
| 132 | +## Scripts |
| 133 | + |
| 134 | +### `publish-jar.sh` and `publish-shadowJar.sh` |
| 135 | + |
| 136 | +These scripts generate a Maven publishing compatible bundle for publishing to Maven Central. This is for New Relic's use, and users are not required to use it. They should mention this dependency in their application's `pom.xml` file to pull it directly from Maven Central or build locally as per the instructions above. |
59 | 137 |
|
60 | 138 | ## Support |
61 | 139 |
|
62 | 140 | New Relic has open-sourced this project. This project is provided AS-IS WITHOUT WARRANTY OR DEDICATED SUPPORT. Issues and contributions should be reported to the project here on GitHub. |
63 | 141 |
|
64 | | ->[Choose 1 of the 2 options below for Support details, and remove the other one.] |
65 | | -
|
66 | | ->[Option 1 - no specific thread in Community] |
67 | | ->We encourage you to bring your experiences and questions to the [Explorers Hub](https://discuss.newrelic.com) where our community members collaborate on solutions and new ideas. |
| 142 | +### Community Support |
68 | 143 |
|
69 | | ->[Option 2 - thread in Community] |
70 | | ->New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices. Like all official New Relic open source projects, there's a related Community topic in the New Relic Explorers Hub. |
71 | | ->You can find this project's topic/threads here: [URL for Community thread] |
| 144 | +We encourage you to bring your experiences and questions to the [Explorers Hub](https://discuss.newrelic.com) where our community members collaborate on solutions and new ideas. |
72 | 145 |
|
73 | 146 | ## Contributing |
74 | 147 |
|
75 | | -We encourage your contributions to improve [Project Name]! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at opensource@newrelic.com. |
| 148 | +We encourage your contributions to improve the New Relic Log4j 2 Appender! When you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA (required if your contribution is on behalf of a company), please drop us an email at opensource@newrelic.com. |
76 | 149 |
|
77 | | -**A note about vulnerabilities** |
| 150 | +### A Note About Vulnerabilities |
78 | 151 |
|
79 | | -As noted in our [security policy](../../security/policy), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals. |
| 152 | +As noted in our [security policy](../../security/policy), New Relic is committed to the privacy and security of our customers and their data. We believe that coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals. |
80 | 153 |
|
81 | 154 | If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through [HackerOne](https://hackerone.com/newrelic). |
82 | 155 |
|
83 | 156 | ## License |
84 | 157 |
|
85 | | -[Project Name] is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License. |
| 158 | +The New Relic Log4j 2 Appender is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License. |
86 | 159 |
|
87 | | ->[If applicable: [Project Name] also uses source code from third-party libraries. You can find full details on which libraries are used and the terms under which they are licensed in the third-party notices document.] |
|
0 commit comments