init
This commit is contained in:
		
						commit
						797dfb02aa
					
				
							
								
								
									
										42
									
								
								index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								index.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,42 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					var colors = require('colors') // require后,字符串被添加了一系列方法: str.white, str.inverse, ...
 | 
				
			||||||
 | 
					// colors.styles: bold,italic,underline,inverse,yellow,cyan,white,magenta,green,red,grey,blue,rainbow,zebra,random
 | 
				
			||||||
 | 
					// 自定义的 themes:
 | 
				
			||||||
 | 
					colors.setTheme({
 | 
				
			||||||
 | 
					  logprompt: 'inverse',
 | 
				
			||||||
 | 
					  logok:'green',
 | 
				
			||||||
 | 
					  logerror: 'red',
 | 
				
			||||||
 | 
					  logwarn: 'magenta',
 | 
				
			||||||
 | 
					  logtitle: 'cyan'
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const bunyan = require('bunyan')
 | 
				
			||||||
 | 
					const PrettyStream = require('bunyan-pretty-colors')
 | 
				
			||||||
 | 
					const path = require('path')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var prettyStdOut = new PrettyStream()
 | 
				
			||||||
 | 
					prettyStdOut.pipe(process.stdout)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var logger = function (option) {
 | 
				
			||||||
 | 
					  option = option || {}
 | 
				
			||||||
 | 
					  return bunyan.createLogger({
 | 
				
			||||||
 | 
					    name: "log", 
 | 
				
			||||||
 | 
					    src: false,
 | 
				
			||||||
 | 
					    streams: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        level: 'info',
 | 
				
			||||||
 | 
					        stream: prettyStdOut
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        level: 'info',
 | 
				
			||||||
 | 
					        type: 'rotating-file',
 | 
				
			||||||
 | 
					        path: path.join(option.root || 'data.log/', '/', option.file || 'info.log'),
 | 
				
			||||||
 | 
					        period: '1d',   // daily rotation
 | 
				
			||||||
 | 
					        count: 30       // keep 30 days
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports=logger // trace, debug, info, warn, error, fatal
 | 
				
			||||||
							
								
								
									
										14
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "name": "so.base",
 | 
				
			||||||
 | 
					  "version": "0.1.0",
 | 
				
			||||||
 | 
					  "private": true,
 | 
				
			||||||
 | 
					  "dependencies": {
 | 
				
			||||||
 | 
					    "bunyan": "^1.8.12",
 | 
				
			||||||
 | 
					    "bunyan-pretty-colors": "^0.1.7"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "devDependencies": {},
 | 
				
			||||||
 | 
					  "scripts": {
 | 
				
			||||||
 | 
					    "setup": "npm install"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "author": ""
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user