{"id":24901755,"url":"https://github.com/antonsjava/jalw","last_synced_at":"2025-07-26T15:11:29.826Z","repository":{"id":36378496,"uuid":"40683360","full_name":"antonsjava/jalw","owner":"antonsjava","description":"Just another logging wrapper","archived":false,"fork":false,"pushed_at":"2023-12-17T17:29:25.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-04T03:41:56.238Z","etag":null,"topics":["java","logging-library"],"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/antonsjava.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}},"created_at":"2015-08-13T21:48:54.000Z","updated_at":"2021-12-16T07:28:20.000Z","dependencies_parsed_at":"2023-12-17T18:40:21.571Z","dependency_job_id":null,"html_url":"https://github.com/antonsjava/jalw","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/antonsjava/jalw","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonsjava%2Fjalw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonsjava%2Fjalw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonsjava%2Fjalw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonsjava%2Fjalw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonsjava","download_url":"https://codeload.github.com/antonsjava/jalw/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonsjava%2Fjalw/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267184076,"owners_count":24049127,"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","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","logging-library"],"created_at":"2025-02-01T21:17:35.661Z","updated_at":"2025-07-26T15:11:29.793Z","avatar_url":"https://github.com/antonsjava.png","language":"Java","readme":"\n# jalw\n\nJalw stands for just another logging wrapper. And this describes it's functionality.\nInstance of Jalw is lightweight wrapper over some 'real' system logging logger. \nThis logger is used for real logging. Jalw do not provide any configuration. It \nprovides only API.\n\n## Motivation\n\nMany projects uses many different logging frameworks. Slf4j comes with idea how to \nunify this. But if you miss some trace logging functionality maybe Jalw helps you. \n\nI like to log trace information about method name and method input params. It is \npossible to configure some logging systems to provide this information - but is it \nslow and it is not possible to use it in production environments. \n\nOther way is to provide method name in each 'log' statement. \n```\n  log.debug(\"::methodName - this is real log message\");\n```\nBut it requires some extra effort and it makes copy/paste anti-pattern more \ncomplicated. When you copy part of the code - you must rename the method also \nin log statements.\n\n\n## Main features\n\nJalw helps you with following things.\n\n - Simplify adding method name information to each log statement. Method \n   name should be provided only once.\n - Provides execution time to each log statement. It simplify finding slow \n   methods.\n - Provides API for formating log messages independent from real logging API \n   used. So you can use your ussual log formatting also in projects where you \n   cannot use logging API you want. \n - Allows you (in limited way) to log messages, which was not logged before \n   because log level was not allowed. It is usefull in case of some unexpected \n   exceptions.\n - allows you to throws RuntimeException when some method input condition is \n   reached.\n\n\n## Wrapping\n\nJalw requires some real logging API for logging. Like Slf4j or ...\nYou can simply write your own wrapper over your logging API. Jalw brings \nJalwLogger interface, which abstracts the logging API. It requires two method \nfor each log level \n\n - boolean isXXXEnabled() - which returns true if level XXX is opened for logging.\n - void XXX(String message) - which logs message to XXX level\n\nIt simplifies requiremets om logging API, but force Jalw to format logged \nmessages to string form. \n\nJalw defines following levels of logging\n\n - trace\n - debug\n - info\n - warn\n - error\n - fatal\n\nAll this levels must be somehow mapped to real logging system using instance of \nJalwLogger and it is provided to Jalw for real logging. \n\nThe Jalw provides several implementations for other logging systems. You can use them \ndirectly or as example for your own implementation \n - SystemOutJalw https://github.com/antonsjava/jalw/blob/master/src/main/java/sk/antons/jalw/SystemOutJalw.java\n - CommonsJalw https://github.com/antonsjava/jalw/blob/master/src/main/java/sk/antons/jalw/CommonsJalw.java\n - SdkJalw https://github.com/antonsjava/jalw/blob/master/src/main/java/sk/antons/jalw/SdkJalw.java \n - Log4j12Jalw (not provided anymore) https://github.com/antonsjava/jalw/blob/master/src/main/java/sk/antons/jalw/Log4j12Jalw.java \n(See maven chapter for dependence issues)\n\nAll Implementations brings JalwLogger implementation and one factory method for creation Jalw instances.\n\n\n## Tracing\n\nTo trace method info it is necessary to provide method name to Jalw. You can log start of the method \nand of the method in following way\n```java\n  Logger logger = Logger.getLogger(MyClass.class);\n  ...\n  private void aMethod(String text, int level) {\n    Jalw jalw = SdkJalw.jalw(logger).start(\"aMethod\", text, level);\n    if(text == null) {\n      jalw.end(\"The text param is empty\");\n      return;\n    }\n  ...\n    jalw.end();\n  }\n```\nIt produces trace output like \n```\n  \u003e- aMethod [The text param value] [1]  {aMethod - ms: 0}\n  \u003c- aMethod {aMethod - ms: 0}\n```\nor like\n```\n  \u003e- aMethod [null] [1]  {aMethod - ms: 0}\n  \u003c- aMethod [The text param is empty] {aMethod - ms: 0}\n```\nSo you can see start and end of the method execution in log file.\n\nYou can see text '{aMethod - ms: 0}' in each Jalw log statement automatically so \nit is not necessary to put method name there explicitly. You can find there also \ntime from Jalw instance creation to execution of log statement. You can find slow\nmethods by some log file searching. \n\n\n## Logging\n\nFor each level you can use several ways for logging. You can use which one you want\nProvided examples are for debug level, but it is same for all levels. \n\nYou can ask if logging is enabled\n```java\n  if(jalw.debug()) {\n  ...\n  }  \n```\nYou can log simple strings or any object toString().\n```java\n  jalw.debug(\"simple string\");\n  jalw.debug(aVariable);\n```\nYou can log stack trace of exception or limited stack trace\n```java\n  jalw.debug(anException);\n  jalw.debug(anException, 3);\n```\nYou can log formated message using Slf4j format\n```java\n  jalw.debug(\"parameter text: {}, parameter index: {}\". text, index);\n```\nYou can log formated message using printf format\n```java\n  jalw.debugf(\"parameter text: %s, parameter index: %d\". text, index);\n```\nYou can log formated message using append like format\n```java\n  jalw.toDebug().a(\"parameter text: \").a(text).a(\" parameter index: \").a(index).log();\n```\n\n## History\n\nin some cases you want to log messages even they are actually not allowed to \nlog out. For example you receive exception, you see it in log file because it is logged \nto error level, but you like to know input parameter of method, but it is logged to \ntrace which was actually not allowed to log. \n\nJalw stores some limited buffer of messages and allows you to print them to other level \nwhen it was originally logged. Following example shows such usage.\n```java\n  } catch (Exception e) {\n     jalw.historyToError();\n     jalw.error(\"Something strange happens\").error(e);\n  }\n```\nThere is 50 message budffer enabled for each Jalw instance by default. You can change it in \nfollowing way\n```java\n      Jalw jalw = SdkJalw.jalw(logger).withoutHistory().start(\"aMethod\"); // no history\n      Jalw jalw = SdkJalw.jalw(logger).withHistory(100).start(\"aMethod\"); // change limit\n```\nIf message was not logged because it was not enabled the messages are formated in time of \nlogging the history. So all abjects are printed in state as they are in history log time. \nSo history can differ from state as if it was logged normally.\n\n## Thread context\n\nIn some cases you want to 'store' some traces of execution flow in thread. it is usefull \nwhen you have code with direct request processing. You can determine start of processing \nfor context cleaning. And when you store some 'key' informations usefull for debugging \napplication. \n\nThis information is then prointed in historyToError methods or you can process it by your \nown way.\n\nFor example you have some REST API interface where you obtain some id of modified object\nSo you clean context store this information\n```java\n  jalw.contextClean();\n  jalw.context(\"REST update.{}\", path);\n```\nIn other method you can map path to tech {db} id of object to be modified\n```java\n  jalw.context(\"DB content id: {}\", object.getId());\n```\nThen in your exception handling code You van obtain previous information in you debug log.\n```java\n  } catch (Exception e) {\n     jalw.historyToError();\n  }\n```\nOr you can priunt it by yourself.\n```java\n  jalw.info(\"traces: {}\", jalw.contextString());\n```\n\n\n## Input condition check \n\nIf you like to check method input condition and throw an exception and you don;t mind that \nit is IllegalStateException. you can use something like\n```java\n  jalw.checkEmpty(list).a(\"The input list is empty.\").error(true);\n```\nThis is replacement for \n```java\n  if((list == null) || list.isEmpty()) {\n    IllegalStateException e = new IllegalStateException(\"The input list is empty.\");\n    jalw.error(e.toString());\n    jalw.error(e)\n    jalw.end()\n    throw e;\n  }\n```\n## Example\n\nI hope it is clear what Jalw brings. So if you must use any log API you don't like \nand you are familiar with Jalw API I is necessary to write only one simple class \nand use it for instantiating Jalw. \n\nThis is example for Liferay logging API\n```java\nimport com.liferay.portal.kernel.log.Log;\nimport sk.antons.jalw.Jalw;\nimport sk.antons.jalw.JalwLogger;\n\npublic class LRJalw {\n    public static Jalw jalw(Log logger) {\n        return new Jalw(new LRJalwLogger(logger));\n    }\n    \n    private static class LRJalwLogger implements JalwLogger {\n\n        private Log logger = null;\n        public LRJalwLogger(Log logger) {\n            this.logger = logger;\n        }         \n        \n        public boolean isTtraceEnabled() { return logger.isTraceEnabled(); }\n        public boolean isDebugEnabled() { return logger.isDebugEnabled(); }\n        public boolean isInfoEnabled() { return logger.isInfoEnabled(); }\n        public boolean isWarnEnabled() { return logger.isWarnEnabled(); }\n        public boolean isErrorEnabled() { return logger.isErrorEnabled(); }\n        public boolean isFatalEnabled() { return logger.isErrorEnabled(); }\n\n        public void trace(String msg) { logger.debug(msg); }\n        public void debug(String msg) { logger.debug(msg); }\n        public void info(String msg) { logger.info(msg); }\n        public void warn(String msg) { logger.warn(msg); }\n        public void error(String msg) { logger.error(msg); }\n        public void fatal(String msg) { logger.error(msg); }\n\n        \n    }\n}\n```\n\n## Maven usage\n\n```\n   \u003cdependency\u003e\n      \u003cgroupId\u003eio.github.antonsjava\u003c/groupId\u003e\n      \u003cartifactId\u003ejalw\u003c/artifactId\u003e\n      \u003cversion\u003eLASTVERSION\u003c/version\u003e\n   \u003c/dependency\u003e\n```\n\nJalw has implementation dependences to external libs. They are marked as provided so \nif you want to use Slf4j you must add dependency for Slf4j in your own project. To avoid \neny version problems exclude all dependences. \n\n```\n   \u003cdependency\u003e\n      \u003cgroupId\u003eio.github.antonsjava\u003c/groupId\u003e\n      \u003cartifactId\u003ejalw\u003c/artifactId\u003e\n      \u003cversion\u003eLASTVERSION\u003c/version\u003e\n      \u003cexclusions\u003e\n        \u003cexclusion\u003e\n          \u003cgroupId\u003e*\u003c/groupId\u003e\n          \u003cartifactId\u003e*\u003c/artifactId\u003e\n        \u003c/exclusion\u003e\n      \u003c/exclusions\u003e\n   \u003c/dependency\u003e\n```\n\n\n## OSGI usage (Karaf)\n\n```\n   bundle:install mvn:com.github.antonsjava/jalw/1.1\n   bundle:start com.github.antonsjava.jalw/1.1.0\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonsjava%2Fjalw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonsjava%2Fjalw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonsjava%2Fjalw/lists"}