Skip to content
Really simple, ultra fast and light weight Java logging module
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
img
.gitignore
LICENSE.md
README.md
mblogging-1.2.2.jar

README.md

MBLogging

Really simple, ultra fast and light weight Java logging module.

About

MBLogging module was created in alternative to standard Java logging library for small/medium projects that do not need big logging libraries like Log4j. Module is compiled as normal jar file so it is really easy to implement in any Java project. Weight of the MBLogging is 15KB only. There is native support for colorful logs output as you can see on the images above. Every aspect of log format is easily configurable. Logger can work in one of four hierarchic levels:

  • INFO - default level for production (default console colors)

  • DEBUG - level that needs to be set, ideal for debugging (green color near DEBUG label)

  • WARNING - level for warning messages (yellow color, visible on INFO level)

  • ERROR - level for errors and exceptions (red color, visible on INFO level)

Note that some terminals do not support ANSI colors, so it is recommended to change output mode of logger before project production process.

Download latest version

Latest version of MBLogging module can be found on GitHub releases section.

Getting started

package some.weird.package;

import net.bedra.maciej.mblogging.Logger;

public class Main {

	public static void main(String[] args) {
		Logger log = Logger.getLogger();
		log.info("Initializing mblogging module on INFO level...");
		log.debug("Initializing mblogging module on DEBUG level...");
		log.warning("Initializing mblogging module on WARNING level...");
		log.error("Initializing mblogging module on ERROR level...");
	}

}

This simple code example shows how to use MBLogging module.

Logger is distributed as single instance class and it is synchronized so you can use it properly with multithreading.

You can also log messages with objects when more parameters are given in logger methods after comma. All markers '{}' in main log message will be replaced with method parameters.

log.info("Test {} objects printing {}, {}, {}", "of", 1, 2, 3);

Above log will print: Test of objects printing 1, 2, 3

Error level supports exceptions printing:

try {
	System.out.println(1/0);
} catch (Exception ex) {
	log.error(ex);
	log.error("Ow it is exception here:", ex);
	log.error("Ow it is exception here and a lot of objects:", ex, 1, 2, 3, 4, 5);
}

Settings

Logger uses configuration saved in java properties file named mblogging.properties. There are two ways to configure logger. Firstly library will search for configuration in Java resources if it is not there it will search in project root dir. At least library will generate configuration file in project root dir for you if it can not be found. I made it like this because you can decide if you want to give user access to logger configuration even after deploying your project as .exe file. For example, configuration in Java resources will be invisible and uneditable for standard user after deploy. Configuration in project root dir will be editable for everyone after deploy because file will be visible next to .exe file.

Default configuration file looks like this (without comments after '//'):

enabled=true // decide if logger should be enabled
level=info // chose logger level (info or debug)
output=colorful_console // chose logger output (console, colorful_console, file, console_and_file, colorful_console_and_file)
timestamp.format=dd.MM.YYYY (HH\:mm\:ss) // As shown here: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
logs.file.mode=new // chose if every single run of program should be logged to file with mode (new, append)
logs.file.dir=[System.getProperty("user.dir")] // raw path to directory where logs file should be saved
logs.filename=mblogging // name of logs file without extension

Above configuration file sample shows all available options of logger. If you have any trouble to create it properly, it can be generated automatically. Delete mblogging.properties file from project and run your program. File should be generated with default values that can be changed manually with your preferences.

Bugs and issues

If you find any bugs or issues, I will be really happy to fix them! Only one thing that you need to do is to inform me about the problem by opening an issue on GitHub issues page. It will be really helpful to see any exception thrown or stack trace or just image of the fault.

License

The MIT License (MIT)

Copyright (c) 2018 Maciej Bedra

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You can’t perform that action at this time.