Herald


Source link: https://github.com/vbauer/herald

Herald

"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.

Resources

Proteus is meant to be a drop-in replacement for Android’s LayoutInflater; but unlike the compiled XML layouts bundled in the APK, Proteus inflates layouts at runtime.

With Proteus, you can control your Apps layout from the backend (no WebViews). Forget the boilerplate code to findViewById, cast it to a TextView, and then setText(). Proteus has runtime data bindings and formatters. Plugin in your own custom views and attributes and formatters.

SmartDeviceLink (SDL) is a standard set of protocols and messages that connect applications on a smartphone to a vehicle head unit. This messaging enables a consumer to interact with their application using common in-vehicle interfaces such as a touch screen display, embedded voice recognition, steering wheel controls and various vehicle knobs and buttons. There are three main components that make up the SDL ecosystem.

Simple custom ImageView for android giving you a simple way to enable overlapping of two images one over the other.

OkHttp-Stats is an android library built on top of OkHttp3, which is responsible for intercepting all the network calls and for calculating network stats such as the average network speed of the user.

This is more of an analytical tool which can be used to track the success and error response logs.

Can be plugged in to any app which uses okhttp in their networking stack.

Example app to use Protobuf in Android using Square's Wire library.

Espresso's consistency makes it really easy to learn.

Want to match a view with a specific id? Use withId(R.id.some_id). Need to match with a piece of text? Use withText(R.id.some_text) or withText("some text). Awesome, consistent and it's very clear what it is you are doing.

However...

After a few hours writing test code you'll find your code being a little bit too verbose. Not anymore.

Why should you need to explicitly specify that you are matching with some text if you are passing in some text as a parameter? Some for the view id, you can already see that it is a view id.

Ristretto allows you to write the same test code as you already write, but less verbose.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes