-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
116 additions
and
17 deletions.
There are no files selected for viewing
19 changes: 9 additions & 10 deletions
19
examples/custom-logger/index.ts → examples/custom-logger/dummy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
import {main} from '../utils'; | ||
import {Logger, LogFn, Driver, getCredentialsFromEnv, setDefaultLogger} from 'ydb-sdk'; | ||
import {Logger, LogFn, Driver, getCredentialsFromEnv, setupLogger} from 'ydb-sdk'; | ||
|
||
const logFunction: LogFn = (obj: any, ...args: any[]) => { | ||
console.log('Custom logging!', obj, ...args) | ||
console.log('Custom logging!', obj, ...args); | ||
}; | ||
const MyLogger: Logger = { | ||
fatal: logFunction, | ||
error: logFunction, | ||
warn: logFunction, | ||
info: logFunction, | ||
debug: logFunction, | ||
trace: logFunction | ||
} | ||
|
||
setDefaultLogger(MyLogger) | ||
trace: logFunction, | ||
}; | ||
|
||
export async function run(logger: Logger, endpoint: string, database: string) { | ||
await setupLogger(MyLogger); | ||
logger.info('Driver initializing...'); | ||
const authService = getCredentialsFromEnv(); | ||
const driver = new Driver({endpoint, database, authService}); | ||
const timeout = 10000; | ||
if (!await driver.ready(timeout)) { | ||
if (!(await driver.ready(timeout))) { | ||
logger.fatal(`Driver has not become ready in ${timeout}ms!`); | ||
process.exit(1); | ||
} | ||
logger.info('Done'); | ||
driver.destroy() | ||
|
||
logger.info('Done, destroy driver'); | ||
await driver.destroy(); | ||
process.exit(0); | ||
} | ||
|
||
main(run); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {main} from '../utils'; | ||
import {Logger, Driver, getCredentialsFromEnv} from 'ydb-sdk'; | ||
|
||
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, destroy driver'); | ||
await driver.destroy(); | ||
process.exit(0); | ||
} | ||
|
||
main(run); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {mainWithoutLogger} from '../utils'; | ||
import {Driver, getCredentialsFromEnv, setupLogger} from 'ydb-sdk'; | ||
import pino from 'pino'; | ||
|
||
export async function run(endpoint: string, database: string) { | ||
const logger = pino({level: 'debug'}); | ||
logger.info('Driver initializing...'); | ||
setupLogger(logger); | ||
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, destroy driver'); | ||
await driver.destroy(); | ||
process.exit(0); | ||
} | ||
|
||
mainWithoutLogger(run); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {mainWithoutLogger} from '../utils'; | ||
import {Driver, getCredentialsFromEnv, Logger, setupLogger} from 'ydb-sdk'; | ||
import winston from 'winston'; | ||
|
||
export async function run(endpoint: string, database: string) { | ||
const logger: Logger = winston.createLogger({ | ||
level: 'debug', | ||
format: winston.format.json(), | ||
defaultMeta: {service: 'user-service'}, | ||
transports: [new winston.transports.Console({format: winston.format.simple()})], | ||
levels: { | ||
...winston.config.npm.levels, | ||
fatal: 0, | ||
trace: 6, | ||
}, | ||
}) as unknown as Logger; | ||
/* | ||
Log levels accordance: | ||
YDB-SDK-logger -> winston (npm levels) | ||
fatal -> !!! no such level, set exact as error | ||
error -> error | ||
warn -> warn | ||
info -> info | ||
debug -> debug | ||
trace -> silly(6) | ||
*/ | ||
setupLogger(logger); | ||
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, destroy driver'); | ||
await driver.destroy(); | ||
process.exit(0); | ||
} | ||
|
||
mainWithoutLogger(run); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters