Skip to content

Commit

Permalink
feat: 支持自定义log封装
Browse files Browse the repository at this point in the history
  • Loading branch information
pearone committed Oct 7, 2023
1 parent 0393bfd commit f770501
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/event/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dpdfe/event-utils",
"version": "0.0.21",
"version": "0.0.22",
"description": "通用方法",
"author": "pearone",
"homepage": "https://github.com/DPDFE/react-layout/tree/main/packages/event",
Expand Down
2 changes: 2 additions & 0 deletions packages/event/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ export {
export { gray, textColor, opacity } from './color/calc';

export { darken, lighten, range } from './color/computed';

export { log } from './log';
40 changes: 40 additions & 0 deletions packages/event/src/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 封装日志样式,支持颜色模式
* eg: log(type, name, {color: 'red'; background: 'blue'; version: '1.0.0'})
**/
export const log = (...args: any[]) => {
const style = args[args.length - 1] as {
color: string;
background: string;
};
const _style = `color:${style.color}; background: ${style.background}; font-size: 12px`;

let version = 'v0.0.1';
if (args[args.length - 1].color || args[args.length - 1].background) {
args.pop();
}
if (args[args.length - 1].version) {
version = args[args.length - 1].version;
}

console.log(
`%ctag%c${version}`,
'padding: 2px 2px 0;' +
'border-radius: 3px 0 0 3px;' +
'color: #fff;' +
'background: #606060;',
'padding: 2px 2px 0;' +
'border-radius: 0 3px 3px 0;' +
'color: #fff;' +
'background: #42c02e;'
);

args.map((arg) => {
if (typeof arg === 'object') {
console.log(arg);
} else {
const text = `${arg}`;
console.log('%c' + text, _style);
}
});
};

0 comments on commit f770501

Please sign in to comment.