Skip to content

Commit

Permalink
Merge pull request #212 from smartcontractkit/feature/logger
Browse files Browse the repository at this point in the history
Feature/logger
  • Loading branch information
justinkaseman committed Jan 20, 2021
2 parents dd551fe + 8826e14 commit 03c01b7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
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

0 comments on commit 03c01b7

Please sign in to comment.