{"id":525,"date":"2016-01-02T22:59:08","date_gmt":"2016-01-02T20:59:08","guid":{"rendered":"http:\/\/kra.lc\/blog\/?p=525"},"modified":"2016-02-09T16:04:54","modified_gmt":"2016-02-09T14:04:54","slug":"injlog-injection-logger-for-java-8","status":"publish","type":"post","link":"https:\/\/kra.lc\/blog\/2016\/01\/injlog-injection-logger-for-java-8\/","title":{"rendered":"InjLog &#8211; Another neat Injection Logger for Java 8"},"content":{"rendered":"<p>And <a href=\"https:\/\/de.wikipedia.org\/wiki\/Michael_Jackson%E2%80%99s_This_Is_It\" target=\"_blank\"><em>This Is It<\/em><\/a> my dear visitors! Six days, six posts. This makes a total of four posts in 2015 and already two posts in 2016. <em>Great!<\/em> I am very happy to have done <a href=\"https:\/\/kra.lc\/blog\/2015\/12\/java-thread-local-servlet-cookie-filter\/\">that<\/a>, so we have some time to talk about what is going to happen in 2016.<\/p>\n<p>As already said on my <a href=\"https:\/\/kra.lc\/blog\/2016\/01\/java-betterglasspane\/\" target=\"_blank\">post yesterday<\/a>, I plan on releasing more stuff on this blog. But no false promises, if it is going to take until Christmas again, that&#8217;ll be it. But I&#8217;ll try my best to release some smaller snippets throughout the year. Other than that, I&#8217;m planning on something in the area of <em>home automation<\/em>, but I&#8217;ll get to that as well in one of my future posts. Last but not least, there is still a lot of work to do for my projects at the University of Applied Sciences in Mannheim and at my main workplace. So it&#8217;s not going to be boring year at all.<\/p>\n<p>Coming to the last release for this streak of posts. <strong>Logging in Java<\/strong> is a neverending story. There are hundrets of logging frameworks out there. <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/logging\/package-summary.html\" target=\"_blank\">Some build in<\/a> to Java, <a href=\"http:\/\/www.tinylog.org\/\"  target=\"_blank\">some smaller<\/a> or <a href=\"https:\/\/logging.apache.org\/\" target=\"_blank\">bigger<\/a> external libraries. What most of them share: <em>one<\/em> logger is shared for all classes logging data. My requirement was a little different. I had classes wanting to log data, but where and when to log data, should be decided by another class. Therefore I came up with the <a href=\"https:\/\/github.com\/kristian\/injlog\" target=\"_blank\"><strong>InjLog Logging Framework for Java<\/strong><\/a>.<!--more--><\/p>\n<p>InjLog utilizes a concept, I knew about from <em>Enterprise Java Beans<\/em> (EJB) called &#8220;dependency injection&#8221;. InjLog does not really dynamically inject loggers into other objects, but the concept is quite similar anyways. Any class can announce to log data, by implementing the <code>InjectionLogger.Injectable<\/code> interface. Any logger can then be injected into any object implementing the interface, by using the <code>InjectionLogger.injectLogger<\/code> method. The objects itself may call the <code>getLogger<\/code> method, implemented <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/java\/IandI\/defaultmethods.html\" target=\"_blank\">by default<\/a> from the <code>Injectable<\/code> interface, to receive a logger and log messages. This does work, even if no logger has been injected into the object so far. With this mechanism, each object is able to use a different logger. Some objects log to a file, while other objects log to the console, etc. And with a single class and two interfaces, the framework is very leight-weight.<\/p>\n<p>To find more examples, contribute to the development, or give feedback, feel free to check out the InjLog repository on GitHub at: <a href=\"https:\/\/github.com\/kristian\/injlog\" target=\"_blank\"><strong>https:\/\/github.com\/kristian\/injlog<\/strong><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>And This Is It my dear visitors! Six days, six posts. This makes a total of four posts in 2015 and already two posts in 2016. Great! I am very happy to have done that, so we have some time to talk about what is going to happen in 2016. As already said on my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[228,229,230,5,231,226,227],"class_list":["post-525","post","type-post","status-publish","format-standard","hentry","category-release","tag-injection","tag-injection-logger","tag-injlog","tag-java","tag-java-8","tag-log","tag-logger"],"_links":{"self":[{"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/posts\/525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/comments?post=525"}],"version-history":[{"count":27,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/posts\/525\/revisions"}],"predecessor-version":[{"id":552,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/posts\/525\/revisions\/552"}],"wp:attachment":[{"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/media?parent=525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/categories?post=525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kra.lc\/blog\/wp-json\/wp\/v2\/tags?post=525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}