{"id":16284963,"url":"https://github.com/goodforgod/slf4j-simple-logger","last_synced_at":"2025-03-20T02:31:22.842Z","repository":{"id":41992871,"uuid":"415276240","full_name":"GoodforGod/slf4j-simple-logger","owner":"GoodforGod","description":"⚙️ SLF4J based, simple, efficient and structured logger implementation.","archived":false,"fork":false,"pushed_at":"2023-10-07T22:36:42.000Z","size":273,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T13:46:26.647Z","etag":null,"topics":["graalvm","java","json","logger","logging-library","simple","slf4j","slf4j-api","slf4j-logger","structured-logging"],"latest_commit_sha":null,"homepage":"http://goodforgod.dev/slf4j-simple-logger/","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/GoodforGod.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-09T10:27:57.000Z","updated_at":"2024-05-21T19:12:04.000Z","dependencies_parsed_at":"2024-10-10T19:21:48.799Z","dependency_job_id":null,"html_url":"https://github.com/GoodforGod/slf4j-simple-logger","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":"GoodforGod/java-library-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodforGod%2Fslf4j-simple-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodforGod%2Fslf4j-simple-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodforGod%2Fslf4j-simple-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodforGod%2Fslf4j-simple-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoodforGod","download_url":"https://codeload.github.com/GoodforGod/slf4j-simple-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244538589,"owners_count":20468745,"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":["graalvm","java","json","logger","logging-library","simple","slf4j","slf4j-api","slf4j-logger","structured-logging"],"created_at":"2024-10-10T19:21:44.041Z","updated_at":"2025-03-20T02:31:22.357Z","avatar_url":"https://github.com/GoodforGod.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SLF4J Simple Logger\n\n![GraalVM Enabled](https://img.shields.io/badge/GraalVM-Ready-orange?style=plastic)\n[![Minimum required Java version](https://img.shields.io/badge/Java-11%2B-blue?logo=openjdk)](https://openjdk.org/projects/jdk/11/)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/slf4j-simple-logger/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.goodforgod/slf4j-simple-logger)\n[![Java CI](https://github.com/GoodforGod/slf4j-simple-logger/workflows/CI%20Master/badge.svg)](https://github.com/GoodforGod/slf4j-simple-logger/actions?query=workflow%3ACI+Master)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_slf4j-simple-logger\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=GoodforGod_slf4j-simple-logger)\n[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_slf4j-simple-logger\u0026metric=sqale_rating)](https://sonarcloud.io/dashboard?id=GoodforGod_slf4j-simple-logger)\n[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=GoodforGod_slf4j-simple-logger\u0026metric=ncloc)](https://sonarcloud.io/dashboard?id=GoodforGod_slf4j-simple-logger)\n\n[SLF4J](https://github.com/qos-ch/slf4j) based, simple, efficient logger.\n\nThis logger is great for applications that use synchronous output or run in single-thread like command line applications or Serverless applications.\n\nFeatures:\n- Performance optimizations.\n- GraalVM friendly.\n- JSON format support.\n- Environment variables logging.\n- [slf4j-simple-logger](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) compatible configuration.\n\nAnd more...\n\n## Dependency :rocket:\n\n[**Gradle**](https://mvnrepository.com/artifact/io.goodforgod/slf4j-simple-logger)\n```groovy\nimplementation \"io.goodforgod:slf4j-simple-logger:2.0.0\"\n```\n\n[**Maven**](https://mvnrepository.com/artifact/io.goodforgod/slf4j-simple-logger)\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.goodforgod\u003c/groupId\u003e\n    \u003cartifactId\u003eslf4j-simple-logger\u003c/artifactId\u003e\n    \u003cversion\u003e2.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Content\n\n- [Logging example](#logging-example)\n  - [Text format](#text-format)\n  - [Json format](#json-format)\n- [Features](#features)\n  - [Performance Optimizations](#performance-optimizations)\n  - [Output format](#output-format)\n  - [DateTime output](#datetime-output)\n  - [Logger name abbreviation](#logger-name-abbreviation)\n  - [Environment logging](#environment-logging)\n  - [Environment configuration](#environment-configuration)\n    - [Runtime refresh](#runtime-refresh)\n  - [Output split](#output-split)\n  - [Callable and Supplier](#callable-and-supplier)\n  - [Logger level change](#logger-level-change)\n- [Configuration](#configuration)\n- [Compatability](#slf4j-compatability)\n\n## Logging example\n\n### Text format\n\nBelow is example of logged message in text format:\n```java\nMarker myMarker = MarkerFactory.getMarker(\"my_marker\");\nmyMarker.add(MarkerFactory.getMarker(\"my_marker_ref\"));\nlogger.debug(myMarker, \"Message is printed for this logger\");\n```\n\nResult logged message:\n```text\n       Date Time        Implementation  Log Level              Markers                     Environment variables       Thread         Logger Name                     Log Message\n           |                   |            |                     |                                   |                   |                |                               |\n___________|__________   ______|_______   __|__   ________________|______________   __________________|_______________  __|__   ___________|___________    ________________|________________\n|                     | |              | |     | |                                |                                   | |    | |                       |  |                                |\n|                     | |              | |     | |                                |                                   | |    | |                       |  |                                |\n2022-02-23T15:43:40.331 [0.9.0-SNAPSHOT] [DEBUG] [markers=my_marker,my_marker_ref] [SESSION=Console, PROCESSOR_LEVEL=6] [main] io.goodforgod.Application - Message is printed for this logger\n```\n\n### Json format\n\nBelow is example of logged message in json format:\n```java\nException e = new RuntimeException();\nMarker myMarker = MarkerFactory.getMarker(\"my_marker\");\nmyMarker.add(MarkerFactory.getMarker(\"my_marker_ref\"));\nlogger.debug(myMarker, \"Message is printed for this logger\", e);\n```\n\nResult logged message:\n```json\n{\n  \"timestamp\": \"2022-02-23T15:43:40.331\",\n  \"implementation\": \"0.9.0-SNAPSHOT\",\n  \"level\": \"DEBUG\",\n  \"thread\": \"main\",\n  \"logger\": \"io.goodforgod.Application\",\n  \"markers\": [\"my_marker\", \"my_marker_ref\"],\n  \"environment\": [\n    {\n      \"name\": \"SESSION\",\n      \"value\": \"Console\"\n    },\n    {\n      \"name\": \"PROCESSOR_LEVEL\",\n      \"value\": \"6\"\n    }\n  ],\n  \"message\": \"Message is printed for this logger\",\n  \"exception\": \"Ops\",\n  \"stacktrace\": [\n    {\n      \"clazz\": \"io.goodforgod.slf4j.simplelogger.JsonLoggerLayoutTests\",\n      \"message\": \"Ops\",\n      \"method\": \"throwableOutput:279\"\n    },\n    {\n      \"clazz\": \"jdk.internal.reflect.NativeMethodAccessorImpl\",\n      \"method\": \"invoke0:-2\"\n    }\n  ]\n}\n```\n\n## Features\n\n### Performance optimizations\n\nThis implementation is based on default *slf4j-simple-logger*, but there are plenty of performance and feature improvements.\n\nSome cases are 200% faster others are 800% faster, you can read more about here in my [JVM benchmark](https://github.com/GoodforGod/java-logger-benchmark).\n\n### Output format\n\nThere is option to output logged messages in different formats, currently supported formats:\n- TEXT\n- JSON\n\nYou can check example of each format [here](#logging-example).\n\nConfiguration for format is below for TEXT (default value).\n```properties\norg.slf4j.simpleLogger.format=TEXT\n```\n\nAnd same for JSON:\n```properties\norg.slf4j.simpleLogger.format=JSON\n```\n\n### DateTime output\n\nThere are three options to output date \u0026 time:\n1) DATE_TIME - in format *uuuu-MM-dd'T'HH:mm:ss.SSS*, example is - *2022-02-23T15:43:40.331* (read more about Java [Date \u0026 Time formats here](https://goodforgod.dev/posts/2/))\n2) TIME - in format *HH:mm:ss.SSS*, example is - *15:43:40.331* (read more about Java [Date \u0026 Time formats here](https://goodforgod.dev/posts/2/))\n3) UNIX_TIME - time [since epoch](https://en.wikipedia.org/wiki/Unix_time).\n4) MILLIS_FROM_START - Millis from SimpleLoggerConfiguration initialization (may not properly work in GraalVM setups)\n\nYou can also change formatter for DATE_TIME and TIME via configuration:\n```properties\norg.slf4j.simpleLogger.dateTimeFormat=uuuu-MM-dd'T'HH:mm:ss.SSS\n```\n\n### Logger name abbreviation\n\nThere is configuration to abbreviate logger name, like in logback.\n\nIf configuration is:\n```properties\norg.slf4j.simpleLogger.showShortLogName=false\norg.slf4j.simpleLogger.showLogName=true\norg.slf4j.simpleLogger.logNameLength=36\n```\n\nAnd logger is:\n```java\npackage io.goodforgod.internal.logger.example;\n\nimport org.slf4j.LoggerFactory;\nimport org.slf4j.Logger;\n\npublic class Application {\n\n    public static void main(String[] args) {\n        Logger logger = LoggerFactory.getLogger(Application.class);\n        logger.info(\"Message is printed for this logger\");\n    }\n}\n```\n\nThen logger name will be outputted like:\n```text\n2022-02-23T15:43:40.331 [DEBUG] i.g.i.logger.example.Application - Message is printed for this logger\n```\n\nAbbreviation happened to full logger name:\n*io.goodforgod.internal.logger.example.Application* -\u003e *i.g.i.logger.example.Application*\n\n### Environment logging\n\nIt is possible to log environment, format how it will be outputted can be seen [here](#log-example).\n\nIf the configuration is:\n```properties\n# Set environment names to show in output. Envs will be printed out in order they preserve in configuration.\norg.slf4j.simpleLogger.environments=SESSION,PROCESSOR_LEVEL\n# Set to true to show environment with nullable values.\norg.slf4j.simpleLogger.environmentShowNullable=false\n# Set to true to show environment names.\norg.slf4j.simpleLogger.environmentShowName=true\n# Set to true to caches environment values on configuration initialization and then always uses them when logging.\norg.slf4j.simpleLogger.environmentRememberOnStart=false\n```\n\nThen the output will be:\n```text\n2022-02-23T15:43:40.331 [DEBUG] [SESSION=Console, PROCESSOR_LEVEL=6] [main] io.goodforgod.Application - Message is printed for this logger\n```\n\nEnvironment variables are printed in order they preserve in configuration (in example above first SESSION, then PROCESSOR_LEVEL).\n\n### Environment configuration\n\nYou can use environment variables to configure values for property config.\n\nBelow is example where there are two environment variables are used for configuration (*SHOW_LOG_NAME* and *LOG_NAME_LENGTH*):\n```\norg.slf4j.simpleLogger.showLogName=${SHOW_LOG_NAME}\norg.slf4j.simpleLogger.logNameLength=${LOG_NAME_LENGTH:36}\n```\n\nIf environment variable value is absent, then [default value](#configuration) is used.\n\n#### Runtime refresh\n\nEnvironment variable configuration can be refresh in runtime. This can be useful when environment changed, and it is required to update logger config without stopping application.\n```java\nSimpleLoggerFactory.refresh();\n```\n\nOnly these properties can be changed in runtime:\n```properties\n# Default logging level for all loggers. Must be one of (\"TRACE\", \"DEBUG\", \"INFO\", \"WARN\", or \"ERROR\"). (default INFO)\norg.slf4j.simpleLogger.defaultLogLevel=INFO\n# Set logging message output format. Must be one of (\"TEXT\", \"JSON\"). (default TEXT)\norg.slf4j.simpleLogger.format=TEXT\n# Set to true to show current datetime in output. (default true)\norg.slf4j.simpleLogger.showDateTime=true\n# Set datetime output type. Must be one of (\"TIME\", \"DATE_TIME\", \"UNIX_TIME\", \"MILLIS_FROM_START\"). (default DATE_TIME)\norg.slf4j.simpleLogger.dateTimeOutputType=DATE_TIME\n# The date and time formatter pattern to be used in the output. (default uuuu-MM-dd'T'HH:mm:ss.SSS)\norg.slf4j.simpleLogger.dateTimeFormat=uuuu-MM-dd'T'HH:mm:ss.SSS\n# Set ZoneId to use as adjustment for DATE_TIME or TIME. (default ZoneId.systemDefault())\norg.slf4j.simpleLogger.zoneId=UTC\n# Set to true if to show application implementation version from MANIFEST.MF (default false)\norg.slf4j.simpleLogger.showImplementationVersion=false\n# Set to true to show logging level in brackets like: [INFO] (default true)\norg.slf4j.simpleLogger.levelInBrackets=true\n# Set to true if to show current thread in output. (default false)\norg.slf4j.simpleLogger.showThreadName=false\n# Set to true if to show marker parameter values. (default false)\norg.slf4j.simpleLogger.showMarkers=false\n# Set to true to show only class name in output. (default false)\norg.slf4j.simpleLogger.showShortLogName=false\n# Set to true if to show full class name in output (package + class name). (default true)\norg.slf4j.simpleLogger.showLogName=true\n# Set maximum logger name to output and abbreviate if it exceeds length. (default null)\norg.slf4j.simpleLogger.logNameLength=36\n# Set environment names to show in output. Envs will be printed out in order they preserve in configuration. (default null)\norg.slf4j.simpleLogger.environments=SESSION_ID,ORIGIN,HOST\n# Set to true to show environment with nullable values. (default false)\norg.slf4j.simpleLogger.environmentShowNullable=false\n# Set to true to show environment names. (default false)\norg.slf4j.simpleLogger.environmentShowName=false\n```\n\n### Output split\n\nThere is possibility to split *WARN* and *ERROR* logs to different output.\n\nIf configuration is:\n```properties\n# Set default logger output file or System.out or System.error (default System.out)\norg.slf4j.simpleLogger.logFile=System.out\n# Set logger WARN logs output file or System.out or System.error (default System.out)\norg.slf4j.simpleLogger.logFileWarn=System.error\n# Set logger ERROR logs output file or System.out or System.error (default System.out)\norg.slf4j.simpleLogger.logFileError=System.error\n```\n\nThen all logs of TRACE, DEBUG, INFO will be forwarded to *System.out* and all WARN \u0026 ERROR logs will be forwarded to *System.error*.\n\n### Callable and Supplier\n\nCallable or Supplier can be passed as arguments to logger and computed correctly:\n```java\nCallable\u003cString\u003e supplier = () -\u003e \"argument\";\nlogger.info(\"Value supplier is {}.\", supplier);\n```\nResulted output:\n```text\nValue supplier is argument.\n```\n\n### Logger level change\n\nYou can change loggers level using *io.goodforgod.slf4j.simplelogger.SimpleLoggerFactory*:\n```java\nSimpleLoggerFactory factory = (SimpleLoggerFactory) LoggerFactory.getILoggerFactory();\nfactory.setLogLevel(Level.DEBUG);\n```\n\nOr you can use predicate to filter out loggers:\n```java\nSimpleLoggerFactory factory = (SimpleLoggerFactory) LoggerFactory.getILoggerFactory();\nfactory.setLogLevel(Level.DEBUG, logger -\u003e logger.getName().startsWith(\"io.goodforgod.internal.logger.example\"));\n```\n\n## Configuration\n\nLibrary is fully compatibly with *slf4j-simple-logger* configuration, you can check it [here](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html).\n\nExample of full *simplelogger.properties* file:\n```properties\n# Default logging level for all loggers. Must be one of (\"TRACE\", \"DEBUG\", \"INFO\", \"WARN\", or \"ERROR\"). (default INFO)\norg.slf4j.simpleLogger.defaultLogLevel=INFO\n# Set logging message output format. Must be one of (\"TEXT\", \"JSON\"). (default TEXT)\norg.slf4j.simpleLogger.format=TEXT\n# Set to true to show current datetime in output. (default true)\norg.slf4j.simpleLogger.showDateTime=true\n# Set datetime output type. Must be one of (\"TIME\", \"DATE_TIME\", \"UNIX_TIME\", \"MILLIS_FROM_START\"). (default DATE_TIME)\norg.slf4j.simpleLogger.dateTimeOutputType=DATE_TIME\n# The date and time formatter pattern to be used in the output. (default uuuu-MM-dd'T'HH:mm:ss.SSS)\norg.slf4j.simpleLogger.dateTimeFormat=uuuu-MM-dd'T'HH:mm:ss.SSS\n# Set ZoneId to use as adjustment for DATE_TIME or TIME. (default ZoneId.systemDefault())\norg.slf4j.simpleLogger.zoneId=UTC\n# Set to true if to show application implementation version from MANIFEST.MF (default false)\norg.slf4j.simpleLogger.showImplementationVersion=false\n# Set to true to show logging level in brackets like: [INFO] (default true)\norg.slf4j.simpleLogger.levelInBrackets=true\n# Set to true if to show current thread in output. (default false)\norg.slf4j.simpleLogger.showThreadName=false\n# Set to true if to show marker parameter values. (default false)\norg.slf4j.simpleLogger.showMarkers=false\n# Set to true to show only class name in output. (default false)\norg.slf4j.simpleLogger.showShortLogName=false\n# Set to true if to show full class name in output (package + class name). (default true)\norg.slf4j.simpleLogger.showLogName=true\n# Set maximum logger name to output and abbreviate if it exceeds length. (default null)\norg.slf4j.simpleLogger.logNameLength=36\n# Set logger output charset to use (default UTF-8)\norg.slf4j.simpleLogger.charset=UTF-8\n# Set environment names to show in output. Envs will be printed out in order they preserve in configuration. (default null)\norg.slf4j.simpleLogger.environments=SESSION_ID,ORIGIN,HOST\n# Set to true to show environment with nullable values. (default false)\norg.slf4j.simpleLogger.environmentShowNullable=false\n# Set to true to show environment names. (default false)\norg.slf4j.simpleLogger.environmentShowName=false\n# Set to true to caches environment values on configuration initialization and then always uses them when logging. (default false)\norg.slf4j.simpleLogger.environmentRememberOnStart=false\n# Set default logger output file or System.out or System.error (default System.out)\norg.slf4j.simpleLogger.logFile=System.out\n# Set logger WARN logs output file or System.out or System.error (default System.out)\norg.slf4j.simpleLogger.logFileWarn=System.out\n# Set logger ERROR logs output file or System.out or System.error (default System.out)\norg.slf4j.simpleLogger.logFileError=System.out\n\n\n# Set log level for custom loggers\norg.slf4j.simpleLogger.log.path.to.class=WARN\n```\n\n## SLF4J Compatability\n\nStarting from version *2.0.0* library ships for [SLF4J 2.0.0+](https://www.slf4j.org/manual.html). (Based on SLF4J 2.0.7+)\n\nStarting from version *1.0.0* library ships for [SLF4J 1.7.5+](https://www.slf4j.org/manual.html). (Based on SLF4J 1.7.36+)\n\n## License\n\nThis project licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodforgod%2Fslf4j-simple-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodforgod%2Fslf4j-simple-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodforgod%2Fslf4j-simple-logger/lists"}