Skip to content

Commit

Permalink
feat(render-core): update logger to console
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping committed Nov 14, 2023
1 parent 1020f98 commit 94c493c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
3 changes: 2 additions & 1 deletion packages/renderer-core/src/hoc/leaf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { isReactComponent, cloneEnumerableProperty } from '@alilc/lowcode-utils'
import { debounce } from '../utils/common';
import adapter from '../adapter';
import * as types from '../types/index';
import logger from '../utils/logger';

export interface IComponentHocInfo {
schema: any;
Expand Down Expand Up @@ -183,7 +184,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
}

if (!isReactComponent(Comp)) {
console.error(`${schema.componentName} component may be has errors: `, Comp);
logger.error(`${schema.componentName} component may be has errors: `, Comp);
}

initRerenderEvent({
Expand Down
3 changes: 2 additions & 1 deletion packages/renderer-core/src/renderer/addon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import baseRendererFactory from './base';
import { isEmpty } from '../utils';
import { IRendererAppHelper, IBaseRendererProps, IBaseRenderComponent } from '../types';
import logger from '../utils/logger';

export default function addonRendererFactory(): IBaseRenderComponent {
const BaseRenderer = baseRendererFactory();
Expand Down Expand Up @@ -32,7 +33,7 @@ export default function addonRendererFactory(): IBaseRenderComponent {
const schema = props.__schema || {};
this.state = this.__parseData(schema.state || {});
if (isEmpty(props.config) || !props.config?.addonKey) {
console.warn('lce addon has wrong config');
logger.warn('lce addon has wrong config');
this.setState({
__hasError: true,
});
Expand Down
14 changes: 7 additions & 7 deletions packages/renderer-core/src/renderer/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ export function executeLifeCycleMethod(context: any, schema: IPublicTypeNodeSche
}

if (typeof fn !== 'function') {
console.error(`生命周期${method}类型不符`, fn);
logger.error(`生命周期${method}类型不符`, fn);
return;
}

try {
return fn.apply(context, args);
} catch (e) {
console.error(`[${schema.componentName}]生命周期${method}出错`, e);
logger.error(`[${schema.componentName}]生命周期${method}出错`, e);
}
}

Expand Down Expand Up @@ -208,7 +208,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {

async componentDidCatch(...args: any[]) {
this.__executeLifeCycleMethod('componentDidCatch', args);
console.warn(args);
logger.warn(args);
}

reloadDataSource = () => new Promise((resolve, reject) => {
Expand Down Expand Up @@ -278,7 +278,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
value = this.__parseExpression(value, this);
}
if (typeof value !== 'function') {
console.error(`custom method ${key} can not be parsed to a valid function`, value);
logger.error(`custom method ${key} can not be parsed to a valid function`, value);
return;
}
this[key] = value.bind(this);
Expand Down Expand Up @@ -369,7 +369,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
this.setLocale = (loc: string) => {
const setLocaleFn = this.appHelper?.utils?.i18n?.setLocale;
if (!setLocaleFn || typeof setLocaleFn !== 'function') {
console.warn('initI18nAPIs Failed, i18n only works when appHelper.utils.i18n.setLocale() exists');
logger.warn('initI18nAPIs Failed, i18n only works when appHelper.utils.i18n.setLocale() exists');
return undefined;
}
return setLocaleFn(loc);
Expand Down Expand Up @@ -527,7 +527,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {
: {};

if (!Comp) {
console.error(`${schema.componentName} component is not found in components list! component list is:`, components || this.props.__container?.components);
logger.error(`${schema.componentName} component is not found in components list! component list is:`, components || this.props.__container?.components);
return engine.createElement(
engine.getNotFoundComponent(),
{
Expand Down Expand Up @@ -749,7 +749,7 @@ export default function baseRendererFactory(): IBaseRenderComponent {

__createLoopVirtualDom = (schema: IPublicTypeNodeSchema, scope: any, parentInfo: INodeInfo, idx: number | string) => {
if (isFileSchema(schema)) {
console.warn('file type not support Loop');
logger.warn('file type not support Loop');
return null;
}
if (!Array.isArray(schema.loop)) {
Expand Down
3 changes: 2 additions & 1 deletion packages/renderer-core/src/renderer/temp.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IBaseRenderComponent } from '../types';
import logger from '../utils/logger';
import baseRendererFactory from './base';

export default function tempRendererFactory(): IBaseRenderComponent {
Expand Down Expand Up @@ -41,7 +42,7 @@ export default function tempRendererFactory(): IBaseRenderComponent {
}

async componentDidCatch(e: any) {
console.warn(e);
logger.warn(e);
this.__debug(`componentDidCatch - ${this.props.__schema.fileName}`);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/renderer-core/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ export function transformArrayToMap(arr: any[], key: string, overwrite = true) {
return res;
}

export function checkPropTypes(value: any, name: string, rule: any, componentName: string) {
export function checkPropTypes(value: any, name: string, rule: any, componentName: string): boolean {
let ruleFunction = rule;
if (typeof rule === 'string') {
ruleFunction = new Function(`"use strict"; const PropTypes = arguments[0]; return ${rule}`)(PropTypes2);
}
if (!ruleFunction || typeof ruleFunction !== 'function') {
console.warn('checkPropTypes should have a function type rule argument');
logger.warn('checkPropTypes should have a function type rule argument');
return true;
}
const err = ruleFunction(
Expand All @@ -203,7 +203,7 @@ export function checkPropTypes(value: any, name: string, rule: any, componentNam
ReactPropTypesSecret,
);
if (err) {
console.warn(err);
logger.warn(err);
}
return !err;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/renderer-core/src/utils/data-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class DataHelper {
}
const { headers, ...otherProps } = otherOptionsObj || {};
if (!req) {
console.warn(`getDataSource API named ${id} not exist`);
logger.warn(`getDataSource API named ${id} not exist`);
return;
}

Expand Down Expand Up @@ -215,15 +215,15 @@ export class DataHelper {
try {
callbackFn && callbackFn(res && res[id]);
} catch (e) {
console.error('load请求回调函数报错', e);
logger.error('load请求回调函数报错', e);
}
return res && res[id];
})
.catch((err) => {
try {
callbackFn && callbackFn(null, err);
} catch (e) {
console.error('load请求回调函数报错', e);
logger.error('load请求回调函数报错', e);
}
return err;
});
Expand Down Expand Up @@ -300,9 +300,9 @@ export class DataHelper {
return dataHandlerFun.call(this.host, data, error);
} catch (e) {
if (id) {
console.error(`[${id}]单个请求数据处理函数运行出错`, e);
logger.error(`[${id}]单个请求数据处理函数运行出错`, e);
} else {
console.error('请求数据处理函数运行出错', e);
logger.error('请求数据处理函数运行出错', e);
}
}
}
Expand Down

0 comments on commit 94c493c

Please sign in to comment.