Skip to content

Commit

Permalink
refactor(utils): rename log to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
shenjunjian committed Jan 20, 2025
1 parent bbe91c7 commit 931104a
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 32 deletions.
6 changes: 3 additions & 3 deletions packages/renderless/src/common/validate/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import { hasOwn, isNull } from '../type'
import { log } from '@opentiny/utils'
import { logger } from '@opentiny/utils'

const formatRegExp = /%[sdj%]/g

Expand Down Expand Up @@ -208,7 +208,7 @@ export function asyncMap(objArray, option, func, callback) {
})

// 校验器会报告中,errors fields 同时存在,属于正常,不打印; 代码真异常才打印。
pending.catch((error) => (error.errors && error.fields) || log.logger.error(error))
pending.catch((error) => (error.errors && error.fields) || logger.error(error))
return pending
}

Expand Down Expand Up @@ -244,7 +244,7 @@ export function asyncMap(objArray, option, func, callback) {
})

// 校验器会报告中,errors fields 同时存在,属于正常,不打印; 代码真异常才打印。
pending.catch((error) => (error.errors && error.fields) || log.logger.error(error))
pending.catch((error) => (error.errors && error.fields) || logger.error(error))

return pending
}
Expand Down
4 changes: 2 additions & 2 deletions packages/renderless/src/currency/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import { isUndefined, isNull } from '../grid/static'
import { log } from '@opentiny/utils'
import { logger } from '@opentiny/utils'

export const init =
({ state, service, api }) =>
Expand Down Expand Up @@ -76,7 +76,7 @@ export const fixServiceData =
if (text) {
option[valueField] = text
} else {
log('data error. set it to the default value.', 'warn')
logger.warn('data error. set it to the default value.', 'warn')
option[textField] = option[valueField] = props.currency
}
}
Expand Down
16 changes: 8 additions & 8 deletions packages/renderless/src/file-upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type {
} from '@/types'

