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

cw-logger

v1.1.4

Published

cw-logger

Downloads

9

Readme

git repository

cw logger sample

cd sample
node test.js

How to use

Install

To install via npm

npm install cw-logger --save

Using

const config = {
	logRoot: require('path').resolve(__dirname, './logs'), // 日志根目录(需根据实际情况设置)
	logLevel: 'info', // file
	logLevel4console: 'error', // console
	bunyan: {
		// 级别分别是: TRACE DEBUG INFO WARN ERROR FATAL
		categorys: [{
				name: 'console',
				type: 'console',
				logLevel4console: 'error',
				pretty: true, // 格式化console输出日志, 方便查看
				src: true // 开启代码行定位
			},{
				name: 'app', // 模块/分类
				type: 'rotatingFile',
				pretty: true, // 格式化console输出日志, 方便查看
				src: false,
				// logLevel: 'info',
				// logLevel4console: 'error',
				rotateConfig: {
					period: '1d', // The period at which to rotate.
					threshold: '10m', // Rotate log files larger than 10 megabytes
					totalFiles: 10 //The maximum number of rotated files to keep. 0 to keep files regardless of how many there are.
				}
			},{
				name: 'login', // 模块/分类
				type: 'rotatingFile',
				pretty: true, // 格式化console输出日志, 方便查看
				// logLevel: 'info',
				// logLevel4console: 'error',
				rotateConfig: {
					period: '1d', // The period at which to rotate.
					threshold: '10m', // Rotate log files larger than 10 megabytes
					totalFiles: 0 //The maximum number of rotated files to keep. 0 to keep files regardless of how many there are.
				}
			}
		]
	}
};
const log = require('cw-logger')(config);
const myConsoleLogger = log.console;
const loginLogger = log.login;
const appLogger = log.app;

myConsoleLogger.info('info');
loginLogger.info('info');
appLogger.info('info');

myConsoleLogger.error(new Error('error myConsoleLogger'));
loginLogger.error(new Error('error loginLogger'));
appLogger.error(new Error('error appLogger'));

elk logstash suport

在测试环境配置logstash, 启用logstash收集日志 enableLogstash4console: true; 查看日志的地址elk

const name = 'cw-api-gateway'; // 根据实际情况可定义为项目名称
const config = {
	logRoot: require('path').resolve(__dirname, './logs'), // 日志根目录(需根据实际情况设置)
	logLevel: 'info', // file
	logLevel4console: 'error', // console
	bunyan: {
		// 级别分别是: TRACE DEBUG INFO WARN ERROR FATAL
		categorys: [{
				name: 'console',
				type: 'console',
				logLevel4console: 'error',
				pretty: true, // 格式化console输出日志, 方便查看
				src: true
			},{
				name: 'app', // 模块/分类
				type: 'rotatingFile',
				pretty: true, // 格式化console输出日志, 方便查看
				src: false,
				// logLevel: 'info',
				// logLevel4console: 'error',
				rotateConfig: {
					period: '1d', // The period at which to rotate.
					threshold: '10m', // Rotate log files larger than 10 megabytes
					totalFiles: 10 //The maximum number of rotated files to keep. 0 to keep files regardless of how many there are.
				}
			},{
				name: 'login', // 模块/分类
				type: 'rotatingFile',
				pretty: true, // 格式化console输出日志, 方便查看
				// logLevel: 'info',
				// logLevel4console: 'error',
				rotateConfig: {
					period: '1d', // The period at which to rotate.
					threshold: '10m', // Rotate log files larger than 10 megabytes
					totalFiles: 0 //The maximum number of rotated files to keep. 0 to keep files regardless of how many there are.
				}
			}
		]
	},
	enableLogstash4console: true, // 使用elk收集日志, 依赖enableBunyan
	currentLogstashInput: 'tcp', // tcp数据包(相比udp, 大小默认无限制)
	logstash: {
		type: name + (process.env.SITE_DOMAIN ? `-${process.env.SITE_DOMAIN}` : ''),
		udp: {
			host: '192.168.2.155',
			port: 64100,
		  type: name + (process.env.SITE_DOMAIN ? `-${process.env.SITE_DOMAIN}` : '')
		},
		tcp: {
			host: '192.168.2.155',
			port: 64756,
		  type: name + (process.env.SITE_DOMAIN ? `-${process.env.SITE_DOMAIN}` : '')
		}
	},
}

stdout suport pretty format

// 不保证性能, 建议只在开发环境开启pretty, 在生产环境关闭(或者设置logLevel4console为error以上)
// 设置pretty
{
	pretty: true // 格式化console输出日志, 方便查看
}

License

MIT.