技术控

    今日:57| 主题:49101
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Better Logging in Nodejs

[复制链接]
壹人天荒地老 发表于 2016-10-17 02:16:49
121 3

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
In this post we will be discussing about better logging in Node.js. If you are writing an application, detailed logging is required for spotting problems and debugging. Logging is an integral part of any application. A well implemented logging mechanism in the application reduces the time to identify the root cause of the problem.
  But developer should be careful on how much amount of logging should be done, thus in this post we will be going through some of the npm packages which will be helpful in reducing the amount consumed by the developer to do logging.
  Simple Logging Using Console

  The most basic kind of logging used in Node.js is to log the errors or information using the built in console. Console module can put the messages as an info or as an error as shown below :
  But it definitely does not serve our purpose for better logging because it lacks the feature of time-stamps, we cannot distinguish between the info and error and also the severity of the error cannot be distinguish.
   
Better Logging in Nodejs-1 (developer,required,detailed,problems,identify)

  Logging using NPM Modules

  There are number of modules which can help us in doing the logging right for our application. Here we will be discussing about Winston and Bunyan.
   Bunyan: As per  Bunyan , it is a simple and fast JSON logging library for nodejs services. They also have a Bunyan CLI tool for nicely viewing the logs.
   How to Use Bunyan
  Create a file named example5.js whose contents will be :
   var bunyan = require('bunyan');
   var log = bunyan.createLogger({name: 'myFirstBunyanExample'});
   log.info('1st Log using Bunyan');
   log.warn('It's just a warning');
   And then run it as node example5.js | bunyan

Better Logging in Nodejs-2 (developer,required,detailed,problems,identify)

   Winston: As per Winston ,  it is a multi-transport async logging library for node.js. Winston is designed to be a simple and universal logging library with support for multiple transports.
   How to use Winston
  Create a file name example6.js whose contents will be "
    var winston = require('winston');
    winston.log('info', 'Coding Defined Info Logger at www.CodingDefined.com');
    winston.info('Coding Defined Again Info Logger at www.CodingDefined.com');
   And then run it as node example6.js
12下一页
友荐云推荐




上一篇:[工具资源] 老司机推荐 39 个微信公众账号,助你了解码农的世界 ...
下一篇:Adversarial.AI Honeypot Turing Test
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

12138 发表于 2016-10-21 02:44:57
呵呵。。。顶顶
回复 支持 反对

使用道具 举报

湄涟 发表于 2016-11-19 23:12:05
魏渭(奇点)、谭宗明(谭总)、包奕凡(小包总)都没壹人天荒地老帅
回复 支持 反对

使用道具 举报

胡成鑫 发表于 2016-11-21 09:04:42
趁今日埋头苦干,免他日仰慕求人.
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表