Skip to content

Commit 8209b31

Browse files
committed
refactor: avoid using globalContext only to get the logger
This was not buggy, but it's also unnecessarily complicated in these situations.
1 parent 75d5059 commit 8209b31

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

src/database/arangodb/config.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Database } from 'arangojs';
22
import { CreateCollectionOptions } from 'arangojs/collection';
33
import { Config } from 'arangojs/connection';
4-
import { globalContext } from '../../config/global';
54
import { ProjectOptions } from '../../config/interfaces';
6-
import { Logger } from '../../config/logging';
5+
import { DEFAULT_LOGGER_PROVIDER, Logger } from '../../config/logging';
76
import { CustomDatabase } from './arangojs-instrumentation/custom-database';
87
import { ArangoSearchConfiguration } from './schema-migration/arango-search-helpers';
98

@@ -92,10 +91,6 @@ export function initDatabase(config: ArangoDBConfig): Database {
9291
}
9392

9493
export function getArangoDBLogger(schemaContext: ProjectOptions | undefined): Logger {
95-
globalContext.registerContext(schemaContext);
96-
try {
97-
return globalContext.loggerProvider.getLogger('ArangoDBAdapter');
98-
} finally {
99-
globalContext.unregisterContext();
100-
}
94+
const loggerProvider = schemaContext?.loggerProvider ?? DEFAULT_LOGGER_PROVIDER;
95+
return loggerProvider.getLogger('ArangoDBAdapter');
10196
}

src/database/inmemory/inmemory-adapter.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { globalContext } from '../../config/global';
22
import { ProjectOptions } from '../../config/interfaces';
3-
import { Logger } from '../../config/logging';
3+
import { DEFAULT_LOGGER_PROVIDER, Logger } from '../../config/logging';
44
import { Model } from '../../model';
55
import { ALL_QUERY_RESULT_VALIDATOR_FUNCTION_PROVIDERS, QueryNode } from '../../query-tree';
66
import { FlexSearchTokenization } from '../../query-tree/flex-search';
@@ -33,12 +33,8 @@ export class InMemoryAdapter implements DatabaseAdapter {
3333
if (options.db) {
3434
this.db = options.db;
3535
}
36-
globalContext.registerContext(schemaContext);
37-
try {
38-
this.logger = globalContext.loggerProvider.getLogger('InMemoryAdapter');
39-
} finally {
40-
globalContext.unregisterContext();
41-
}
36+
const loggerProvider = schemaContext?.loggerProvider ?? DEFAULT_LOGGER_PROVIDER;
37+
this.logger = loggerProvider.getLogger('InMemoryAdapter');
4238
}
4339

4440
/**

0 commit comments

Comments
 (0)