{"id":15337294,"url":"https://github.com/vy/log4j2-redis-appender","last_synced_at":"2025-04-13T21:36:49.534Z","repository":{"id":21107410,"uuid":"91571398","full_name":"vy/log4j2-redis-appender","owner":"vy","description":"A Log4j 2 Appender for Redis.","archived":false,"fork":false,"pushed_at":"2024-04-29T00:31:54.000Z","size":399,"stargazers_count":32,"open_issues_count":0,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-02T06:09:20.360Z","etag":null,"topics":["java","log4j2","logging","redis"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"COPYING.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"vy"}},"created_at":"2017-05-17T11:58:59.000Z","updated_at":"2024-05-22T05:38:34.190Z","dependencies_parsed_at":"2023-02-17T01:50:15.341Z","dependency_job_id":"1bff0346-b589-43bf-811e-dc21eeb67eea","html_url":"https://github.com/vy/log4j2-redis-appender","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vy%2Flog4j2-redis-appender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vy%2Flog4j2-redis-appender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vy%2Flog4j2-redis-appender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vy%2Flog4j2-redis-appender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vy","download_url":"https://codeload.github.com/vy/log4j2-redis-appender/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788651,"owners_count":21161725,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","log4j2","logging","redis"],"created_at":"2024-10-01T10:20:29.861Z","updated_at":"2025-04-13T21:36:49.508Z","avatar_url":"https://github.com/vy.png","language":"Java","funding_links":["https://github.com/sponsors/vy"],"categories":[],"sub_categories":[],"readme":"\u003c!---\n Copyright 2017-2024 Volkan Yazıcı\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n        https://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permits and\n limitations under the License.\n--\u003e\n\n[![Actions Status](https://github.com/vy/log4j2-redis-appender/workflows/build/badge.svg)](https://github.com/vy/log4j2-redis-appender/actions)\n[![Maven Central](https://img.shields.io/maven-central/v/com.vlkan.log4j2/log4j2-redis-appender-parent.svg)](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.vlkan.log4j2%22)\n[![License](https://img.shields.io/github/license/vy/log4j2-redis-appender.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\n`RedisAppender` plugin provides a [Log4j 2.x](https://logging.apache.org/log4j/2.x/)\nappender for [Redis](https://redis.io/) in-memory data structure store. The plugin\nuses [Jedis](https://github.com/xetorthio/jedis) as a client for Redis.\n\n# Usage\n\nAdd the `log4j2-redis-appender` dependency to your POM file\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.vlkan.log4j2\u003c/groupId\u003e\n    \u003cartifactId\u003elog4j2-redis-appender\u003c/artifactId\u003e\n    \u003cversion\u003e${log4j2-redis-appender.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\ntogether with a valid `log4j-core` dependency:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.apache.logging.log4j\u003c/groupId\u003e\n    \u003cartifactId\u003elog4j-core\u003c/artifactId\u003e\n    \u003cversion\u003e${log4j2.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nBelow you can find a sample `log4j2.xml` snippet employing `RedisAppender`.\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cConfiguration\u003e\n    \u003cAppenders\u003e\n        \u003cRedisAppender name=\"REDIS\"\n                       key=\"log4j2-messages\"\n                       host=\"localhost\"\n                       port=\"6379\"\u003e\n            \u003cPatternLayout pattern=\"%level %msg\"/\u003e\n            \u003cRedisConnectionPoolConfig testWhileIdle=\"true\"\n                                       minEvictableIdleTimeMillis=\"60000\"\n                                       timeBetweenEvictionRunsMillis=\"30000\"\n                                       numTestsPerEvictionRun=\"-1\"/\u003e\n            \u003cRedisThrottlerConfig bufferSize=\"500\"\n                                  batchSize=\"100\"\n                                  flushPeriodMillis=\"1000\"\n                                  maxEventCountPerSecond=\"100\"\n                                  maxByteCountPerSecond=\"4194304\"\n                                  maxErrorCountPerSecond=\"0.003\"/\u003e\n        \u003c/RedisAppender\u003e\n    \u003c/Appenders\u003e\n    \u003cLoggers\u003e\n        \u003cRoot level=\"all\"\u003e\n            \u003cAppenderRef ref=\"REDIS\"/\u003e\n        \u003c/Root\u003e\n    \u003c/Loggers\u003e\n\u003c/Configuration\u003e\n```\n\nOne can make `RedisAppender` work against a\n[sentinel](https://redis.io/topics/sentinel) setup using `sentinelNodes` and\n`sentinelMaster` parameters:\n\n```xml\n\u003cRedisAppender name=\"REDIS\"\n               key=\"log4j2-messages\"\n               sentinelNodes=\"localhost:63791,localhost:63792\"\n               sentinelMaster=\"mymaster\"\u003e\n...\n\u003c/RedisAppender\u003e\n```\n\nNote that `sentinelNodes` and `sentinelMaster` have priority over `host` and\n`port` parameters.\n\n`RedisAppender` is configured with the following parameters:\n\n| Parameter Name | Type | Default | Description |\n|----------------|------|---------|-------------|\n| `charset` | String | `UTF-8` | output charset |\n| `database` | int | 0 | Redis logical database |\n| `key` | String | | Redis queue key |\n| `host` | String | `localhost` | Redis host|\n| `port` | int | 6379 | Redis port |\n| `sentinelNodes` | String | `null` | Redis sentinel nodes as comma-separated list, e.g., `host1:port1,host2:port2`. If specified, `host` and `port` parameters are ignored. |\n| `sentinelMaster` | String | `null` | Redis sentinel master name |\n| `username` | String | `default` | Redis username |\n| `password` | String | `null` | Redis password |\n| `command` | String | `rpush` | Redis command for writing to the queue. Accepts `rpush` (default) and `publish`. |\n| `connectionTimeoutSeconds` | int | 2 | initial connection timeout in seconds |\n| `socketTimeoutSeconds` | int | 2 | socket timeout in seconds |\n| `ignoreExceptions` | boolean | `true` | Enabling causes exceptions encountered while appending events to be internally logged and then ignored. When set to false, exceptions will be propagated to the caller, instead. You must set this to false when wrapping this appender in a `FailoverAppender`. |\n| `Layout` | Layout | `PatternLayout` | used to format the `LogEvent`s |\n| `RedisConnectionPoolConfig` | RedisConnectionPoolConfig | | Redis connection pool configuration |\n| `RedisThrottlerConfig` | RedisThrottlerConfig | | Redis throttler configuration |\n\n## Redis Connection Pool\n\n`RedisConnectionPoolConfig` is a wrapper for `JedisPoolConfig` which extends\n[GenericObjectPoolConfig](https://commons.apache.org/proper/commons-pool/apidocs/org/apache/commons/pool2/impl/GenericObjectPoolConfig.html)\nof [Apache Commons Pool](https://commons.apache.org/proper/commons-pool/).\nBelow is a complete list of available `RedisConnectionPoolConfig` attributes.\n\n| Parameter Name | Type | Default |\n|----------------|------|-------------|\n| `maxTotal` | int | 8 |\n| `maxIdle` | int | 8 |\n| `minIdle` | int | 0 |\n| `lifo` | boolean | `true` |\n| `fairness` | boolean | `false` |\n| `maxWaitMillis` | long | -1 |\n| `minEvictableIdleTimeMillis` | long | 1000 * 60 |\n| `softMinEvictableIdleTimeMillis` | long | -1 |\n| `numTestsPerEvictionRun` | int | -1 |\n| `testOnCreate` | boolean | `false` |\n| `testOnBorrow` | boolean | `false` |\n| `testOnReturn` | boolean | `false` |\n| `testWhileIdle` | boolean | `true` |\n| `timeBetweenEvictionRunsMillis` | long | 1000 * 30 |\n| `evictionPolicyClassName` | String | `org.apache.commons.pool2.impl.DefaultEvictionPolicy` |\n| `blockWhenExhausted` | boolean | `true` |\n| `jmxEnabled` | boolean | `true` |\n| `jmxNameBase` | String | `null` |\n| `jmxNamePrefix` | String | `com.vlkan.log4j2.redis.appender.JedisConnectionPool` |\n\n## Redis Throttler\n\nWhile Log4j 2 provides utilities like\n[BurstFilter](https://logging.apache.org/log4j/2.x/manual/filters.html#BurstFilter)\nand [AsyncAppender](https://logging.apache.org/log4j/2.x/manual/appenders.html#AsyncAppender)\nthat you can wrap around any appender to facilitate throttling,\n[the appender API](https://logging.apache.org/log4j/2.0/log4j-core/apidocs/org/apache/logging/log4j/core/Appender.html)\n[falls short of communicating this intent](http://mail-archives.apache.org/mod_mbox/logging-dev/201706.mbox/browser).\nHence, `RedisAppender` provides its own throttling mechanics to exploit batch\npushes available in [Redis RPUSH](https://redis.io/commands/rpush). This\nfeature is configured by `RedisThrottlerConfig` element using the following\nattributes:\n\n| Parameter Name | Type | Description |\n|----------------|------|-------------|\n| `bufferSize` | int | `LogEvent` buffer size (defaults to 500) |\n| `batchSize` | int | size of batches fed into Redis `RPUSH` (defaults to 100) |\n| `flushPeriodMillis` | long | buffer flush period (defaults to 1000) |\n| `maxEventCountPerSecond` | double | allowed maximum number of events per second (defaults to 0, that is, unlimited) |\n| `maxByteCountPerSecond` | double | allowed maximum number of bytes per second (defaults to 0, that is, unlimited) |\n| `maxErrorCountPerSecond` | double | allowed maximum number of errors per second propagated (defaults to 0.003, that is, approximately once every 5 minutes) |\n| `jmxBeanName` | String | `RedisThrottlerJmxBean` name (defaults to `org.apache.logging.log4j2:type=\u003cloggerContextName\u003e,component=Appenders,name=\u003cappenderName\u003e,subtype=RedisThrottler`) |\n\nThe buffer is flushed if either there are more than `batchSize` events\nqueued in the buffer, or the last flush was older than `flushPeriodMillis`.\n\n`maxErrorCountPerSecond` is there to avoid flooding logs if the application\nis suffering a shortage of memory, or the Redis server is unreachable.\n\nFat JAR\n=======\n\nProject also contains a `log4j2-redis-appender-fatjar` artifact which\nincludes all its transitive dependencies in a separate shaded package (to\navoid the JAR Hell) with the exception of `log4j-core`, that you need to\ninclude separately.\n\nThis might come handy if you want to use this plugin along with already\ncompiled applications, e.g., Elasticsearch 5.x, which requires Log4j 2.x.\n\nF.A.Q.\n======\n\n- **How can I connect to multiple Redis servers for failover?** You can define\n  multiple Redis appenders nested under a\n  [FailoverAppender](https://logging.apache.org/log4j/2.x/manual/appenders.html#FailoverAppender).\n  (Don't forget to turn off `ignoreExceptions` flag.)\n\n- **How can I avoid getting `AccessControlException` exceptions?** If you are\n  using the plugin in a security manager enabled Java application (for\n  instance, which is the case for Elasticsearch since version 2.3), you\n  might be getting `AccessControlException` exceptions as follows:\n\n  ```\n  [2017-06-23T11:25:35,644][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [tst-store-001.data] uncaught exception in thread [commons-pool-EvictionTimer]\n  java.security.AccessControlException: access denied (\"java.lang.RuntimePermission\" \"setContextClassLoader\")\n          at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) ~[?:1.8.0_131]\n          at java.security.AccessController.checkPermission(AccessController.java:884) ~[?:1.8.0_131]\n          at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) ~[?:1.8.0_131]\n          at java.lang.Thread.setContextClassLoader(Thread.java:1474) [?:1.8.0_131]\n          at org.apache.commons.pool2.impl.BaseGenericObjectPool$Evictor.run(BaseGenericObjectPool.java:1052) ~[log4j2-redis-appender.jar:?]\n          at java.util.TimerThread.mainLoop(Timer.java:555) ~[?:1.8.0_131]\n          at java.util.TimerThread.run(Timer.java:505) ~[?:1.8.0_131]\n  ```\n\n  To alleviate this, you need to grant necessary permissions using a\n  [policy file](http://docs.oracle.com/javase/8/docs/technotes/guides/security/PolicyFiles.html):\n\n  ```\n  grant {\n      permission java.lang.RuntimePermission \"setContextClassLoader\";\n  };\n  ```\n\n  Then you can activate this policy for your application via either placing it\n  under one of [default policy file locations](http://docs.oracle.com/javase/8/docs/technotes/guides/security/PolicyFiles.html#DefaultLocs)\n  (e.g., `$JAVA_HOME/lib/security/java.policy`) or providing it as an argument\n  at runtime, that is, `-Djava.security.policy=someURL`.\n\n- **How can I access JMX bean of an appender?** Once you have a reference to\n  the relevant `LoggerContext`, you can access the instance of the appender\n  and its JMX bean by its name as follows:\n\n  ```java\n  Appender appender = loggerContext.getConfiguration().getAppender(\"REDIS\");\n  RedisThrottlerJmxBean jmxBean = ((RedisAppender) appender).getJmxBean();\n  ```\n\n  You can either create your own `LoggerContext`:\n\n  ```java\n  LoggerContextResource loggerContextResource = new LoggerContextResource(\"/path/to/log4j2.xml\");\n  LoggerContext loggerContext = loggerContextResource.getLoggerContext();\n  ```\n\n  or get a handle to an existing one:\n\n  ```java\n   LoggerContext logContext = (LoggerContext) LogManager.getContext(false);\n   ```\n\n   Here note that you should be using `org.apache.logging.log4j.core.LoggerContext`,\n   not `org.apache.logging.log4j.spi.LoggerContext`.\n\nContributors\n============\n\n- [Boris Faniuk](https://github.com//bfanyuk)\n- [Khaled Bakhtiari](https://github.com/ec84b4)\n- [Roberto Martinez Caballero](https://github.com/rmarticaba)\n- [t9t](https://github.com/t9t)\n- [Yaroslav Skopets](https://github.com/yskopets)\n\n# Security policy\n\nIf you have encountered an unlisted security vulnerability or other unexpected behaviour that has security impact, please report them privately to the [volkan@yazi.ci](mailto:volkan@yazi.ci) email address.\n\n# License\n\nCopyright \u0026copy; 2017-2024 [Volkan Yazıcı](https://volkan.yazi.ci/)\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvy%2Flog4j2-redis-appender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvy%2Flog4j2-redis-appender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvy%2Flog4j2-redis-appender/lists"}