Skip to content

Commit

Permalink
build, deploy: Improve logging of image build messages
Browse files Browse the repository at this point in the history
Change-type: patch
  • Loading branch information
pdcastro committed Sep 18, 2021
1 parent fdf5648 commit 1892067
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/utils/compose_ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ export async function makeBuildTasks(
infoStr = `build [${task.context}]`;
}
logger.logDebug(` ${task.serviceName}: ${infoStr}`);
task.logger = logger.getAdapter();
});

logger.logDebug(
Expand Down
22 changes: 22 additions & 0 deletions lib/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ enum Level {
LIVEPUSH = 'livepush',
}

interface LoggerAdapter {
debug: (msg: string) => void;
error: (msg: string) => void;
info: (msg: string) => void;
log: (msg: string) => void;
warn: (msg: string) => void;
}

/**
* General purpose logger class with support for log streams and colours.
* Call `Logger.getLogger()` to retrieve a global shared instance of this
Expand Down Expand Up @@ -57,6 +65,8 @@ class Logger {

protected deferredLogMessages: Array<[string, Level]>;

protected adapter: LoggerAdapter;

protected constructor() {
const logger = new StreamLogger();
const chalk = getChalk();
Expand Down Expand Up @@ -91,6 +101,14 @@ class Logger {
this.formatMessage = logger.formatWithPrefix.bind(logger);

this.deferredLogMessages = [];

this.adapter = {
debug: (msg: string) => this.logDebug(msg),
error: (msg: string) => this.logError(msg),
info: (msg: string) => this.logInfo(msg),
log: (msg: string) => this.logLogs(msg),
warn: (msg: string) => this.logWarn(msg),
};
}

protected static logger: Logger;
Expand Down Expand Up @@ -151,6 +169,10 @@ class Logger {
});
this.deferredLogMessages = [];
}

public getAdapter(): LoggerAdapter {
return this.adapter;
}
}

export = Logger;
6 changes: 3 additions & 3 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
"resin-cli-visuals": "^1.8.0",
"resin-compose-parse": "^2.1.3",
"resin-doodles": "^0.1.1",
"resin-multibuild": "^4.12.1",
"resin-multibuild": "4.12.2-logger-for-multiarch-warnings-42766be3d4df67319e34ffcb3cb89af1dd51a4c0",
"resin-stream-logger": "^0.1.2",
"rimraf": "^3.0.2",
"semver": "^7.3.2",
Expand Down

0 comments on commit 1892067

Please sign in to comment.