Skip to content

Commit

Permalink
feat: add backward compatibility for setDefaultLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
zeruk committed Mar 7, 2023
1 parent affbbc2 commit bd637bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions examples/custom-logger/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {main} from '../utils';
import {Logger, LogFn, Driver, getCredentialsFromEnv, setupLogger} from 'ydb-sdk';
import {Logger, LogFn, Driver, getCredentialsFromEnv, setupLogger, setDefaultLogger} from 'ydb-sdk';

const logFunction: LogFn = (obj: any, ...args: any[]) => {
console.log('Custom logging!', obj, ...args);
Expand All @@ -14,7 +14,8 @@ const MyLogger: Logger = {
};

export async function run(logger: Logger, endpoint: string, database: string) {
await setupLogger(MyLogger);
setupLogger(MyLogger);
// setDefaultLogger(MyLogger); // will work too
logger.info('Driver initializing...');
const authService = getCredentialsFromEnv();
const driver = new Driver({endpoint, database, authService});
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export {Ydb} from 'ydb-sdk-proto';
export {
getLogger,
setupLogger,
setDefaultLogger,
Logger,
LogFn,
FallbackLogger,
Expand Down
9 changes: 8 additions & 1 deletion src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export function setupLogger(logger: Logger) {
globalLogger = logger;
globalLogger.debug(`Default logger changed to ${globalLogger.constructor.name}`);
}
/**
* @deprecated
* Use setupLogger instead
*/
export function setDefaultLogger(logger: Logger){
return setupLogger(logger)
}

/** basic fallback implementation of LogFn */
export function getFallbackLogFunction(level: string) {
Expand Down Expand Up @@ -85,7 +92,7 @@ export class FallbackLogger implements Logger {
export function getLogger(options?: any): Logger {
if (!globalLogger) {
globalLogger = new FallbackLogger(options);
globalLogger.warn('Using fallback logger');
globalLogger.debug('Using fallback logger');
}
return globalLogger;
}

0 comments on commit bd637bc

Please sign in to comment.