用法:
@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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。