未加星标

Introducing a new ndjson logger with

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二04 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏
Introducing a new ndjson logger with:rocket:

Emojis are everywhere. They can be used to :mega: in a compact form or simply add some :ghost: to your message. For javascript Studio , I started using emoji in log messages to highlight :warning: and :rotating_light:, and I found that it actually adds readability. However, putting plain emoji directly into log files is not what I wanted. My preferred log file format is ndjson and I would like to have emoji as an optional UI bling :sparkles:.

So I made a tiny ndjson logger, and a CLI to format the logs :white_check_mark:. I released it as open source software under the MIT license, and this is what it looks like:


Introducing a new ndjson logger with

You can install it with npm install @studio/log -S . Read all about the API on the GitHub page.

javascript-studio/studio-log

studio-log - A tiny JSON logger with emoji support github.com

Disabled bydefault

There is no default output stream configured to prevent unwanted log output in test cases or when reusing libraries for a command line tool. Set stdout as the log destination like this:

require([email protected]/log').out(process.stdout); A different approach to loglevels

There is another fundamental difference to other log libraries: There are no log levels. Yes, no “info” or “debug” anymore. And while “warn” and “error” are a thing in @studio.log , there is no severity level associated with any of the logger functions. So why did I do that?

Whenever I used log files to trace an issue, the most important logs where the debug entries. They tend to have the relevant details about HTTP requests or configs in use. The screaming error is just where the problem surfaces, but the stack trace does not help with reproducing an issue. Therefore I never filter logs based on log levels in production environments of a server application. However, when you have a command line tool, you might want some control over what is logged and what is not. In this case, I want to mute certain types of logs, and this is what @studio/log allows me to do. I can mute logs by namespace, by topic or only a specific combination of namespace and topic.

What are namespaces andtopics?

While namespaces work like the “classic” log instance names, topics are the functions that the logger instances expose. They make the log statements a bit more expressive and the topics are mapped to emojis in the emojilog CLI to :white_check_mark: :warning: :bug: :rotating_light: :see_no_evil: :small_red_triangle: :small_red_triangle_down: :outbox_tray: :inbox_tray: :satellite: :checkered_flag: :rocket: :no_entry: :sparkles: :mega: :floppy_disk: :moneybag: :1234: and :ghost:.

const logger = require([email protected]/log'); const log = logger('app'); // "app" is the namespace

log.launch('my service', { port: 433 }); // "launch" is the topic

Why not Bunjan, Bole orPino?

I like Bunjan , Bole and Pino . They’re all great when you need a logger for a Node server application. They add the hostname and process ID by default and, in case of Bunjan, have nice built-in features for log file rotation and more. The environments I’m targeting are AWS Lambda functions and command line tools where these features have no value. Especially for Lambda functions, the size of the deployed source is important for fast cold starts. I use browserify to merge all sources into a single file and @studio/log has a minimal footprint when used like this.

If you like the project and need an advanced feature, it can be added with a custom transform stream. See the project readme for details.

:checkered_flag: Thanks for reading and happy logging.

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: GitJavaScriptJavaGitHub
分页:12
转载请注明
本文标题:Introducing a new ndjson logger with
本站链接:http://www.codesec.net/view/534218.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(42)