Skip to content

Commit

Permalink
feat: add custom logger
Browse files Browse the repository at this point in the history
Add setDefaultLogger func and change
@retryable decorator not to initialize logger
before first use of function
Also remove `pino-pretty` from examples package
due to defined declaration in `pino-pretty`
downgrade pino to make tests working on node 10.x.x
Addresses #191
  • Loading branch information
zeruk committed Nov 15, 2022
1 parent ad8dbd2 commit 2d411cd
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 555 deletions.
32 changes: 32 additions & 0 deletions examples/custom-logger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {main} from '../utils';
import {Logger, LogFn, Driver, getCredentialsFromEnv, setDefaultLogger} from 'ydb-sdk';

const logFunction: LogFn = (obj: any, ...args: any[]) => {
console.log('Custom logging!', obj, ...args)
};
const MyLogger: Logger = {
fatal: logFunction,
error: logFunction,
warn: logFunction,
info: logFunction,
debug: logFunction,
trace: logFunction
}

setDefaultLogger(MyLogger)

export async function run(logger: Logger, endpoint: string, database: string) {
logger.info('Driver initializing...');
const authService = getCredentialsFromEnv();
const driver = new Driver({endpoint, database, authService});
const timeout = 10000;
if (!await driver.ready(timeout)) {
logger.fatal(`Driver has not become ready in ${timeout}ms!`);
process.exit(1);
}
logger.info('Done');
driver.destroy()

}

main(run);
3 changes: 1 addition & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"dependencies": {
"yargs": "^16.1.0",
"ydb-sdk": "*"
"ydb-sdk": "file:.."
},
"devDependencies": {
"@types/crc": "^3.4.0",
Expand All @@ -28,7 +28,6 @@
"@types/yargs": "^15.0.9",
"crc": "^3.8.0",
"express": "^4.17.1",
"pino-pretty": "^9.1.1",
"typescript": "^4.6.4"
}
}
Loading

0 comments on commit 2d411cd

Please sign in to comment.