All Projects → vbauer → herald

vbauer / herald

Licence: Apache-2.0 license
Log annotation for logging frameworks

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to herald

liquibase-slf4j
Liquibase SLF4J Logger.
Stars: ✭ 42 (-40.85%)
Mutual labels:  slf4j, log4j, logback, logger
Sofa Common Tools
sofa-common-tools is a library that provide some utility functions to other SOFA libraries.
Stars: ✭ 141 (+98.59%)
Mutual labels:  slf4j, logback
Kotlin Inline Logger
A logger facilitating lazily-evaluated log calls via Kotlin's inline classes & functions.
Stars: ✭ 77 (+8.45%)
Mutual labels:  slf4j, logger
Stubbornjava
Unconventional Java code for building web servers / services without a framework. Think dropwizard but as a seed project instead of a framework. If this project had a theme it would be break the rules but be mindful of your decisions.
Stars: ✭ 184 (+159.15%)
Mutual labels:  slf4j, logback
Izumi
Productivity-oriented collection of lightweight fancy stuff for Scala toolchain
Stars: ✭ 423 (+495.77%)
Mutual labels:  slf4j, logger
Scala Logging
Convenient and performant logging library for Scala wrapping SLF4J.
Stars: ✭ 804 (+1032.39%)
Mutual labels:  slf4j, logback
Finatra
Fast, testable, Scala services built on TwitterServer and Finagle
Stars: ✭ 2,126 (+2894.37%)
Mutual labels:  slf4j, guice
jcabi-log
Static Wrapper of SLF4J easing you from the necessity to create static LOGGER instances in each Java class
Stars: ✭ 53 (-25.35%)
Mutual labels:  slf4j, logger
LogDNA-Android-Client
Android client for LogDNA
Stars: ✭ 22 (-69.01%)
Mutual labels:  logger, logs
logback-access-spring-boot-starter
Spring Boot Starter for Logback-access.
Stars: ✭ 153 (+115.49%)
Mutual labels:  logback, logger
logops
Really simple and performant logger for node projects compatible with any kind of deployments as your server operations/environment defined
Stars: ✭ 20 (-71.83%)
Mutual labels:  logger, logs
Tinylog
tinylog is a lightweight logging framework for Java, Kotlin, Scala, and Android
Stars: ✭ 360 (+407.04%)
Mutual labels:  slf4j, logger
Scribe
The fastest logging library in the world. Built from scratch in Scala and programmatically configurable.
Stars: ✭ 304 (+328.17%)
Mutual labels:  slf4j, logback
Testlogcollectors
A framework for capturing log statements during tests. Compatible with most popular logging frameworks. Works with JUnit and TestNG
Stars: ✭ 31 (-56.34%)
Mutual labels:  slf4j, logs
echopraxia
Java Logging API with clean and simple structured logging and conditional & contextual features. JSON implementations in Logback and Log4J.
Stars: ✭ 37 (-47.89%)
Mutual labels:  slf4j, logback
Terse Logback
Structured Logging, Tracing, and Observability with Logback
Stars: ✭ 146 (+105.63%)
Mutual labels:  slf4j, logback
telegram-log
Send a Telegram message when your scripts fire an exception or when they finish their execution.
Stars: ✭ 16 (-77.46%)
Mutual labels:  log4j, logger
logunit
A Java library for unit-testing logging.
Stars: ✭ 40 (-43.66%)
Mutual labels:  slf4j, logback
loggers
Abstract logging for Golang projects. A kind of log4go in the spirit of log4j
Stars: ✭ 17 (-76.06%)
Mutual labels:  log4j, logger
slf4j-timber
SLF4J binding for Jake Wharton's Timber Android logging library
Stars: ✭ 44 (-38.03%)
Mutual labels:  slf4j, log4j

Herald

Android Arsenal Build Status Coverage Status Maven Codacy Badge

"Why, sometimes I've believed as many as six impossible things before breakfast." - Lewis Carroll, Alice in Wonderland.

