Skip to content

Commit

Permalink
Fix log initialization (microsoft#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkSnail authored Nov 22, 2019
1 parent a63f2ed commit 5845ca0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
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

0 comments on commit 5845ca0

Please sign in to comment.