用法:
@debug message [key=value | value ...]
@info message [key=value | value ...]
@warn message [key=value | value ...]
@error message [key=value | value ...]
@logmsg level message [key=value | value ...]
創建帶有信息性 message
的日誌記錄。為方便起見,定義了四個日誌記錄宏 @debug
、 @info
、 @warn
和 @error
,它們以標準嚴重級別記錄 Debug
、 Info
、 Warn
和 Error
。 @logmsg
允許以編程方式將 level
設置為任何 LogLevel
或自定義日誌級別類型。
message
應該是一個表達式,計算結果為一個字符串,該字符串是日誌事件的人類可讀說明。按照慣例,此字符串在顯示時將被格式化為降價。
key=value
對的可選列表支持任意用戶定義的元數據,這些元數據將作為日誌記錄的一部分傳遞到日誌後端。如果僅提供 value
表達式,則將使用
生成表示該表達式的鍵。例如,Symbol
x
變為 x=x
,而 foo(10)
變為 Symbol("foo(10)")=foo(10)
。對於 splatting 鍵值對列表,請使用正常的 splatting 語法 @info "blah" kws...
。
有一些鍵允許覆蓋自動生成的日誌數據:
_module=mod
可用於指定與消息源位置不同的發起模塊。_group=symbol
可用於覆蓋消息組(這通常源自源文件的基本名稱)。_id=symbol
可用於覆蓋自動生成的唯一消息標識符。如果您需要非常緊密地關聯在不同源代碼行上生成的消息,這很有用。_file=string
和_line=integer
可用於覆蓋日誌消息的明顯源位置。
還有一些具有傳統含義的鍵值對:
maxlog=integer
應該用作後端的提示,即消息應該顯示不超過maxlog
次。exception=ex
應該用於傳輸帶有日誌消息的異常,通常與@error
一起使用。可以使用元組exception=(ex,bt)
附加關聯的回溯bt
。
例子
@debug "Verbose debugging information. Invisible by default"
@info "An informational message"
@warn "Something was odd. You should pay attention"
@error "A non fatal error occurred"
x = 10
@info "Some variables attached to the message" x a=42.0
@debug begin
sA = sum(A)
"sum(A) = $sA is an expensive operation, evaluated only when `shouldlog` returns true"
end
for i=1:10000
@info "With the default backend, you will only see (i = $i) ten times" maxlog=10
@debug "Algorithm1" i progress=i/10000
end
相關用法
- Julia Logging.disable_logging用法及代碼示例
- Julia Logging.LogLevel用法及代碼示例
- Julia LibGit2.count用法及代碼示例
- Julia LinearAlgebra.BLAS.dot用法及代碼示例
- Julia LinearAlgebra.bunchkaufman用法及代碼示例
- Julia LinearAlgebra.cholesky!用法及代碼示例
- Julia LinearAlgebra.istriu用法及代碼示例
- Julia LinearAlgebra.istril用法及代碼示例
- Julia LinearAlgebra.stride1用法及代碼示例
- Julia LinearAlgebra.svd用法及代碼示例
- Julia LinearAlgebra.logdet用法及代碼示例
- Julia LinearAlgebra.eigen用法及代碼示例
- Julia LibGit2.authors用法及代碼示例
- Julia LibGit2.clone用法及代碼示例
- Julia LinearAlgebra.BLAS.dotu用法及代碼示例
- Julia LinearAlgebra.ldlt!用法及代碼示例
- Julia LinearAlgebra.I用法及代碼示例
- Julia LinearAlgebra.Transpose用法及代碼示例
- Julia LinearIndices用法及代碼示例
- Julia LinearAlgebra.det用法及代碼示例
- Julia LinearAlgebra.tril!用法及代碼示例
- Julia LinearAlgebra.schur!用法及代碼示例
- Julia LinearAlgebra.tr用法及代碼示例
- Julia LibGit2.GitRemoteAnon用法及代碼示例
- Julia LinearAlgebra.axpby!用法及代碼示例
注:本文由純淨天空篩選整理自julialang.org 大神的英文原創作品 Logging.@logmsg — Macro。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。