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

beauty-logger

v5.0.0

Published

A beautiful logger system for both nodejs and browser

Downloads

13

Readme

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