Skip to Content
持續交付|使用Java
book

持續交付|使用Java

by Daniel Bryant, Abraham Marín-Pérez
July 2019
Intermediate to advanced
480 pages
9h 35m
Chinese
GoTop Information, Inc.
Content preview from 持續交付|使用Java
384
| 第十三章
我們建議在盡可能高的級別(最接近呼叫或用戶發起的操作)上面 log 錯誤。試著在呼
叫堆疊中多次 log 單一錯誤經常在 log 中加入雜訊,讓你難以追蹤問題。
防範“過度
log
log 級別真正強大之處在於,它們可讓你在部署或運行期修改 log 的數
量。例如,如果 app 沒有按照預期執行,運維人員可以啟用更精細的 log
級別,例如
DEBUG
,以獲得更多的資訊。但是,產生額外的 dubug 問題會
降低性能,諷刺的是,當你開始尋找問題時,很多問題就會消失,原因通
常是時機(timing)和記憶體的使用模式會隨著額外的 log 而改變,我們
也看過一個 app 在啟用 log 時完全崩潰,因為它在生產環境中產生 log
句需要極大量的記憶體(相關的
TRACE
敘句一直以來都只在嚴格控制下的
開發環境中使用,而且資料量很少)。
Java 生態系統有好幾種 log 框架可供你選擇。接下來要介紹兩種最熱門的:SLF4J(與
Logback)以及 Log4j 2
別發明自己的
logger
請不要試著實作你自己的 log 框架,或採取同樣糟糕的做法,直接使用
System.out.println
。現代的 Java log 框架已經有了高度的發展,相較於
直接將細節 echo 到控制台(在容器環境中可能存在,也可能不存在),
它們提供了更多的彈性。
SLF4J
Simple Logging Facade for JavaSLF4J)(
https://www.slf4j.org/
)旨在提供各種
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

精實企業|高績效組織如何達成創新規模化

精實企業|高績效組織如何達成創新規模化

Jez Humble, Joanne Molesky, Barry O'Reilly
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
精通機器學習|使用Python

精通機器學習|使用Python

Sarah Guido, Andreas C. Mueller
数字化转型:企业破局的34 个锦囊

数字化转型:企业破局的34 个锦囊

Gary O’Brien, Xiao Guo, Mike Mason

Publisher Resources

ISBN: 9789865021740