程序员记录每天工作日志软件_程序员日志记录简介
程序員記錄每天工作日志軟件
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.
那是日志的診斷部分,是最重要的部分,基本上也是開發人員可以更容易理解的部分,因為它是日常工作的一部分。 還有另一部分稱為審核日志記錄。 診斷日志記錄負責記錄運行時發生的事件(方法調用,輸入/輸出,HTTP調用,SQL執行),而審核日志記錄則負責記錄更多抽象的業務邏輯事件。 此類事件可以是用戶操作(添加,編輯/刪除內容,交易,訪問數據)或具有管理價值或更重要的是法律價值的其他事物。
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/
程序員記錄每天工作日志軟件
總結
以上是生活随笔為你收集整理的程序员记录每天工作日志软件_程序员日志记录简介的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端学习(3305):函数组件userm
- 下一篇: 前端学习(3132):react-hel