import { extend } from '../common/object'
import { xss, log, crypt } from '@opentiny/utils'
import { xss, logger, crypt } from '@opentiny/utils'
import uploadAjax from '../common/deps/upload-ajax'
import { isObject } from '../common/type'
import { isEmptyObject } from '../common/type'
Expand Down Expand Up @@ -555,7 +555,7 @@ export const handleStart =
state,
vm
}: Pick<IFileUploadRenderlessParams, 'api' | 'constants' | 'props' | 'state' | 'vm'>) =>
(rawFiles: IFileUploadFile[], updateId: string, reUpload: boolean = false) => {
(rawFiles: IFileUploadFile[], updateId: string, reUpload = false) => {
if (state.isHwh5) {
rawFiles = handleHwh5Files(rawFiles, props.hwh5)
}
Expand Down Expand Up @@ -900,7 +900,7 @@ export const abort =

export const abortDownload =
({ state }: Pick<IFileUploadRenderlessParams, 'state'>) =>
(file: IFileUploadFile, batch: boolean = false) => {
(file: IFileUploadFile, batch = false) => {
const cancel = (docId) => {
if (!docId) return
const cancels = state.downloadCancelToken[docId]
Expand Down Expand Up @@ -1685,7 +1685,7 @@ export const afterDownload =
']'
]

log.logger.warn(msgArray.join(''))
logger.warn(msgArray.join(''))
delete state.downloadReplayAtoms[key]
} else {
if (state.downloadReplayAtoms[key] === undefined) {
Expand All @@ -1694,7 +1694,7 @@ export const afterDownload =

const msgArray = ['replay ', countDownloadReplay, '! [docId:', file.docId, ', chunk:', range.index, ']']

log.logger.warn(msgArray.join(''))
logger.warn(msgArray.join(''))

state.downloadReplayAtoms[key] += 1

Expand Down Expand Up @@ -1932,7 +1932,7 @@ const afterUpload = ({
file.chunk,
']'
]
log.logger.warn(msgArray.join(''))
logger.warn(msgArray.join(''))

delete state.replayAtoms[key]
} else {
Expand All @@ -1942,7 +1942,7 @@ const afterUpload = ({

const msgArray = ['replay ', countReplay, '! [docId:', file.docId, ', chunk:', file.chunk, ']']

log.logger.warn(msgArray.join(''))
logger.warn(msgArray.join(''))

state.replayAtoms[key] += 1

Expand Down Expand Up @@ -2263,7 +2263,7 @@ export const getToken =

export const previewFile =
({ api, props }: Pick<IFileUploadRenderlessParams, 'api' | 'props'>) =>
(file: IFileUploadFile, open: boolean = false) => {
(file: IFileUploadFile, open = false) => {
return new Promise((resolve, reject) => {
try {
const tokenParams = { isOnlinePreview: true, file, type: 'preview', token: props.edm.preview.token }
Expand Down
4 changes: 2 additions & 2 deletions packages/renderless/src/tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { on, off } from '../common/deps/dom'
import { getDataset } from '../common/dataset'
import { copyArray } from '../common/object'

import { log } from '@opentiny/utils'
import { logger } from '@opentiny/utils'

export const setChildren = (props) => (data) => (props.data = data)

Expand Down Expand Up @@ -823,7 +823,7 @@ export const addNode =
}

if (state.allNodeKeys.includes(nodeId) && !props.editConfig.noWarning) {
log.logger.warn(`the ${props.nodeKey || 'id'} ${nodeId} is already exists. Please check.`)
logger.warn(`the ${props.nodeKey || 'id'} ${nodeId} is already exists. Please check.`)
}

state.allNodeKeys.push(nodeId)
Expand Down
6 changes: 2 additions & 4 deletions packages/renderless/src/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import debounce from '../common/deps/debounce'
import { toDateStr } from '../common/date'
import { toJsonStr } from '../common/object'
import { toJson } from '../common/string'
import { log } from '@opentiny/utils'
import { logger } from '@opentiny/utils'

const toLowerCase = (val) => {
return typeof val === 'string' ? val.toLowerCase() : val
Expand Down Expand Up @@ -87,7 +87,6 @@ const request = {
},

setCache(data, valueField) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const me = this

if (valueField && !this.group[valueField]) {
Expand Down Expand Up @@ -116,7 +115,6 @@ const request = {
})
},
batchRequest(api) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const me = this
const reqParamsSeq = me.getParams()
let reqLen = reqParamsSeq.length
Expand All @@ -141,7 +139,7 @@ const request = {
}
})
})
errors.length && log.logger.warn(`user [${errors.join(',')}] not found`)
errors.length && logger.warn(`user [${errors.join(',')}] not found`)
this.clearRequest()
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import xss from './xss'
import log from './log'
import logger from './logger'
import crypt from './crypt'

export { xss, log, crypt }
export { xss, logger, crypt }

export default {
xss,
log,
logger,
crypt
}
7 changes: 0 additions & 7 deletions packages/utils/src/log/index.ts

This file was deleted.

7 changes: 7 additions & 0 deletions packages/utils/src/logger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getWindow } from '../window'

const _win: any = getWindow()
/** 使用 logger.xxx 代替 window.console.xxx, 避免语法警告 */
export const logger = _win.console as Console

export default logger
2 changes: 1 addition & 1 deletion packages/vue-common/src/breakpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import debounce from '@opentiny/vue-renderless/common/deps/debounce'
*
* @example
* const breakpoint = useBreakpoint()
* watch(breakpoint.current, (current) => { console.log(current) })
* watch(breakpoint.current, (current) => { ...... })
*/
export const useBreakpoint = () => {
const activeBreakpoint = hooks.ref('')
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/grid/src/tools/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { log } from '@opentiny/utils'
import { logger } from '@opentiny/utils'
import GlobalConfig from '../config'

const outLog = (type) => (message, detail) => {
Expand All @@ -8,7 +8,7 @@ const outLog = (type) => (message, detail) => {
msg += `: ${detail}`
}

log.logger.log(msg, type)
logger[type](msg)

return msg
}
Expand Down

0 comments on commit 931104a

Please sign in to comment.