程序员记录每天工作日志软件_程序员日志记录简介
程序員記錄每天工作日志軟件
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.
在軟件開發(fā)中,并非所有開發(fā)人員都非常重視。 那部分是正確的日志記錄,每個(gè)在調(diào)試過程中浪費(fèi)了無數(shù)小時(shí)的人都知道我的意思。
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.
有用的日志可以為開發(fā)人員(尤其是在必須調(diào)試/維護(hù)他人代碼的情況下)提供了巨大的幫助,可幫助他們理解代碼的實(shí)際功能。 一些開發(fā)人員說,堆棧跟蹤是某人應(yīng)有的全部需求,但事實(shí)并非如此。 堆棧跟蹤很不錯(cuò),可以告訴您哪里出了什么問題以及出了什么問題,但是它們并不能告訴您如何到達(dá)那里。 當(dāng)然,您可以在斷點(diǎn)處跟蹤執(zhí)行,但是盲目地進(jìn)行會(huì)使整個(gè)過程比實(shí)際應(yīng)該甚至可能要花費(fèi)更多的時(shí)間。
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.
那是日志的診斷部分,是最重要的部分,基本上也是開發(fā)人員可以更容易理解的部分,因?yàn)樗侨粘9ぷ鞯囊徊糠帧?還有另一部分稱為審核日志記錄。 診斷日志記錄負(fù)責(zé)記錄運(yùn)行時(shí)發(fā)生的事件(方法調(diào)用,輸入/輸出,HTTP調(diào)用,SQL執(zhí)行),而審核日志記錄則負(fù)責(zé)記錄更多抽象的業(yè)務(wù)邏輯事件。 此類事件可以是用戶操作(添加,編輯/刪除內(nèi)容,交易,訪問數(shù)據(jù))或具有管理價(jià)值或更重要的是法律價(jià)值的其他事物。
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.
在后端世界中,有一些很棒的日志記錄框架可供選擇,因?yàn)閷?duì)它們的需求早就出現(xiàn)了。 例如,在Java中,您可以在Java自己的日志記錄引擎,java.util.logging或一些出色的外部框架(例如Logback或最受歡迎的Log4j)之間進(jìn)行選擇,在前端世界中,事情還沒那么遠(yuǎn),但是有一些選項(xiàng)可以幫助您加倍努力(當(dāng)然也可以擺脫平凡的console.log消息)。 前端的兩個(gè)這樣的Javascript庫是最小但功能強(qiáng)大的日志級(jí)別,以及browser-bunyan,bunyan是很棒的node.js日志模塊的端口,用于瀏覽器。 這些框架之間有一些共同點(diǎn),但有一些獨(dú)特之處應(yīng)指導(dǎo)開發(fā)人員選擇所需的框架。 可以通過一些示例來說明這些用法。
Manifesto: Server logs should be structured. JSON’s a good format. Let’s do that.宣言:服務(wù)器日志應(yīng)結(jié)構(gòu)化。 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宣言所言,日志應(yīng)結(jié)構(gòu)化并易于索引,過濾和搜索。 這個(gè)很棒的框架以JSON格式生成日志,然后其他服務(wù)可以輕松使用該日志以進(jìn)行進(jìn)一步處理。
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導(dǎo)出功能外, Bunyan還具有子記錄器的概念,該子記錄器可用于為應(yīng)用程序的不同組件創(chuàng)建不同的記錄器。 這樣,您就可以僅在應(yīng)用程序的特定部分中包含哪些字段和額外信息,從而具有極大的靈活性。 Bunyan還合并了流,這是其記錄器的“輸出”設(shè)置。 您可以創(chuàng)建多個(gè)流,并為每個(gè)記錄器分配一個(gè)或多個(gè)礦石,并且每個(gè)流可以具有不同的設(shè)置,例如要記錄的最低日志級(jí)別(可接受的Bunyan級(jí)別是致命/錯(cuò)誤/警告/信息/調(diào)試/跟蹤)或輸出方法(在瀏覽器中,只有控制臺(tái)相關(guān)的選項(xiàng),但是,在Node環(huán)境中,您可以執(zhí)行其他操作,例如將日志寫入特定文件)。
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這是準(zhǔn)系統(tǒng)可靠的日常日志記錄庫。 它沒有做任何花哨的事情,它不允許您重新配置附加程序或添加復(fù)雜的日志過濾規(guī)則或煮茶(更可惜),但是它確實(shí)具有您實(shí)際使用的所有核心功能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.
日志級(jí)別非常適度,它為自己提供了一個(gè)最小的日志框架,該框架僅增加了大多數(shù)應(yīng)用程序所需的最低限度。 它添加了一些適當(dāng)?shù)幕诩?jí)別的日志記錄(trace / debug / info / warn / error),并過濾了要在控制臺(tái)上顯示的最低級(jí)別。
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.
該框架的強(qiáng)大之處在于其簡單性,因?yàn)閷⑵浜喜⒌侥捻?xiàng)目中并開始使用它非常容易,永遠(yuǎn)替換了console.log()。 此外,loglevel還有一個(gè)隱藏的gem,即它的可擴(kuò)展性,因?yàn)闉榇司帉懥烁鞣N插件,這些插件為想要它們的人提供了額外的功能,例如給消息加上前綴 。
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應(yīng)用程序選擇哪種框架,都可以確保在調(diào)試過程中節(jié)省大量的工作時(shí)間,并使應(yīng)用程序更具前瞻性。
翻譯自: https://www.freecodecamp.org/news/you-should-have-better-logging-now-fbab2f667fac/
程序員記錄每天工作日志軟件
總結(jié)
以上是生活随笔為你收集整理的程序员记录每天工作日志软件_程序员日志记录简介的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端学习(3305):函数组件userm
- 下一篇: 【交叉/综合/新兴】 2019年-中国