Giter Site home page Giter Site logo

hyper-logger's Introduction

Hyper Logger

Simple logger for node.js without dependencies.




1 - Install

npm i @omarty13/hyper-logger --save


2 - Usage

import { HyperLogger, }                 from './index.mjs';


const logger = new HyperLogger({
	levels: [ "fatal", "error", "warn", "info", "debug", "trace", ],
	level: "trace",
	dirname: "../Logs",
	filename: "server-node.log",
	maxSize: 100 * 1024* 1024, // 100Mb
	maxFiles: 20,
});

logger.on("error", (err) => {
	console.log(err.stack);
});

// To see the log with the reason if an uncaughtException occurs
process.on('uncaughtException', (err, origin) => {
	logger.fatal(err.stack, { className: "index.mjs", funcName: "process.on('uncaughtException')", messageColors: [ "fgRed", "bright" ], data: { errName: err.name, errCode: err.code, errMessage: err.message, origin, } });
	logger.stop(() => process.exit(1));
});

logger.trace("", {
	className: "SomeClass",
	instanceName: "someInstanceName",
	funcName: 'someFunctionName',
	data: { foo: "bar", someArray: ["one", "two"] }
});

// [25-10-2022 22:50:04.975] [trace] [SomeClass::someInstanceName] someFunctionName : {"foo":"bar","someArray":["one","two"]}

logger.fatal("This is fatal message.", { className: "index.js", instanceName: "instanceName", funcName: "funcFatal()", data: { a: 1, } });
logger.error("This is error message.", { className: "index.js", instanceName: "instanceName", funcName: "funcError()", messageColors: [ "fgGreen", ], });
logger.warn("This is warn message.", { className: "index.js", instanceName: "instanceName", funcName: "funcWarn()", messageColors: [ "bgBlue", ], });
logger.info("This is info message.", { className: "index.js", instanceName: "instanceName", funcName: "funcInfo()", messageColors: [ "fgBlue", ], });
logger.debug("This is debug message.", { className: "index.js", instanceName: "instanceName", funcName: "funcDebug()", messageColors: [ "underscore", "bgGray", ], });
logger.trace("This is trace message.", { className: "index.js", instanceName: "instanceName", funcName: "funcTrace()", messageColors: [ "bright", ], });

// Call stop() to write the latest logs to a file. If no callback is passed, it will work like an async function.
logger.stop(() => process.exit());

hyper-logger's People

Contributors

omarty13 avatar

Stargazers

 avatar

Watchers

 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.