node-logtify

1.1.0 • Public • Published

Node Logtify

disclaimer

This project is under active Development and may be unstable or contain bugs. We do not recommend using it in a production environment.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install node-logtify

API

const { nodeLogtify } = require('node-logtify')

Example

const express = require("express");
const app = express();
const { nodeLogtify, readLog } = require('node-logtify');

const PORT = 3000;

app.use(nodeLogtify);

app.use((req, res, next) => {
  setTimeout(() => {
    const dataLog = readLog()
    // Save the log to Database
    console.log('dataLog:', readLog)
  }, 500);
  next()
})

app.get('/', (req, res) => {
  return res.status(200).json('Hello World !);
});

app.listen(PORT, () => {
  console.log(`Listening on port ${PORT}`);
});

Example Log Cron

const express = require("express");
const app = express();
const cron = require('node-cron');
const { nodeCronLogtify } = require('node-logtify');

const PORT = 3000;


cron.schedule('* * * * *', () => {
    /**
     * required :
     *   1. a file for store logs, example: cron.log
     *   2. State for log, example :  Cron Running
     * 
     * if a state is object : you must convert in JSON Stringify
     * 
    **/
    nodeCronLogtify('cron.log', 'Cron Running')
    nodeCronLogtify('cron.log', JSON.stringify({message: 'Cron Running'}))

});

app.listen(PORT, () => {
  console.log(`Listening on port ${PORT}`);
});

Package Sidebar

Install

npm i node-logtify

Weekly Downloads

5

Version

1.1.0

License

ISC

Unpacked Size

6.24 kB

Total Files

5

Last publish

Collaborators

  • amilin