cms_applog_models

3.0.11 • Public • Published

#This Beta Test Please Skip

Applog V3 Model

Version 3

Install

npm i cms_applog_models

Version < 3

See this link click

How to use

Normal

applog.js

const { ApplogModel } = require('cms_applog_models');
let logOptions = {
    filename:'applogTest.log',
    maxLogSize:10000, // max size of log file
    backups:3 // num of backup file
}

let ApplogConfig = {
    self_system: 'test',
    self_group: 'test',
    self_type: 'test'
}

let mode = 'normal' 

exports.Log = class extends LogBeats{
    constructor(){
        super(ApplogConfig,logOptions,mode);
    }
}

test.js

const { Log } = require('./applog');
let applog = new Log();
applog.setMessage('Test')
    .setRequest({ code: 200, message: 'success' })
    .setEnvironment('local')
    .setSelfFunction('test')
    .sendIgnoreResponse(1);

Middleware

applog.js

const { createMiddlewareBeats } = require('cms_applog_models');
let logOptions = {
    filename:'applogTest.log',
    maxLogSize:10000, // max size of log file
    backups:3 // num of backup file
}
let ApplogConfig = {
    self_system: 'test',
    self_group: 'test',
    self_type: 'test'
}

let mode = 'loadtest'
exports.logMiddleware = createMiddlewareBeats(ApplogConfig,logOptions,mode);

index.js

const express = require('express');
const app = express();
const { logMiddleware } = require('./applog');

app.get('/test',logMiddleware,(req,res)=>{
    setTimeout(() => {
        res.send({code:200}).saveLog('Hello')    
    }, 3000);
    
});


app.listen(3000,()=>{
   console.log('Listen on port: ' + 3000);
});

Setting

logConfig

  • filename : Log name
  • maxLogSize : Max size of log file
  • backups : Num of Backup file

ApplogConfig

  • self_system : system name
  • self_group : group of system
  • self_type : type of system

Mode

  • normal : default
  • loadtest : not send log in this mode

Change Log

Change LOG

Readme

Keywords

Package Sidebar

Install

npm i cms_applog_models

Weekly Downloads

66

Version

3.0.11

License

ISC

Unpacked Size

55.1 kB

Total Files

11

Last publish

Collaborators

  • bestwk1993