Code Monkey home page Code Monkey logo

beauty-logger's Introduction

beauty-logger

[ENGLISH] | 中文

A beautiful logger system for both nodejs and browser

Tip

For browser logger, it's better to use logger-for-cannot-duplicate

Usage

const path = require('path');
const Logger = require('beauty-logger');

const logger1 = new Logger({
  logFilePath: path.join(__dirname, './server.log'),
});

const logger2 = new Logger({
  //max size of per log file, default: 10MB
  logFileSize: 1024 * 1024 * 5,
  logFilePath: {
    //log file name, default: as follows
    info: path.join(__dirname, './info.log'),
    warn: path.join(__dirname, './warn.log'),
    error: path.join(__dirname, './error.log'),
  },
  //enable data type warn, default: false
  dataTypeWarn: true,
  //disable print log in console, default: false
  productionModel: false,
  //only print log in console, default: false
  onlyPrintInConsole: false,
  //execute other beauty logger instance at the same time,default:[]
  otherBeautyLoggerInstances: [],
  //execute callback when logging, default: null
  //level: log level
  //data: log content
  //pid: process pid
  //filePath: execute log function filename
  //content: pure log content, without time and pid and etc.
  callback: (level, data, pid, filePath, content) => void,
  //count package usage to upload
  uploadPackageInfoUrl: ""
});
logger1.info('logger1', 'beauty-logger'); // [2021-12-21 16:30:18.998] [INFO] [charms-Mac-Pro.local] [3400] [lib/beauty-logger.ts:323] "logger1"   [ext] "beauty-logger"
logger2.info('logger2', 'beauty-logger'); // [2021-12-21 16:30:18.998] [INFO] [charms-Mac-Pro.local] [3400] [lib/beauty-logger.ts:323] "logger2"   [ext] "beauty-logger"

Apis

  1. logger.debug
  2. logger.info
  3. logger.warn
  4. logger.error
  5. logger.log

Test

npm run test

Functions

  1. Support user define the slice of log file size and log file path.

  2. Only logger.debug doesn't log to file, all of them can be print in console.

  3. Only identify 999 levels in input value which contains object or array.

  4. Support to print part of req and res(big object) in nodejs

  5. Data type includes Number, String, Undefined, Null, Boolean, Object, Array, Function, Error, Set, Map and Symbol can be support stringify. If something can't be stringify, it will be print data type, such as DOM element, it will print '[object HTMLDivElement]'

  6. Although we support print Function, Set, Map and Symbol directly, we still don't recommend to print it without any transfer, and it will give a warn to remind you if you set dataTypeWarn to be true.

  7. Enable productionModel will not print log to console, it will be fast for program in production environment.

  8. In default, it will log file by log level and it will log into multiple different kinds of files, if you specify logFilePath as a path string, beauty-logger will print all logs to one file.

  9. Support new multiple beauty-logger instance to log different files.

  10. All of logger method support Promise chain call

  11. Reserve data type which is in console, only stringify data which will be written to file.

  12. Only support logger.debug, logger.info, logger.warn, logger.error and logger.log

  13. Support nodejs at least 6.x

  14. support more beauty logger working at the same time and print which file execute it correctly.

  15. execute callback when logging

Preview pictures

log_example_1

License

MIT

beauty-logger's People

Contributors

zhoushoujian avatar

Watchers

 avatar

beauty-logger's Issues

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.