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

think-logger3

v1.4.0

Published

logger for ThinkJS 3.x

Downloads

2,808

Readme

think-logger

npm Travis Coveralls David

ThinkJS3.x log module, based on log4js.

Installation

npm install think-logger3

How To Use

Basic

const Logger = require('think-logger3');
const logger = new Logger();
logger.debug('Hello World');

There has four log function you can use:

logger.info('info log');
logger.debug('debug log');
logger.warn('warn log');
logger.error('error log');

Advanced

If you want to log file, you can use file adapter like this:

const Logger = require('think-logger3');
const logger = new Logger({
   handle: Logger.File,
   filename: __dirname + '/test.log'
});
logger.debug('Hello World');

Adapters

File

This adapter will log to a file, and supports split log file by a constant file size. For example:

const Logger = require('think-logger3');
const logger = new Logger({
  handle: Logger.File,
  filename: __dirname + '/debug.log',
  maxLogSize: 50 * 1024,  //50M
  backups: 10 //max chunk number
})

Then initial log would create a file called debug.log. After this file reached maxLogSize, a new file named debug.log.1 will be created. After log file number reached backups, old log chunk file will be removed.

Configuration

  • filename: log filename
  • maxLogSize: The maximum size (in bytes) for a log file, if not provided then logs won't be rotated.
  • backups: The number of log files to keep after logSize has been reached (default 5)
  • absolute: If filename is a absolute path, the absolute value should be true.
  • layout: Layout defines the way how a log record is rendered. More layouts can see here.

DateFile

This adapter will log to a file, moving old log messages to timestamped files according to a specified pattern. For example:

const Logger = require('think-logger3');
const logger = new Logger({
  handle: Logger.DateFile,
  filename: __dirname + '/debug.log',
  pattern: '-yyyy-MM-dd',
  alwaysIncludePattern: false
});

Then initial log would create a file called debug.log. At midnight, the current debug.log file would be rename to debug.log-2017-03-12(for example), and a new debug.log file created.

Configuration

  • level: log level
  • filename: log base filename
  • pattern: date filename would append to filename. A new file is started whenever the pattern for the current log entry differs from that of the previous log entry. The following strings are recognised in the pattern:
    • yyyy - the full year, use yy for just the last two digits
    • MM - the month
    • dd - the day of the month
    • hh - the hour of the day (24-hour clock)
    • mm - the minute of the hour
    • ss - seconds
    • SSS - milliseconds (although I'm not sure you'd want to roll your logs every millisecond)
    • O - timezone (capital letter o)
  • alwaysIncludePattern: If alwaysIncludePattern is true, then the initial file will be filename.2017-03-12 and no renaming will occur at midnight, but a new file will be written to with the name filename.2017-03-13.
  • absolute: If filename is a absolute path, the absolute value should be true.
  • layout: Layout defines the way how a log record is rendered. More layouts can see here.

Basic

If those adapter configuration can't satisfy your need, you can use this adapter and set config like log4js. For example:

const Logger = require('think-logger3');
const logger = new Logger({
  handle: Logger.Basic,
  appenders: {
    everything: { type: 'file', filename: 'all-the-logs.log' },
    emergencies: {  type: 'file', filename: 'oh-no-not-again.log' },
    'just-errors': { type: 'logLevelFilter', appender: 'emergencies', level: 'error' }
  },
  categories: {
    default: { appenders: ['just-errors', 'everything'], level: 'debug' }
  }
});

All properties are as same as log4js except handle property. You can see more configure properties on log4js documentation.

Contributing

Contributions welcome!

License

MIT