1.1.0 • Published 1 year ago

node-logtify v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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}`);
});
1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago