{"id":15523804,"url":"https://github.com/bwaldvogel/log4j-systemd-journal-appender","last_synced_at":"2025-04-23T07:21:57.178Z","repository":{"id":21804250,"uuid":"25126836","full_name":"bwaldvogel/log4j-systemd-journal-appender","owner":"bwaldvogel","description":"Log4j appender for systemd-journal that maintains structured log data","archived":false,"fork":false,"pushed_at":"2022-05-22T07:51:14.000Z","size":402,"stargazers_count":24,"open_issues_count":3,"forks_count":14,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T22:41:15.976Z","etag":null,"topics":["java","journald","log4j","systemd"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bwaldvogel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-12T17:41:19.000Z","updated_at":"2023-09-13T13:20:21.000Z","dependencies_parsed_at":"2022-07-16T14:18:10.320Z","dependency_job_id":null,"html_url":"https://github.com/bwaldvogel/log4j-systemd-journal-appender","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwaldvogel%2Flog4j-systemd-journal-appender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwaldvogel%2Flog4j-systemd-journal-appender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwaldvogel%2Flog4j-systemd-journal-appender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwaldvogel%2Flog4j-systemd-journal-appender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bwaldvogel","download_url":"https://codeload.github.com/bwaldvogel/log4j-systemd-journal-appender/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250387471,"owners_count":21422143,"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","journald","log4j","systemd"],"created_at":"2024-10-02T10:47:00.298Z","updated_at":"2025-04-23T07:21:57.152Z","avatar_url":"https://github.com/bwaldvogel.png","language":"Java","funding_links":["https://www.paypal.me/BenediktWaldvogel"],"categories":[],"sub_categories":[],"readme":"[![CI](https://github.com/bwaldvogel/log4j-systemd-journal-appender/workflows/CI/badge.svg)](https://github.com/bwaldvogel/log4j-systemd-journal-appender/actions)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/de.bwaldvogel/log4j-systemd-journal-appender/badge.svg)](http://maven-badges.herokuapp.com/maven-central/de.bwaldvogel/log4j-systemd-journal-appender)\n[![BSD 3-Clause License](https://img.shields.io/github/license/bwaldvogel/log4j-systemd-journal-appender.svg)](https://opensource.org/licenses/BSD-3-Clause)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/BenediktWaldvogel)\n\n[Log4j][log4j] appender that logs event meta data such as the timestamp, the logger name, the exception stacktrace, [ThreadContext (aka MDC)][thread-context] or the Java thread name to [fields][systemd-journal-fields] in [systemd journal][systemd-journal] (aka \"the Journal\") .\n\nRead Lennart Poettering's blog post [systemd for Developers III][systemd-for-developers] if you are not familar with [systemd journal][systemd-journal].\n\n## Usage with Log4j 2.x ##\nAdd the following Maven dependency to your project:\n\n```xml\n\u003cdependency\u003e\n\t\u003cgroupId\u003ede.bwaldvogel\u003c/groupId\u003e\n\t\u003cartifactId\u003elog4j-systemd-journal-appender\u003c/artifactId\u003e\n\t\u003cversion\u003e2.5.1\u003c/version\u003e\n\t\u003cscope\u003eruntime\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n## Usage with Log4j 1.x ##\n\nSee the [`1.x` branch][1.x-branch] of this project.\n\n### Runtime dependencies ###\n\n- Java 8 or later\n- Linux with systemd-journal\n- Log4j 2.x\n\n**Note:**\n\nJNA requires execute permissions in `java.io.tmpdir` (which defaults to `/tmp`).\nFor example, if the folder is mounted with \"`noexec`\" for security reasons, you need to define a different temporary directory for JNA:\n\n    -Djna.tmpdir=/tmp-folder/with/exec/permissions\n\n## Configuration\n\nThe appender can be configured with the following properties\n\nProperty name         | Default           | Type    | Description\n--------------------- | ----------------- | ------- | -----------\n`logSource`           | false             | boolean | Determines whether the log locations are logged. Note that there is a performance overhead when switched on. The data is logged in standard systemd journal fields `CODE_FILE`, `CODE_LINE` and `CODE_FUNC`.\n`logStacktrace`       | true              | boolean | Determines whether the full exception stack trace is logged. This data is logged in the user field `STACKTRACE`.\n`logThreadName`       | true              | boolean | Determines whether the thread name is logged. This data is logged in the user field `THREAD_NAME`.\n`logLoggerName`       | true              | boolean | Determines whether the logger name is logged. This data is logged in the user field `LOG4J_LOGGER`.\n`logAppenderName`     | true              | boolean | Determines whether the appender name is logged. This data is logged in the user field `LOG4J_APPENDER`.\n`logThreadContext`    | true              | boolean | Determines whether the [thread context][thread-context] is logged. Each key/value pair is logged as user field with the `threadContextPrefix` prefix.\n`threadContextPrefix` | `THREAD_CONTEXT_` | String  | Determines how [thread context][thread-context] keys should be prefixed when `logThreadContext` is set to true. Note that keys need to match the regex pattern `[A-Z0-9_]+` and are normalized otherwise.\n`syslogIdentifier`    | null              | String  | This data is logged in the syslog compatibility field `SYSLOG_IDENTIFIER`. If this is not set, the underlying system will use the command name (usually `java`) instead.\n`syslogFacility`      | null              | Number  | This data is logged in the syslog compatibility field `SYSLOG_FACILITY`.\n\n## Example ##\n\n### `log4j2.xml`\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cConfiguration status=\"INFO\" packages=\"de.bwaldvogel.log4j\"\u003e\n    \u003cAppenders\u003e\n        \u003cConsole name=\"console\" target=\"SYSTEM_OUT\"\u003e\n            \u003cPatternLayout pattern=\"%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n\" /\u003e\n        \u003c/Console\u003e\n        \u003cSystemdJournal name=\"journal\" logStacktrace=\"true\" logSource=\"false\" /\u003e\n    \u003c/Appenders\u003e\n    \u003cLoggers\u003e\n        \u003cRoot level=\"INFO\"\u003e\n            \u003cAppenderRef ref=\"console\" /\u003e\n            \u003cAppenderRef ref=\"journal\" /\u003e\n        \u003c/Root\u003e\n    \u003c/Loggers\u003e\n\u003c/Configuration\u003e\n```\n\nThis will tell Log4j to log to [systemd journal][systemd-journal] as well as to stdout (console).\nNote that a layout is optional for `SystemdJournal`.\nThis is because meta data of a log event such as the timestamp, the logger name or the Java thread name are mapped to [systemd-journal fields][systemd-journal-fields] and need not be rendered into a string that loses all the semantic information.\n\n### `YourExample.java`\n```java\nimport org.apache.logging.log4j.*;\n\nclass YourExample {\n\n    private static Logger logger = LogManager.getLogger(YourExample.class);\n\n    public static void main(String[] args) {\n        ThreadContext.put(\"MY_KEY\", \"some value\");\n        logger.info(\"this is an example\");\n    }\n}\n```\n\nRunning this sample class will log a message to journald:\n\n### Systemd Journal\n\n```\n# journalctl -n\nOkt 13 21:26:00 myhost java[2370]: this is an example\n```\n\nUse `journalctl -o verbose` to show all fields:\n\n```\n# journalctl -o verbose -n\nDi 2015-09-29 21:07:05.850017 CEST [s=45e0…;i=984;b=c257…;m=1833…;t=520e…;x=3e1e…]\n    PRIORITY=6\n    _TRANSPORT=journal\n    _UID=1000\n    _GID=1000\n    _CAP_EFFECTIVE=0\n    _SYSTEMD_OWNER_UID=1000\n    _SYSTEMD_SLICE=user-1000.slice\n    _MACHINE_ID=4abc6d…\n    _HOSTNAME=myhost\n    _SYSTEMD_CGROUP=/user.slice/user-1000.slice/session-2.scope\n    _SYSTEMD_SESSION=2\n    _SYSTEMD_UNIT=session-2.scope\n    _BOOT_ID=c257f8…\n    THREAD_NAME=main\n    LOG4J_LOGGER=de.bwaldvogel.log4j.SystemdJournalAppenderIntegrationTest\n    _COMM=java\n    _EXE=/usr/bin/java\n    MESSAGE=this is a test message with a MDC\n    CODE_FILE=SystemdJournalAppenderIntegrationTest.java\n    CODE_FUNC=testMessageWithMDC\n    CODE_LINE=36\n    THREAD_CONTEXT_MY_KEY=some value\n    SYSLOG_IDENTIFIER=log4j2-test\n    LOG4J_APPENDER=Journal\n    _PID=8224\n    _CMDLINE=/usr/bin/java …\n    _SOURCE_REALTIME_TIMESTAMP=1443553625850017\n```\n\nNote that the [ThreadContext][thread-context] key-value pair `{\"MY_KEY\": \"some value\"}` is automatically added as field with prefix `THREAD_CONTEXT`.\n\nYou can use the power of [systemd journal][systemd-journal] to filter for interesting messages. Example:\n\n`journalctl CODE_FUNC=testMessageWithMDC THREAD_NAME=main` will only show messages that are logged from the Java main thread in a method called `testMessageWithMDC`.\n\n\n## Contributing ##\n\nWe are happy to receive pull-requests if you want to contribute code to the project.\n\nIf you want to thank the author for this library or want to support the maintenance work,\nwe are happy to receive a donation.\n\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/BenediktWaldvogel)\n\n\n## Related Work ##\n\n* [logback-journal][logback-journal]\n\t* Systemd Journal appender for Logback\n\n[1.x-branch]: https://github.com/bwaldvogel/log4j-systemd-journal-appender/tree/1.x\n[log4j]: http://logging.apache.org/log4j/2.x/\n[thread-context]: http://logging.apache.org/log4j/2.x/manual/thread-context.html\n[systemd-for-developers]: http://0pointer.de/blog/projects/journal-submit.html\n[systemd-journal]: http://www.freedesktop.org/software/systemd/man/systemd-journald.service.html\n[systemd-journal-fields]: http://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html\n[logback-journal]: https://github.com/gnieh/logback-journal\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwaldvogel%2Flog4j-systemd-journal-appender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbwaldvogel%2Flog4j-systemd-journal-appender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwaldvogel%2Flog4j-systemd-journal-appender/lists"}