npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

logmyerr

v1.1.2

Published

LogMyErr plugin will handle the logging of errors, warnings and info

Downloads

21

Readme

npm version NPM Downloads PackageBuild

LogMyErr

LogMyErr JS Module enables write logs in log file or text file in server side.

Features:

  • Uses the custom log message to output information and write log to the text file of log file/ in custom extention.
  • Exception Handler allows us to handle exception from the route file in MVC.

Please report bugs there on Github.


Implementing Logger and Custom Logger

    const {logger} = require('logmyerr');
    logger.write("Hello, World");
  • logger will creates a log directory in your local folder and create it automatically create a folder log with logmyerr-dd-mm-yy.log format in base project directory

  • logger.write this methods takes different parameters.

    • message - required parameter, This takes your message or a information. type : String, default value : No
    • type - optional parameter, it can accept only the Info/error/warn/debug. type : String, default value : info
      • Example
        1. logger.LOGTYPE.info
        2. logger.LOGTYPE.error
        3. logger.LOGTYPE.warn
        4. logger.LOGTYPE.debug
     loggers.write(err.stack,loggers.LOGTYPE.info);
    • priority - optional parameter, it can accept only the critical/informative/major. type : String, default value : informative
      • Example
        1. this.PRIORITY.critical
        2. this.PRIORITY.informative
        3. this.PRIORITY.major
     loggers.write(err.stack,loggers.LOGTYPE.info, loggers.PRIORITY.informative);

OR

    const {customLogger} = require('logmyerr');
    const logger = customLogger.getInstance();
    logger.write("Hello, World");
  • In this customLogger it help us to change the default configuration.

Example

    const {customLogger} = require('logmyerr');
    let defaultConfig = {
        logFileName: "logmyerr" ,
        logFileExtension: ".log",
        logFilePath: "<Your System local path or a Custom Path>", 
        logFolderName: "logs",
        }
    const logger = customLogger.getInstance(defaultConfig);
    logger.write("Hello, World");
  • logger will creates a logs directory in custom local folder and create it automatically create a folder log with logmyerr-dd-mm-yy.log format in base project directory

  • logger.write this methods takes different parameters.

    • message - required parameter, This takes your message or a information. type : String, default value : No
    • type - optional parameter, it can accept only the Info/error/warn/debug. type : String, default value : info
      • Example
        1. logger.LOGTYPE.info
        2. logger.LOGTYPE.error
        3. logger.LOGTYPE.warn
        4. logger.LOGTYPE.debug
     loggers.write(err.stack,loggers.LOGTYPE.info);
    • priority - optional parameter, it can accept only the critical/informative/major. type : String, default value : informative - Example 1) this.PRIORITY.critical 2) this.PRIORITY.informative 3) this.PRIORITY.major
     loggers.write(err.stack,loggers.LOGTYPE.info, loggers.PRIORITY.informative);

Exception Handler Router based

If you are following MVC patter in you Application you can use this exception handler to Handle all your exception from your router. Basically It will handles the all the exception from your controller.

let  express  =  require('express');
let  router  =  express.Router();
let {exceptionHandler} =  require('logmyerr');
const  LoginController  =  require('../controllers/login.controllers');
router.post('/', exceptionHandler(LoginController.login)); 

and also it must to be implement the global exception handler in main.js file

Example

📁 app.js

var  createError  =  require('http-errors');
var  express  =  require('express');
var  path  =  require('path');
var  cookieParser  =  require('cookie-parser');
// importing DotEnv
require('dotenv').config();
let {logger} =  require('logmyerr');
let  loginRouter  =  require('./routes/login.routes');

var  app  =  express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/login', loginRouter);

app.use(function(req, res, next) {
if(process.env.NODE_ENV ===  'development'){
next(createError(404));
}else  if(process.env.NODE_ENV ===  'Perf'){
next(createError(404));
}else{
const  err  =  new  Error('Not Found');
err.status =  404;
next(err);
}
});

// error handler
app.use(function(err, req, res, next) {
if(process.env.NODE_ENV ===  'development'){
// set locals, only providing error in development
res.locals.message =  err.message;
res.locals.error =  req.app.get('env') ===  'development'  ?  err  : {};
loggers.write(err.stack,loggers.LOGTYPE.error, loggers.PRIORITY.critical);
// render the error page
res.status(err.status ||  500);
res.json({
message: err.message,
});
}
else{
res.status (err.status ||  500);
loggers.write(err.stack,loggers.LOGTYPE.error, loggers.PRIORITY.critical);
res.json({
error: {
message: "Internal Server Error"
}
});
}
});
module.exports  =  app;

📶 router.js

let  express  =  require('express');
let  router  =  express.Router();
let {exceptionHandler} =  require('logmyerr');
const  LoginController  =  require('../controllers/login.controllers');
router.post('/', exceptionHandler(LoginController.login));

🎮 Controller.js

const  LoginController  = {}
LoginController.login  = (req, res) => {
	throw  new  Error("Dummy Exception");
}

License

MIT