Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Fix log initialization #1755

Merged
merged 17 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/nni_manager/common/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,7 @@ class Logger {
}
}

function getLogger(fileName?: string): Logger {
component.Container.bind(Logger).provider({
get: (): Logger => new Logger(fileName)
});

function getLogger(): Logger {
return component.get(Logger);
}

Expand Down
8 changes: 6 additions & 2 deletions src/nni_manager/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function initStartupInfo(
setExperimentStartupInfo(createNew, expId, basePort, logDirectory, experimentLogLevel, readonly);
}

async function initContainer(platformMode: string): Promise<void> {
async function initContainer(platformMode: string, logFileName?: string): Promise<void> {
if (platformMode === 'local') {
Container.bind(TrainingService)
.to(LocalTrainingService)
Expand Down Expand Up @@ -82,6 +82,9 @@ async function initContainer(platformMode: string): Promise<void> {
Container.bind(DataStore)
.to(NNIDataStore)
.scope(Scope.Singleton);
Container.bind(Logger).provider({
get: (): Logger => new Logger(logFileName)
});
const ds: DataStore = component.get(DataStore);

await ds.init();
Expand Down Expand Up @@ -145,13 +148,14 @@ initStartupInfo(startMode, experimentId, port, logDir, logLevel, readonly);

mkDirP(getLogDir())
.then(async () => {
const log: Logger = getLogger();
try {
await initContainer(mode);
const restServer: NNIRestServer = component.get(NNIRestServer);
await restServer.start();
const log: Logger = getLogger();
log.info(`Rest server listening on: ${restServer.endPoint}`);
} catch (err) {
const log: Logger = getLogger();
log.error(`${err.stack}`);
throw err;
}
Expand Down