Skip to content

Commit

Permalink
feat(prject): access unified log module (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Mar 14, 2020
1 parent 0081f87 commit 750ef0a
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/antd/src/components/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useRef, useMemo } from 'react'
import { Form as AntdForm } from 'antd'
import { InternalForm } from '@formily/react-schema-renderer'
import { normalizeCol, autoScrollInValidateFailed, isAntdV4 } from '../shared'
import { normalizeCol, autoScrollInValidateFailed, isAntdV4,log } from '../shared'
import { FormItemDeepProvider } from '../context'
import { IAntdFormProps } from '../types'
import {
Expand Down Expand Up @@ -41,7 +41,7 @@ export const Form: React.FC<IAntdFormProps &
{form => {
const onSubmit = e => {
if (e && e.preventDefault) e.preventDefault()
form.submit().catch(e => console.warn(e))
form.submit().catch(e => log.warn(e))
}
const onReset = () => {
form.reset({ validate: false, forceClear: false })
Expand Down
7 changes: 4 additions & 3 deletions packages/antd/src/components/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
import {
normalizeCol,
pickFormItemProps,
pickNotFormItemProps
pickNotFormItemProps,
log
} from '../shared'
import { useDeepFormItem } from '../context'
import { IAntdFormItemProps } from '../types'
Expand Down Expand Up @@ -67,8 +68,8 @@ export const FormItem: React.FC<IAntdFormItemProps> = topProps => {
const renderComponent = ({ props, state, mutators, form }) => {
if (!component) {
if (children) return <Fragment>{children}</Fragment>
console.error(
`[Formily Error]: Can't fount the component. Its key is ${name}.`
log.error(
`Can't fount the component. Its key is ${name}.`
)
return null
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
isNum,
isArr,
clone,
log,
isValid,
FormPath,
FormPathPattern,
Expand Down Expand Up @@ -1067,7 +1068,7 @@ export function createForm<FieldProps, VirtualFieldProps>(

// 打印warnings日志从submit挪到这里
if (warnings.length) {
console.warn(warnings)
log.warn(warnings)
}
if (errors.length > 0) {
if (throwErrors) {
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/components/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useRef } from 'react'
import { Form as NextForm } from '@alifd/next'
import { InternalForm } from '@formily/react-schema-renderer'
import { normalizeCol, autoScrollInValidateFailed } from '../shared'
import { normalizeCol, autoScrollInValidateFailed,log } from '../shared'
import { FormItemDeepProvider } from '../context'
import { INextFormProps } from '../types'
import {
Expand Down Expand Up @@ -49,7 +49,7 @@ export const Form: React.FC<INextFormProps &
field={false}
onSubmit={e => {
if (e && e.preventDefault) e.preventDefault()
form.submit().catch(e => console.warn(e))
form.submit().catch(e => log.warn(e))
}}
onReset={() => {
form.reset({ validate: false, forceClear: false })
Expand Down
7 changes: 4 additions & 3 deletions packages/next/src/components/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
import {
normalizeCol,
pickNotFormItemProps,
pickFormItemProps
pickFormItemProps,
log
} from '../shared'
import { useDeepFormItem } from '../context'
import { INextFormItemProps } from '../types'
Expand Down Expand Up @@ -66,8 +67,8 @@ export const FormItem: React.FC<INextFormItemProps> = topProps => {
const renderComponent = ({ props, state, mutators, form }) => {
if (!component) {
if (children) return <Fragment>{children}</Fragment>
console.error(
`[Formily Error]: Can't fount the component. Its key is ${name}.`
log.error(
`Can't fount the component. Its key is ${name}.`
)
return null
}
Expand Down
36 changes: 25 additions & 11 deletions packages/react-schema-renderer/src/components/SchemaField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useContext, Fragment } from 'react'
import { Field, VirtualField, IFieldState } from '@formily/react'
import { FormPath, isFn, isStr, isEqual, isValid } from '@formily/shared'
import { FormPath, isFn, isStr, isEqual, isValid, log } from '@formily/shared'
import {
ISchemaFieldProps,
ISchemaFieldComponentProps,
Expand Down Expand Up @@ -149,7 +149,9 @@ export const SchemaField: React.FunctionComponent<ISchemaFieldProps> = (
return renderFieldDelegate(props => {
const renderComponent = () => {
if (!formRegistry.formItemComponent) {
console.error(`[Formily Error]: Can not found any component.Its key is ${ErrorTipPathStr}.`)
log.error(
`Can not found any component.Its key is ${ErrorTipPathStr}.`
)
return null
}
return React.createElement(
Expand All @@ -169,13 +171,17 @@ export const SchemaField: React.FunctionComponent<ISchemaFieldProps> = (
return renderFieldDelegate(props => {
const stateComponent =
props.schema.getExtendsComponent() || props.schema.type
if (!isStr(stateComponent)){
console.error(`[Formily Error]: Can not found any form component <${stateComponent}>.Its key is ${ErrorTipPathStr}.`)
return null
if (!isStr(stateComponent)) {
log.error(
`Can not found any form component <${stateComponent}>.Its key is ${ErrorTipPathStr}.`
)
return null
}
const renderComponent = (): React.ReactElement => {
if (!formRegistry.fields[stateComponent]) {
console.error(`[Formily Error]: Can not found the field component <${stateComponent}>.Its key is ${ErrorTipPathStr}.`)
log.error(
`Can not found the field component <${stateComponent}>.Its key is ${ErrorTipPathStr}.`
)
return null
}
return React.createElement(
Expand All @@ -193,13 +199,17 @@ export const SchemaField: React.FunctionComponent<ISchemaFieldProps> = (
return renderVirtualFieldDelegate(props => {
const stateComponent =
props.schema.getExtendsComponent() || props.schema.type
if (!isStr(stateComponent)){
console.error(`[Formily Error]: Can not found any virtual form component <${stateComponent}>.Its key is ${ErrorTipPathStr}.`)
if (!isStr(stateComponent)) {
log.error(
`Can not found any virtual form component <${stateComponent}>.Its key is ${ErrorTipPathStr}.`
)
return null
}
const renderComponent = () => {
if (!formRegistry.virtualFields[stateComponent]) {
console.error(`[Formily Error]: Can not found the virtual field component <${stateComponent}>.Its key is ${ErrorTipPathStr}.`)
log.error(
`Can not found the virtual field component <${stateComponent}>.Its key is ${ErrorTipPathStr}.`
)
return null
}
return React.createElement(
Expand All @@ -214,11 +224,15 @@ export const SchemaField: React.FunctionComponent<ISchemaFieldProps> = (
return renderComponent()
})
} else {
console.error(`[Formily Error]: Can not found the field component <${initialComponent}>.Its key is ${ErrorTipPathStr}.`)
log.error(
`Can not found the field component <${initialComponent}>.Its key is ${ErrorTipPathStr}.`
)
return null
}
} else {
console.error(`[Formily Error]: Can not found the field component <${initialComponent}>.Its key is ${ErrorTipPathStr}.`)
log.error(
`Can not found the field component <${initialComponent}>.Its key is ${ErrorTipPathStr}.`
)
return null
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/react-schema-renderer/src/components/SchemaForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SchemaContext, {
FormComponentsContext,
FormExpressionScopeContext
} from '../shared/context'
import { log } from '@formily/shared'

export const SchemaForm: React.FC<ISchemaFormProps> = props => {
const {
Expand All @@ -32,7 +33,7 @@ export const SchemaForm: React.FC<ISchemaFormProps> = props => {
...formComponentProps,
onSubmit: (e: any) => {
if (e && e.preventDefault) e.preventDefault()
form.submit().catch(e => console.warn(e))
form.submit().catch(e => log.warn(e))
},
onReset: () => {
form.reset({ validate: false, forceClear: false })
Expand Down
7 changes: 6 additions & 1 deletion packages/react-schema-renderer/src/shared/registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isFn, lowercase, reduce, each, deprecate } from '@formily/shared'
import { isFn, lowercase, reduce, each, deprecate, log } from '@formily/shared'
import {
ComponentWithStyleComponent,
ISchemaFieldWrapper,
Expand Down Expand Up @@ -61,6 +61,11 @@ export function registerFormField(
(isFn(component) || typeof component.styledComponentId === 'string')
) {
name = lowercase(name)
if (registry.fields[name]) {
log.warn(
'Component registration naming conflict. Please change the name. Globally registered components will no longer support overlay registration in the future.'
)
}
if (noWrapper) {
registry.fields[name] = component
registry.fields[name].__WRAPPERS__ = []
Expand Down
7 changes: 4 additions & 3 deletions packages/validator/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
FormPath,
each,
globalThisPolyfill,
merge as deepmerge
merge as deepmerge,
log
} from '@formily/shared'
import locales from './locale'

Expand Down Expand Up @@ -55,8 +56,8 @@ export const setLanguage = setValidationLanguage

export const getMessage = (path: string) => {
const message = getIn(LOCALE.messages, `${getMatchLang(LOCALE.lang)}.${path}`)
if (!message && console && console.error) {
console.error(
if (!message) {
log.error(
`field is not valid,but not found ${path} error message. Please set the language pack first through setValidationLocale`
)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/validator/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
isObj,
isValid,
each,
log,
reduce,
FormPath,
FormPathPattern
Expand Down Expand Up @@ -208,7 +209,7 @@ class FormValidator {
warnings
}
} catch (error) {
console.error(error)
log.error(error)
return {
errors,
warnings
Expand Down

0 comments on commit 750ef0a

Please sign in to comment.