程序员记录每天工作日志软件_程序员日志记录简介

程序员记录每天工作日志软件

by Stefanos Vardalos

由Stefanos Vardalos

程序员日志记录简介 (An introduction to logging for programmers)

There is a part of software development that not all developers take very seriously. That part is proper logging and everyone who has lost countless hours during debugging knows exactly what I mean.

在软件开发中,并非所有开发人员都非常重视。 那部分是正确的日志记录,每个在调试过程中浪费了无数小时的人都知道我的意思。

Useful logs can provide the developer ( especially when someone has to debug/maintain someone else’s code ) with tremendous help when trying to understand what the code actually does. Some developers say that stack trace is all someone should ever need but, that could not be further from the truth. Stack traces are great and can tell you where and what went wrong, but they can’t tell you how you got there in the first place. Surely you can follow execution through break points but, going in blind will make the whole process a lot more time-consuming than it actually should, and could be.

有用的日志可以为开发人员(尤其是在必须调试/维护他人代码的情况下)提供了巨大的帮助,可帮助他们理解代码的实际功能。 一些开发人员说,堆栈跟踪是某人应有的全部需求,但事实并非如此。 堆栈跟踪很不错,可以告诉您哪里出了什么问题以及出了什么问题,但是它们并不能告诉您如何到达那里。 当然,您可以在断点处跟踪执行,但是盲目地进行会使整个过程比实际应该甚至可能要花费更多的时间。

That is the diagnostic part of logging, the most important one and basically the one that developers could understand easier, as it is more part of their daily work routine. There is another part which is called audit logging. Where the diagnostic logging takes care of recording the events that happen during runtime ( method calls, input/outputs, HTTP calls, SQL executions ), the audit logging is responsible for recording more abstract, business logic events. Such events can be user actions (adding/editing/removal of content, transactions, access data) or other things that have either managerial value or, more importantly, legal value.

In the back end world, there have been some great logging frameworks to choose from as the need for those arose a lot earlier. For example in Java, you can take a pick between Java’s own logging engine, java.util.logging or some great external frameworks like Logback or the most popular Log4j.In the front end world, things haven’t gotten that far yet, but there are options that can help you do the extra mile ( and of course get rid of trivial console.log messages ). Two such Javascript libraries for the front end are the minimal but powerful loglevel and the browser-bunyan, a port of the awesome node.js logging module for the browser. Some features are common between those frameworks but there are unique ones which should guide the developer to choose which one he needs. The use of those can be shown with some examples.

在后端世界中,有一些很棒的日志记录框架可供选择,因为对它们的需求早就出现了。 例如,在Java中,您可以在Java自己的日志记录引擎,java.util.logging或一些出色的外部框架(例如Logback或最受欢迎的Log4j)之间进行选择,在前端世界中,事情还没那么远,但是有一些选项可以帮助您加倍努力(当然也可以摆脱平凡的console.log消息)。 前端的两个这样的Javascript库是最小但功能强大的日志级别,以及browser-bunyan,bunyan是很棒的node.js日志模块的端口,用于浏览器。 这些框架之间有一些共同点,但有一些独特之处应指导开发人员选择所需的框架。 可以通过一些示例来说明这些用法。

Manifesto: Server logs should be structured. JSON’s a good format. Let’s do that.

宣言:服务器日志应结构化。 JSON是一种很好的格式。 来做吧。

As original Bunyan’s manifesto goes, logs should be structured and easily indexed, filtered, searched. This awesome framework produces logs in JSON format which then can be easily consumed by other services for further processing.

正如原始的Bunyan宣言所言,日志应结构化并易于索引,过滤和搜索。 这个很棒的框架以JSON格式生成日志,然后其他服务可以轻松使用该日志以进行进一步处理。

Apart from the JSON exporting capability, Bunyan has the concept of child loggers, which can be used to create different loggers for different components of the application. That gives great flexibility as to what fields and extra info you want to include in specific parts of your application only. Bunyan also incorporates streams, which are the ‘output’ settings of its loggers. You can create multiple streams and assign one ore more to each logger and each stream can have different settings like the minimum level of logs to record ( acceptable levels of Bunyan are fatal/error/warn/info/debug/trace ) or output method ( in the browser there are only console related options but, in a Node environment you can do other things like write logs to a specific file ).

除JSON导出功能外, Bunyan还具有子记录器的概念,该子记录器可用于为应用程序的不同组件创建不同的记录器。 这样,您就可以仅在应用程序的特定部分中包含哪些字段和额外信息,从而具有极大的灵活性。 Bunyan还合并了流,这是其记录器的“输出”设置。 您可以创建多个流,并为每个记录器分配一个或多个矿石,并且每个流可以具有不同的设置,例如要记录的最低日志级别(可接受的Bunyan级别是致命/错误/警告/信息/调试/跟踪)或输出方法(在浏览器中,只有控制台相关的选项,但是,在Node环境中,您可以执行其他操作,例如将日志写入特定文件)。

This is a barebones reliable everyday logging library. It does not do fancy things, it does not let you reconfigure appenders or add complex log filtering rules or boil tea (more’s the pity), but it does have the all core functionality that you actually use

这是准系统可靠的日常日志记录库。 它没有做任何花哨的事情,它不允许您重新配置附加程序或添加复杂的日志过滤规则或煮茶(更可惜),但是它确实具有您实际使用的所有核心功能

With quite a modest statement, loglevel presents itself a minimal logging framework that adds just the bare minimum that most applications need. It adds some proper level-based logging ( trace/debug/info/warn/error ) and filtering as to what is the minimum level to be displayed on the console.

日志级别非常适度,它为自己提供了一个最小的日志框架,该框架仅增加了大多数应用程序所需的最低限度。 它添加了一些适当的基于级别的日志记录(trace / debug / info / warn / error),并过滤了要在控制台上显示的最低级别。

The power of this framework is its simplicity, as it is dead easy to incorporate it into your project and start using it, replacing the console.log() for ever. Furthermore, loglevel has one more hidden gem, its extensibility, as there are various plugins written for it, that provide extra features for those who want them, like prefixing messages.

该框架的强大之处在于其简单性,因为将其合并到您的项目中并开始使用它非常容易,永远替换了console.log()。 此外,loglevel还有一个隐藏的gem,即它的可扩展性,因为为此编写了各种插件,这些插件为想要它们的人提供了额外的功能,例如给消息加上前缀 。

Whichever framework you choose in the end for your JavaScript Application, you will save for sure a lot of hours of work during debugging and will make your application more future-proof.

最后,无论您为JavaScript应用程序选择哪种框架,都可以确保在调试过程中节省大量的工作时间,并使应用程序更具前瞻性。

翻译自: https://www.freecodecamp.org/news/you-should-have-better-logging-now-fbab2f667fac/

程序员记录每天工作日志软件

文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树首页概览92888 人正在系统学习中 相关资源:哨兵软件测试SAS/SATA硬盘软件_hbasas-Web服务器工具类资源-CSDN…

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年6月12日
下一篇 2020年6月12日

相关推荐