Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
4b6a0ea7
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
4b6a0ea7
编写于
9月 06, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(app): log
上级
1a5979eb
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
157 addition
and
180 deletion
+157
-180
packages/uni-app-plus/__tests__/hbx/console.spec.ts
packages/uni-app-plus/__tests__/hbx/console.spec.ts
+1
-1
packages/uni-app-plus/dist/uni-app-view.umd.js
packages/uni-app-plus/dist/uni-app-view.umd.js
+1
-1
packages/uni-app-plus/dist/uni.runtime.esm.js
packages/uni-app-plus/dist/uni.runtime.esm.js
+58
-0
packages/uni-app-plus/src/service/api/index.ts
packages/uni-app-plus/src/service/api/index.ts
+1
-0
packages/uni-app-plus/src/service/api/plugin/log.ts
packages/uni-app-plus/src/service/api/plugin/log.ts
+67
-0
packages/uni-cli-shared/__tests__/console.spec.ts
packages/uni-cli-shared/__tests__/console.spec.ts
+16
-5
packages/uni-cli-shared/src/hbx/index.ts
packages/uni-cli-shared/src/hbx/index.ts
+2
-1
packages/uni-cli-shared/src/logs/console.ts
packages/uni-cli-shared/src/logs/console.ts
+2
-2
packages/uni-cli-shared/src/vite/plugins/console.ts
packages/uni-cli-shared/src/vite/plugins/console.ts
+2
-0
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+2
-54
packages/uni-shared/dist/uni-shared.es.js
packages/uni-shared/dist/uni-shared.es.js
+3
-55
packages/uni-shared/src/hbx/formatLog.ts
packages/uni-shared/src/hbx/formatLog.ts
+2
-61
未找到文件。
packages/uni-
shared
/__tests__/hbx/console.spec.ts
→
packages/uni-
app-plus
/__tests__/hbx/console.spec.ts
浏览文件 @
4b6a0ea7
import
{
normalizeLog
}
from
'
../../src/
hbx/formatL
og
'
import
{
normalizeLog
}
from
'
../../src/
service/api/plugin/l
og
'
const
filename
=
'
foo.vue
'
describe
(
'
console
'
,
()
=>
{
test
(
'
console.log format
'
,
()
=>
{
...
...
packages/uni-app-plus/dist/uni-app-view.umd.js
浏览文件 @
4b6a0ea7
此差异已折叠。
点击以展开。
packages/uni-app-plus/dist/uni.runtime.esm.js
浏览文件 @
4b6a0ea7
...
...
@@ -17090,6 +17090,63 @@ function invokeHostEvent(event, data) {
hostEventCallbacks.forEach((fn) => fn(event, data));
}
function __log__(type, filename, ...args) {
const res = normalizeLog(type, filename, args);
res && console[type](res);
}
function isDebugMode() {
// @ts-expect-error
return typeof __channelId__ === 'string' && __channelId__;
}
function jsonStringifyReplacer(k, p) {
switch (toRawType(p)) {
case 'Function':
return 'function() { [native code] }';
default:
return p;
}
}
function normalizeLog(type, filename, args) {
if (isDebugMode()) {
args.push(filename.replace('at ', 'uni-app:///'));
return console[type].apply(console, args);
}
const msgs = args.map(function (v) {
const type = toTypeString(v).toLowerCase();
if (['[object object]', '[object array]', '[object module]'].indexOf(type) !==
-1) {
try {
v =
'---BEGIN:JSON---' +
JSON.stringify(v, jsonStringifyReplacer) +
'---END:JSON---';
}
catch (e) {
v = type;
}
}
else {
if (v === null) {
v = '---NULL---';
}
else if (v === undefined) {
v = '---UNDEFINED---';
}
else {
const vType = toRawType(v).toUpperCase();
if (vType === 'NUMBER' || vType === 'BOOLEAN') {
v = '---BEGIN:' + vType + '---' + v + '---END:' + vType + '---';
}
else {
v = String(v);
}
}
}
return v;
});
return msgs.join('---COMMA---') + ' ' + filename;
}
const EventType = {
load: 'load',
close: 'close',
...
...
@@ -19162,6 +19219,7 @@ var uni$1 = {
navigateToMiniProgram: navigateToMiniProgram,
onHostEventReceive: onHostEventReceive,
onNativeEventReceive: onNativeEventReceive,
__log__: __log__,
navigateTo: navigateTo,
reLaunch: reLaunch,
switchTab: switchTab,
...
...
packages/uni-app-plus/src/service/api/index.ts
浏览文件 @
4b6a0ea7
...
...
@@ -80,6 +80,7 @@ export {
onHostEventReceive
,
onNativeEventReceive
,
}
from
'
./plugin/sdk
'
export
{
__log__
}
from
'
./plugin/log
'
export
*
from
'
./ad/rewardedVideoAd
'
export
*
from
'
./ad/fullScreenVideoAd
'
...
...
packages/uni-app-plus/src/service/api/plugin/log.ts
0 → 100644
浏览文件 @
4b6a0ea7
import
{
toTypeString
,
toRawType
}
from
'
@vue/shared
'
export
function
__log__
(
type
:
'
log
'
|
'
info
'
|
'
debug
'
|
'
warn
'
|
'
error
'
,
filename
:
string
,
...
args
:
unknown
[]
)
{
const
res
=
normalizeLog
(
type
,
filename
,
args
)
res
&&
console
[
type
](
res
)
}
function
isDebugMode
()
{
// @ts-expect-error
return
typeof
__channelId__
===
'
string
'
&&
__channelId__
}
function
jsonStringifyReplacer
(
k
:
string
,
p
:
unknown
)
{
switch
(
toRawType
(
p
))
{
case
'
Function
'
:
return
'
function() { [native code] }
'
default
:
return
p
}
}
export
function
normalizeLog
(
type
:
'
log
'
|
'
info
'
|
'
debug
'
|
'
warn
'
|
'
error
'
,
filename
:
string
,
args
:
unknown
[]
)
{
if
(
isDebugMode
())
{
args
.
push
(
filename
.
replace
(
'
at
'
,
'
uni-app:///
'
))
return
console
[
type
].
apply
(
console
,
args
)
}
const
msgs
=
args
.
map
(
function
(
v
)
{
const
type
=
toTypeString
(
v
).
toLowerCase
()
if
(
[
'
[object object]
'
,
'
[object array]
'
,
'
[object module]
'
].
indexOf
(
type
)
!==
-
1
)
{
try
{
v
=
'
---BEGIN:JSON---
'
+
JSON
.
stringify
(
v
,
jsonStringifyReplacer
)
+
'
---END:JSON---
'
}
catch
(
e
)
{
v
=
type
}
}
else
{
if
(
v
===
null
)
{
v
=
'
---NULL---
'
}
else
if
(
v
===
undefined
)
{
v
=
'
---UNDEFINED---
'
}
else
{
const
vType
=
toRawType
(
v
).
toUpperCase
()
if
(
vType
===
'
NUMBER
'
||
vType
===
'
BOOLEAN
'
)
{
v
=
'
---BEGIN:
'
+
vType
+
'
---
'
+
v
+
'
---END:
'
+
vType
+
'
---
'
}
else
{
v
=
String
(
v
)
}
}
}
return
v
})
return
msgs
.
join
(
'
---COMMA---
'
)
+
'
'
+
filename
}
packages/uni-cli-shared/__tests__/console.spec.ts
浏览文件 @
4b6a0ea7
import
{
rewriteConsoleExpr
}
from
'
../src/logs/console
'
const
filename
=
'
foo.vue
'
const
METHOD
=
'
__f__
'
describe
(
'
console
'
,
()
=>
{
test
(
'
console.log
'
,
()
=>
{
expect
(
rewriteConsoleExpr
(
filename
,
filename
,
`const a = 1;console.log(a);`
).
code
rewriteConsoleExpr
(
METHOD
,
filename
,
filename
,
`const a = 1;console.log(a);`
).
code
).
toMatchSnapshot
()
})
test
(
'
console.log multiline
'
,
()
=>
{
expect
(
rewriteConsoleExpr
(
METHOD
,
filename
,
filename
,
`const a = 1;
...
...
@@ -23,22 +30,26 @@ console.log(a,b,c);
})
test
(
'
console.info
'
,
()
=>
{
expect
(
rewriteConsoleExpr
(
filename
,
filename
,
`console.info(a,b,c);`
).
code
rewriteConsoleExpr
(
METHOD
,
filename
,
filename
,
`console.info(a,b,c);`
)
.
code
).
toMatchSnapshot
()
})
test
(
'
console.debug
'
,
()
=>
{
expect
(
rewriteConsoleExpr
(
filename
,
filename
,
`console.info(a,b,c);`
).
code
rewriteConsoleExpr
(
METHOD
,
filename
,
filename
,
`console.info(a,b,c);`
)
.
code
).
toMatchSnapshot
()
})
test
(
'
console.warn
'
,
()
=>
{
expect
(
rewriteConsoleExpr
(
filename
,
filename
,
`console.info(a,b,c);`
).
code
rewriteConsoleExpr
(
METHOD
,
filename
,
filename
,
`console.info(a,b,c);`
)
.
code
).
toMatchSnapshot
()
})
test
(
'
console.error
'
,
()
=>
{
expect
(
rewriteConsoleExpr
(
filename
,
filename
,
`console.info(a,b,c);`
).
code
rewriteConsoleExpr
(
METHOD
,
filename
,
filename
,
`console.info(a,b,c);`
)
.
code
).
toMatchSnapshot
()
})
})
packages/uni-cli-shared/src/hbx/index.ts
浏览文件 @
4b6a0ea7
...
...
@@ -11,8 +11,9 @@ export {
formatInstallHBuilderXPluginTips
,
}
from
'
./alias
'
export
function
uniHBuilderXConsolePlugin
()
{
export
function
uniHBuilderXConsolePlugin
(
method
:
string
=
'
__f__
'
)
{
return
uniConsolePlugin
({
method
,
filename
(
filename
)
{
filename
=
path
.
relative
(
process
.
env
.
UNI_INPUT_DIR
,
filename
)
if
(
filename
.
startsWith
(
'
.
'
)
||
path
.
isAbsolute
(
filename
))
{
...
...
packages/uni-cli-shared/src/logs/console.ts
浏览文件 @
4b6a0ea7
import
MagicString
from
'
magic-string
'
import
{
normalizePath
}
from
'
../utils
'
const
F
=
'
__f__
'
export
function
rewriteConsoleExpr
(
method
:
string
,
id
:
string
,
filename
:
string
,
code
:
string
,
...
...
@@ -18,7 +18,7 @@ export function rewriteConsoleExpr(
s
.
overwrite
(
match
.
index
,
match
.
index
+
expr
.
length
+
1
,
F
+
`('
${
type
}
','at
${
filename
}
:
${
locate
(
match
.
index
).
line
+
1
}
',`
method
+
`('
${
type
}
','at
${
filename
}
:
${
locate
(
match
.
index
).
line
+
1
}
',`
)
}
return
{
...
...
packages/uni-cli-shared/src/vite/plugins/console.ts
浏览文件 @
4b6a0ea7
...
...
@@ -7,6 +7,7 @@ import { rewriteConsoleExpr } from '../../logs/console'
import
{
withSourcemap
}
from
'
../../vite/utils/utils
'
export
interface
ConsoleOptions
{
method
:
string
filename
?:
(
filename
:
string
)
=>
string
include
?:
FilterPattern
exclude
?:
FilterPattern
...
...
@@ -38,6 +39,7 @@ export function uniConsolePlugin(options: ConsoleOptions): Plugin {
}
debugConsole
(
id
)
return
rewriteConsoleExpr
(
options
.
method
,
id
,
filename
,
code
,
...
...
packages/uni-shared/dist/uni-shared.cjs.js
浏览文件 @
4b6a0ea7
...
...
@@ -654,61 +654,9 @@ function parseUrl(url) {
};
}
function
isDebugMode
()
{
// @ts-expect-error
return
typeof
__channelId__
===
'
string
'
&&
__channelId__
;
}
function
jsonStringifyReplacer
(
k
,
p
)
{
switch
(
shared
.
toRawType
(
p
))
{
case
'
Function
'
:
return
'
function() { [native code] }
'
;
default
:
return
p
;
}
}
function
normalizeLog
(
type
,
filename
,
args
)
{
if
(
isDebugMode
())
{
args
.
push
(
filename
.
replace
(
'
at
'
,
'
uni-app:///
'
));
return
console
[
type
].
apply
(
console
,
args
);
}
const
msgs
=
args
.
map
(
function
(
v
)
{
const
type
=
shared
.
toTypeString
(
v
).
toLowerCase
();
if
([
'
[object object]
'
,
'
[object array]
'
,
'
[object module]
'
].
indexOf
(
type
)
!==
-
1
)
{
try
{
v
=
'
---BEGIN:JSON---
'
+
JSON
.
stringify
(
v
,
jsonStringifyReplacer
)
+
'
---END:JSON---
'
;
}
catch
(
e
)
{
v
=
type
;
}
}
else
{
if
(
v
===
null
)
{
v
=
'
---NULL---
'
;
}
else
if
(
v
===
undefined
)
{
v
=
'
---UNDEFINED---
'
;
}
else
{
const
vType
=
shared
.
toRawType
(
v
).
toUpperCase
();
if
(
vType
===
'
NUMBER
'
||
vType
===
'
BOOLEAN
'
)
{
v
=
'
---BEGIN:
'
+
vType
+
'
---
'
+
v
+
'
---END:
'
+
vType
+
'
---
'
;
}
else
{
v
=
String
(
v
);
}
}
}
return
v
;
});
return
msgs
.
join
(
'
---COMMA---
'
)
+
'
'
+
filename
;
}
function
formatAppLog
(
type
,
filename
,
...
args
)
{
const
res
=
normalizeLog
(
type
,
filename
,
args
);
res
&&
console
[
type
](
re
s
);
// @ts-ignore
uni
.
__log__
&&
uni
.
__log__
(
type
,
filename
,
arg
s
);
}
function
formatH5Log
(
type
,
filename
,
...
args
)
{
console
[
type
].
apply
(
console
,
[...
args
,
filename
]);
...
...
packages/uni-shared/dist/uni-shared.es.js
浏览文件 @
4b6a0ea7
import
{
isHTMLTag
,
isSVGTag
,
hyphenate
,
camelize
,
isString
,
isFunction
,
isPlainObject
,
extend
,
isArray
,
toTypeString
,
toRawType
,
capitalize
}
from
'
@vue/shared
'
;
import
{
isHTMLTag
,
isSVGTag
,
hyphenate
,
camelize
,
isString
,
isFunction
,
isPlainObject
,
extend
,
isArray
,
capitalize
}
from
'
@vue/shared
'
;
const
BUILT_IN_TAG_NAMES
=
[
'
ad
'
,
...
...
@@ -650,61 +650,9 @@ function parseUrl(url) {
};
}
function
isDebugMode
()
{
// @ts-expect-error
return
typeof
__channelId__
===
'
string
'
&&
__channelId__
;
}
function
jsonStringifyReplacer
(
k
,
p
)
{
switch
(
toRawType
(
p
))
{
case
'
Function
'
:
return
'
function() { [native code] }
'
;
default
:
return
p
;
}
}
function
normalizeLog
(
type
,
filename
,
args
)
{
if
(
isDebugMode
())
{
args
.
push
(
filename
.
replace
(
'
at
'
,
'
uni-app:///
'
));
return
console
[
type
].
apply
(
console
,
args
);
}
const
msgs
=
args
.
map
(
function
(
v
)
{
const
type
=
toTypeString
(
v
).
toLowerCase
();
if
([
'
[object object]
'
,
'
[object array]
'
,
'
[object module]
'
].
indexOf
(
type
)
!==
-
1
)
{
try
{
v
=
'
---BEGIN:JSON---
'
+
JSON
.
stringify
(
v
,
jsonStringifyReplacer
)
+
'
---END:JSON---
'
;
}
catch
(
e
)
{
v
=
type
;
}
}
else
{
if
(
v
===
null
)
{
v
=
'
---NULL---
'
;
}
else
if
(
v
===
undefined
)
{
v
=
'
---UNDEFINED---
'
;
}
else
{
const
vType
=
toRawType
(
v
).
toUpperCase
();
if
(
vType
===
'
NUMBER
'
||
vType
===
'
BOOLEAN
'
)
{
v
=
'
---BEGIN:
'
+
vType
+
'
---
'
+
v
+
'
---END:
'
+
vType
+
'
---
'
;
}
else
{
v
=
String
(
v
);
}
}
}
return
v
;
});
return
msgs
.
join
(
'
---COMMA---
'
)
+
'
'
+
filename
;
}
function
formatAppLog
(
type
,
filename
,
...
args
)
{
const
res
=
normalizeLog
(
type
,
filename
,
args
);
res
&&
console
[
type
](
re
s
);
// @ts-ignore
uni
.
__log__
&&
uni
.
__log__
(
type
,
filename
,
arg
s
);
}
function
formatH5Log
(
type
,
filename
,
...
args
)
{
console
[
type
].
apply
(
console
,
[...
args
,
filename
]);
...
...
packages/uni-shared/src/hbx/formatLog.ts
浏览文件 @
4b6a0ea7
import
{
toTypeString
,
toRawType
}
from
'
@vue/shared
'
function
isDebugMode
()
{
// @ts-expect-error
return
typeof
__channelId__
===
'
string
'
&&
__channelId__
}
function
jsonStringifyReplacer
(
k
:
string
,
p
:
unknown
)
{
switch
(
toRawType
(
p
))
{
case
'
Function
'
:
return
'
function() { [native code] }
'
default
:
return
p
}
}
export
function
normalizeLog
(
type
:
'
log
'
|
'
info
'
|
'
debug
'
|
'
warn
'
|
'
error
'
,
filename
:
string
,
args
:
unknown
[]
)
{
if
(
isDebugMode
())
{
args
.
push
(
filename
.
replace
(
'
at
'
,
'
uni-app:///
'
))
return
console
[
type
].
apply
(
console
,
args
)
}
const
msgs
=
args
.
map
(
function
(
v
)
{
const
type
=
toTypeString
(
v
).
toLowerCase
()
if
(
[
'
[object object]
'
,
'
[object array]
'
,
'
[object module]
'
].
indexOf
(
type
)
!==
-
1
)
{
try
{
v
=
'
---BEGIN:JSON---
'
+
JSON
.
stringify
(
v
,
jsonStringifyReplacer
)
+
'
---END:JSON---
'
}
catch
(
e
)
{
v
=
type
}
}
else
{
if
(
v
===
null
)
{
v
=
'
---NULL---
'
}
else
if
(
v
===
undefined
)
{
v
=
'
---UNDEFINED---
'
}
else
{
const
vType
=
toRawType
(
v
).
toUpperCase
()
if
(
vType
===
'
NUMBER
'
||
vType
===
'
BOOLEAN
'
)
{
v
=
'
---BEGIN:
'
+
vType
+
'
---
'
+
v
+
'
---END:
'
+
vType
+
'
---
'
}
else
{
v
=
String
(
v
)
}
}
}
return
v
})
return
msgs
.
join
(
'
---COMMA---
'
)
+
'
'
+
filename
}
export
function
formatAppLog
(
type
:
'
log
'
|
'
info
'
|
'
debug
'
|
'
warn
'
|
'
error
'
,
filename
:
string
,
...
args
:
unknown
[]
)
{
const
res
=
normalizeLog
(
type
,
filename
,
args
)
res
&&
console
[
type
](
re
s
)
// @ts-ignore
uni
.
__log__
&&
uni
.
__log__
(
type
,
filename
,
arg
s
)
}
export
function
formatH5Log
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录