Herald provides a very simple way to initialize logger objects and does all magic for you. You can annotate any field of some class with a @Log annotation to let Herald inject suitable logger in this field. It does not matter whether it is a static field or not.

Just forget about this code:

private static final Logger LOGGER =
    LoggerFactory.getLogger(Foo.class);

Write less code, use short form:

@Log
private Logger logger;

Online documentation:

Main features

Supported logging frameworks

It is also possible to add other logging frameworks:

  • Create new class in your project, it should implement interface com.github.vbauer.herald.logger.LogFactory. Add all necessary logic about logger creation in this class.
  • Create ServiceLoader's file in your project: "META-INF/services/com.github.vbauer.herald.logger.LogFactory".
  • Add full class name of your new extension in this file.

That's all!

Setup

Maven:

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

<dependency>
    <groupId>com.github.vbauer</groupId>
    <artifactId>herald</artifactId>
    <version>1.2.3</version>
</dependency>

Gradle:

repositories {
    maven {
        url "https://jitpack.io"
    }
}

dependencies {
    compile 'com.github.vbauer:herald:1.2.3'
}

Configuration

Java configuration

The project is integrated with Spring & Guice frameworks, but can be used without it:

LoggerInjector.inject(bean);

// or even using varargs:
LoggerInjector.inject(bean1, bean2, bean3);

As you can see, it is unnecessary to do some specific configuration when you use it in Java without IOC container.

Android configuration

You need to create base class for your component (ex: Activity) and call LoggerInjector.inject:

public class BaseActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LoggerInjector.inject(this);
    }
}

Guice / RoboGuice configuration

Herald contains specific Guice module to support @Log annotation (com.github.vbauer.herald.ext.guice.LogModule):

final Injector injector = Guice.createInjector(new LogModule());

Now, all your beans will be processed with LoggerInjector and logger fields will be initialized if necessary.

Spring configuration

Java based configuration

You need to configure only one BeanPostProcessor:

@Configuration
public class AppContext {

    @Bean
    public LogBeanPostProcessor logBeanPostProcessor() {
        return new LogBeanPostProcessor();
    }

}

XML Schema-based configuration

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean class="com.github.vbauer.herald.ext.spring.LogBeanPostProcessor" />

</beans>

Spring Boot support

Herald has out of the box integration with Spring Boot. You do not need to define LogBeanPostProcessor in your application context. Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added.

See LogAutoConfiguration for more details.

@Log annotation

You can use @Log annotation in 2 ways:

  • Put it on class - All suitable logger fields will be injected. Validation check will be switched off, so all undefined logger fields will be skipped.
  • Put it on field - It allows you to inject only suitable logger and throws MissedLogFactoryException otherwise.

It is also possible to configure logger name using this annotation:

@Log("MyCustomLoggerName")
private Logger logger;

If you do not specify it, then class name will be used as logger name.

If you want to specify mandatory for logger instantiation, use required parameter (default is true). Use @Log(required = false) to make your logger object optional (it could be useful in some rare cases).

FAQ

  • Q: How to select protocol for Syslog4j?
    • A: Use @Log.name(), default protocol is "udp".
  • Q: How to configure Syslog4j with Herald?
    • A: Use standard Syslog4j API, ex:
    final SyslogIF syslog = Syslog.getInstance("udp");
    syslog.getConfig().setHost("192.168.100.1");
    syslog.getConfig().setPort(1514);

Development

To build project in strict mode with tests, you can run:

mvn -P strict clean package

Might also like

  • jconditions - Extra conditional annotations for JUnit.
  • jackdaw - Java Annotation Processor which allows to simplify development.
  • houdini - Type conversion system for Java projects.
  • caesar - Library that allows to create async beans from sync beans.
  • commons-vfs2-cifs - SMB/CIFS provider for Commons VFS.
  • avconv4java - Java interface to avconv tool.

License

Copyright 2015 Vladislav Bauer

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

See LICENSE file for more details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].