mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 12:30:06 +00:00
chore(*): refactor to use logger if available
This commit is contained in:
@@ -607,6 +607,7 @@ export class SASViyaApiClient {
|
|||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
isForced?: boolean
|
isForced?: boolean
|
||||||
): Promise<Folder> {
|
): Promise<Folder> {
|
||||||
|
const logger = process.logger || console
|
||||||
if (!parentFolderPath && !parentFolderUri) {
|
if (!parentFolderPath && !parentFolderUri) {
|
||||||
throw new Error('Path or URI of the parent folder is required.')
|
throw new Error('Path or URI of the parent folder is required.')
|
||||||
}
|
}
|
||||||
@@ -614,7 +615,7 @@ export class SASViyaApiClient {
|
|||||||
if (!parentFolderUri && parentFolderPath) {
|
if (!parentFolderUri && parentFolderPath) {
|
||||||
parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
|
parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
|
||||||
if (!parentFolderUri) {
|
if (!parentFolderUri) {
|
||||||
console.log(
|
logger.info(
|
||||||
`Parent folder at path '${parentFolderPath}' is not present.`
|
`Parent folder at path '${parentFolderPath}' is not present.`
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -626,7 +627,7 @@ export class SASViyaApiClient {
|
|||||||
if (newParentFolderPath === '') {
|
if (newParentFolderPath === '') {
|
||||||
throw new Error('Root folder has to be present on the server.')
|
throw new Error('Root folder has to be present on the server.')
|
||||||
}
|
}
|
||||||
console.log(
|
logger.info(
|
||||||
`Creating parent folder:\n'${newFolderName}' in '${newParentFolderPath}'`
|
`Creating parent folder:\n'${newFolderName}' in '${newParentFolderPath}'`
|
||||||
)
|
)
|
||||||
const parentFolder = await this.createFolder(
|
const parentFolder = await this.createFolder(
|
||||||
@@ -635,7 +636,7 @@ export class SASViyaApiClient {
|
|||||||
undefined,
|
undefined,
|
||||||
accessToken
|
accessToken
|
||||||
)
|
)
|
||||||
console.log(
|
logger.info(
|
||||||
`Parent folder '${newFolderName}' has been successfully created.`
|
`Parent folder '${newFolderName}' has been successfully created.`
|
||||||
)
|
)
|
||||||
parentFolderUri = `/folders/folders/${parentFolder.id}`
|
parentFolderUri = `/folders/folders/${parentFolder.id}`
|
||||||
@@ -1138,6 +1139,8 @@ export class SASViyaApiClient {
|
|||||||
authConfig?: AuthConfig,
|
authConfig?: AuthConfig,
|
||||||
pollOptions?: PollOptions
|
pollOptions?: PollOptions
|
||||||
) {
|
) {
|
||||||
|
const logger = process.logger || console
|
||||||
|
|
||||||
let POLL_INTERVAL = 300
|
let POLL_INTERVAL = 300
|
||||||
let MAX_POLL_COUNT = 1000
|
let MAX_POLL_COUNT = 1000
|
||||||
let MAX_ERROR_COUNT = 5
|
let MAX_ERROR_COUNT = 5
|
||||||
@@ -1258,8 +1261,8 @@ export class SASViyaApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.debug && printedState !== postedJobState) {
|
if (this.debug && printedState !== postedJobState) {
|
||||||
console.log('Polling job status...')
|
logger.info('Polling job status...')
|
||||||
console.log(`Current job state: ${postedJobState}`)
|
logger.info(`Current job state: ${postedJobState}`)
|
||||||
|
|
||||||
printedState = postedJobState
|
printedState = postedJobState
|
||||||
}
|
}
|
||||||
@@ -1449,6 +1452,9 @@ export class SASViyaApiClient {
|
|||||||
accessToken
|
accessToken
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!sourceFolderUri) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
const sourceFolderId = sourceFolderUri?.split('/').pop()
|
const sourceFolderId = sourceFolderUri?.split('/').pop()
|
||||||
|
|
||||||
const { result: folder } = await this.requestClient
|
const { result: folder } = await this.requestClient
|
||||||
|
|||||||
@@ -158,6 +158,8 @@ export class SessionManager {
|
|||||||
etag: string | null,
|
etag: string | null,
|
||||||
accessToken?: string
|
accessToken?: string
|
||||||
) {
|
) {
|
||||||
|
const logger = process.logger || console
|
||||||
|
|
||||||
let sessionState = session.state
|
let sessionState = session.state
|
||||||
|
|
||||||
const stateLink = session.links.find((l: any) => l.rel === 'state')
|
const stateLink = session.links.find((l: any) => l.rel === 'state')
|
||||||
@@ -170,7 +172,7 @@ export class SessionManager {
|
|||||||
) {
|
) {
|
||||||
if (stateLink) {
|
if (stateLink) {
|
||||||
if (this.debug && !this.printedSessionState.printed) {
|
if (this.debug && !this.printedSessionState.printed) {
|
||||||
console.log('Polling session status...')
|
logger.info('Polling session status...')
|
||||||
|
|
||||||
this.printedSessionState.printed = true
|
this.printedSessionState.printed = true
|
||||||
}
|
}
|
||||||
@@ -186,7 +188,7 @@ export class SessionManager {
|
|||||||
sessionState = state.trim()
|
sessionState = state.trim()
|
||||||
|
|
||||||
if (this.debug && this.printedSessionState.state !== sessionState) {
|
if (this.debug && this.printedSessionState.state !== sessionState) {
|
||||||
console.log(`Current session state is '${sessionState}'`)
|
logger.info(`Current session state is '${sessionState}'`)
|
||||||
|
|
||||||
this.printedSessionState.state = sessionState
|
this.printedSessionState.state = sessionState
|
||||||
this.printedSessionState.printed = false
|
this.printedSessionState.printed = false
|
||||||
|
|||||||
@@ -287,7 +287,8 @@ export class RequestClient implements HttpClient {
|
|||||||
})
|
})
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error)
|
const logger = process.logger || console
|
||||||
|
logger.error(error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,14 @@ export const fetchLogByChunks = async (
|
|||||||
logUrl: string,
|
logUrl: string,
|
||||||
logCount: number
|
logCount: number
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
|
const logger = process.logger || console
|
||||||
|
|
||||||
let log: string = ''
|
let log: string = ''
|
||||||
|
|
||||||
const loglimit = logCount < 10000 ? logCount : 10000
|
const loglimit = logCount < 10000 ? logCount : 10000
|
||||||
let start = 0
|
let start = 0
|
||||||
do {
|
do {
|
||||||
console.log(
|
logger.info(
|
||||||
`Fetching logs from line no: ${start + 1} to ${
|
`Fetching logs from line no: ${start + 1} to ${
|
||||||
start + loglimit
|
start + loglimit
|
||||||
} of ${logCount}.`
|
} of ${logCount}.`
|
||||||
|
|||||||
Reference in New Issue
Block a user