瀏覽代碼

ft: 函数优化

master
SisMaker 1 天之前
父節點
當前提交
361227114c
共有 2 個文件被更改,包括 10 次插入2 次删除
  1. +2
    -2
      src/formatter/lgFmtTer.erl
  2. +8
    -0
      src/utils/lgUtil.erl

+ 2
- 2
src/formatter/lgFmtTer.erl 查看文件

@ -91,7 +91,7 @@ safeFormat(Fmt, Args, Limit) ->
output(message, LgMsg) ->
#lgMsg{msgFormat = Format, msgArgs = Args, msgSafety = Safety, msgFormatSize = Size} = LgMsg,
?lgCASE(Args =/= [] andalso Args =/= undefined, ?lgCASE(Safety == safe, safeFormat(Format, Args, [{charsLimit, Size}]), unsafeFormat(Format, Args)), Format);
output(datetime, LgMsg) -> lgUtil:msToBinStr(LgMsg#lgMsg.timestamp);
output(datetime, LgMsg) -> lgUtil:msToIolStr(LgMsg#lgMsg.timestamp);
output(pid, LgMsg) -> pid_to_list(LgMsg#lgMsg.pid);
output(node, _LgMsg) -> ?eLogCfg:get(?eLogNodeName);
output(module, LgMsg) -> atom_to_binary(LgMsg#lgMsg.module, utf8);
@ -134,7 +134,7 @@ output(Other, _) -> makeStr(Other).
output(message, LgMsg, _Width) ->
#lgMsg{msgFormat = Format, msgArgs = Args, msgSafety = Safety, msgFormatSize = Size} = LgMsg,
?lgCASE(Args =/= [] andalso Args =/= undefined, ?lgCASE(Safety == safe, safeFormat(Format, Args, [{charsLimit, Size}]), unsafeFormat(Format, Args)), Format);
output(datetime, LgMsg, _Width) -> lgUtil:msToBinStr(LgMsg#lgMsg.timestamp);
output(datetime, LgMsg, _Width) -> lgUtil:msToIolStr(LgMsg#lgMsg.timestamp);
output(pid, LgMsg, _Width) -> pid_to_list(LgMsg#lgMsg.pid);
output(node, _LgMsg, _Width) -> ?eLogCfg:get(?eLogNodeName);
output(module, LgMsg, _Width) -> atom_to_binary(LgMsg#lgMsg.module, utf8);

+ 8
- 0
src/utils/lgUtil.erl 查看文件

@ -19,6 +19,7 @@
, nowMs/0
, msToBinStr/0
, msToBinStr/1
, msToIolStr/1
, curYMDHMStr/0
, parseRotateSpec/1
, calcNextRotateMs/1
@ -193,6 +194,13 @@ msToBinStr(MsTick) ->
{{Y, M, D}, {H, Mi, S}} = erlang:universaltime_to_localtime(erlang:posixtime_to_universaltime(ThisSec)),
<<(integer_to_binary(Y))/binary, "-", (i2b(M))/binary, "-", (i2b(D))/binary, " ", (i2b(H))/binary, ":", (i2b(Mi))/binary, ":", (i2b(S))/binary, ".", (i3b(ThisMs))/binary>>.
msToIolStr(MsTick) ->
ThisSec = MsTick div 1000,
ThisMs = MsTick rem 1000,
{{Y, M, D}, {H, Mi, S}} = erlang:universaltime_to_localtime(erlang:posixtime_to_universaltime(ThisSec)),
[integer_to_binary(Y), "-", i2b(M), "-", i2b(D), " ", i2b(H), ":", i2b(Mi), ":", i2b(S), ".", i3b(ThisMs)].
curYMDHMStr() ->
{{Y, M, D}, {H, Mi, _S}} = lgTime:curDateTime(),
<<(integer_to_binary(Y))/binary, (i2b(M))/binary, (i2b(D))/binary, (i2b(H))/binary, (i2b(Mi))/binary>>.

Loading…
取消
儲存