Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/logger #212

Merged
merged 9 commits into from
Jan 20, 2021
6 changes: 3 additions & 3 deletions 2-step/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ const execute = (input, callback) => {
return callback(400, Requester.errored(jobRunID, 'invalid dividend'))
}

logger.info('Getting value from contract: ' + contract)
logger.debug('Getting value from contract: ' + contract)
getContractPrice(contract)
.then((price) => {
price = price / multiply
logger.info('Value: ' + price)
logger.debug('Value: ' + price)
if (price <= 0) {
return callback(500, Requester.errored(jobRunID, 'on-chain value equal or less than 0'))
}
Expand All @@ -55,7 +55,7 @@ const execute = (input, callback) => {
}

const result = transform(response.result, price, operator, dividend)
logger.info('New result: ' + result)
logger.debug('New result: ' + result)

response.data.result = result
response.result = result
Expand Down
11 changes: 8 additions & 3 deletions bootstrap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ const withStatusCode = (execute: ExecuteWrappedResponse) => async (data_: Adapte
// Log adapter input & output data
const withLogger = (execute: ExecuteWrappedResponse) => async (data: AdapterRequest) => {
logger.debug('Input: ', { input: data })
const result = await execute(data)
logger.debug(`Output: [${result.statusCode}]: `, { output: result.data })
return result
try {
const result = await execute(data)
logger.debug(`Output: [${result.statusCode}]: `, { output: result.data })
return result
} catch (error) {
logger.error(error.toString(), { stack: error.stack })
throw error
}
}

const middleware = [withLogger, skipOnError(withCache), withStatusCode]
Expand Down
2 changes: 1 addition & 1 deletion composite/defi-pulse/src/symbols/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ERC20ABI_bytes32 = [
const getERC20Symbol = async (rpcUrl: string, address: string): Promise<string> => {
const provider = new ethers.providers.JsonRpcProvider(rpcUrl)
const _symbol = (abi: any) => new ethers.Contract(address, abi, provider).symbol()
logger.info('Calling blockchain to get ERC20 token symbol...')
logger.debug('Calling blockchain to get ERC20 token symbol...')
try {
return await _symbol(ERC20ABI)
} catch (ignoreable) {
Expand Down
8 changes: 7 additions & 1 deletion external-adapter/src/requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ export class Requester {
}

// Success
logger.info(`Received response: ${JSON.stringify(response.data)}`)
const { data, status, statusText } = response
logger.debug({
message: 'Received response',
data,
status,
statusText,
})
return response
}

Expand Down
1 change: 0 additions & 1 deletion orchid-bandwidth/test/adapter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('execute', () => {
requests.forEach((req) => {
it(`${req.name}`, (done) => {
execute(req.testData, (statusCode, data) => {
console.log(JSON.stringify(data))
assertSuccess({ expected: 200, actual: statusCode }, data, jobID)
assert.isAbove(data.result, 0)
assert.isAbove(data.data.result, 0)
Expand Down
3 changes: 2 additions & 1 deletion typings/@chainlink/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ declare module '@chainlink/types' {
stack: string
cause: string
}

export type AdapterErrorResponse = {
jobRunID: string
status: string
Expand All @@ -67,7 +68,7 @@ declare module '@chainlink/types' {
// TODO: clean this ASAP
export type WrappedAdapterResponse = {
statusCode: number
data: AdapterResponse
data: AdapterResponse | AdapterErrorResponse
}
export type ExecuteWrappedResponse = (input: AdapterRequest) => Promise<WrappedAdapterResponse>

Expand Down