Skip to content

zdong11/xa

 
 

Repository files navigation

xa

Beautiful & Customizable log messages in your terminal ❤️

Build Status XO Code Style Unicorn

Screenshot

Installation

npm install --save xa

Usage

Default logger is usign only stdoutHandler which accepts these types of logging

  • info: (label, message)

  • loading: (label, message)

  • warn: (label, message)

  • experimental: (label, message)

  • on: (label, message)

  • off: (label, message)

  • error: (message)

Example

See example.js file.

const xa = require("xa");

xa.info("SUCCESS", "Finished converting file!");

xa.warn(
	'WARN',
	`This module is deprecated! Read more: ${xa.link('http://example.com')}`
);

Customize

xa uses chalk for colorful output, so you can customize technically every color 🦄

Handlers

Logger({
	handlers: [
		stdoutHandler({
			info: "magenta",
			error: "blue"
		})
	]
});

Handlers are functions that are called when you are logging something. You are able to use predefined one or you can create it by your own like this:

function mineHandler(options = defaultOptions) {
	return (type, label, message) => {
		switch (type) {
			case "error":
				DB.insert({
					into: "errors",
					date: new Date(),
					message,
					label
				});
				break;
			default:
				DB.insert({
					into: "logs",
					date: new Date(),
					message,
					label
				});
				break;
		}
	};
}

stdoutHandler customization

stdoutHandler accepts object with names of acceptable log methods and their display color as values.

const stdoutHandlerOptions = {
	error: "red",
	experimental: "magenta",
	info: "green",
	loading: "blue",
	off: "gray",
	on: "white",
	warn: "yellow"
};

Thanks:

License

MIT © Antoni Kepinski

About

Beautiful & Customizable logger ❤️

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%