Coder Social home page Coder Social logo

niconex / slogger Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 14 KB

Simple Logger - Probably the most beautiful logging library you've ever seen.

License: GNU Lesser General Public License v2.1

Java 100.00%
java logging-library box logger logging ascii-table ascii-graphics

slogger's Introduction

slogger

Simple Logger - Probably the most beautiful logging library you've ever seen.

Back story

I had a very complex data flow to debug at work so I came up with this logging class to help me find even the most insidious bugs. I wanted a simple-to-use logging library that allowed me to build very clear log messages even from many places in the code.

Usage

Using SLogger is extremely easy. To create a log message in one place you can do like this:

SLogger.begin("myMethod")
		.field("WHEN", "Today")
		.field("LINE", "3")
		.newLine()
		.field("Nice Field", "Value")
		.line("This is just a simple line in the log")
		.print();

This will produce the following log message:

┌───────────────────────────────────────┐
│ 21-09-2020 12:40:37 - myMethod        │
├───────────────────────────────────────┤
│ WHEN: Today                           │
│ LINE: 3                               │
│                                       │
│ Nice Field: Value                     │
│ This is just a simple line in the log │
└───────────────────────────────────────┘

For a more complex case in which you want to log data from multiple functions or points in your code you can do like this:

class MyClass {
	SLogger logger;

	void calledMethod() {
		logger = logger.line("We now are in the 'calledMethod' method!")
				.field("MyExampleField", "MyExampleValue");

	}

	void myMethod() {
		logger = SLogger.begin("My Awesome Title")
				.line("We are in the 'myMethod' method!")
				.field("METHOD", "myMethod")
				.newLine();

		calledMethod();

		logger.newLine()
				.line("End of the execution.")
				.print();
	}
}

This will produce the following log message:

┌──────────────────────────────────────────┐
│ 21-09-2020 12:47:16 - My Awesome Title   │
├──────────────────────────────────────────┤
│ We are in the 'myMethod' method!         │
│ METHOD: myMethod                         │
│                                          │
│ We now are in the 'calledMethod' method! │
│ MyExampleField: MyExampleValue           │
│                                          │
│ End of the execution.                    │
└──────────────────────────────────────────┘

Optionally it can use log4j to log in production code, just use the log method instead of the print one.

slogger's People

Contributors

niconex avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.