Skip to content

Commit

Permalink
[INTERNAL] Enhance logging based on new ui5-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Jan 17, 2023
1 parent b40e3f5 commit 82b6ec1
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 107 deletions.
18 changes: 12 additions & 6 deletions lib/build/ProjectBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {promisify} from "node:util";
import rimraf from "rimraf";
const rimrafp = promisify(rimraf);
import * as resourceFactory from "@ui5/fs/resourceFactory";
import logger from "@ui5/logger";
const log = logger.getLogger("ProjectBuilder");
import BuildLogger from "@ui5/logger/BuildLogger";
const log = new BuildLogger("ProjectBuilder");
import composeProjectList from "./helpers/composeProjectList.js";
import BuildContext from "./helpers/BuildContext.js";
import prettyHrtime from "pretty-hrtime";
Expand Down Expand Up @@ -197,10 +197,13 @@ class ProjectBuilder {
}
});

log.setProjects(queue.map((projectBuildContext) => {
return projectBuildContext.getProject().getName();
}));
if (queue.length > 1) { // Do not log if only the root project is being built
log.info(`Processing ${queue.length} projects`);
if (alreadyBuilt.length) {
log.info(` Reusing built results of ${alreadyBuilt.length} projects`);
log.info(` Reusing build results of ${alreadyBuilt.length} projects`);
log.info(` Building ${queue.length - alreadyBuilt.length} projects`);
}

Expand Down Expand Up @@ -232,13 +235,16 @@ class ProjectBuilder {
const pWrites = [];
for (const projectBuildContext of queue) {
const projectName = projectBuildContext.getProject().getName();
const projectType = projectBuildContext.getProject().getType();
log.verbose(`Processing project ${projectName}...`);

// Only build projects that are not already build (i.e. provide a matching build manifest)
if (!alreadyBuilt.includes(projectName)) {
log.info(`Building project ${projectName}...`);
if (alreadyBuilt.includes(projectName)) {
log.skipProjectBuild(projectName, projectType);
} else {
log.startProjectBuild(projectName, projectType);
await projectBuildContext.getTaskRunner().runTasks();
log.verbose(`Finished building project ${projectName}`);
log.endProjectBuild(projectName, projectType);
}
if (!requestedProjects.includes(projectName)) {
// Project has not been requested
Expand Down
15 changes: 8 additions & 7 deletions lib/build/TaskRunner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import composeTaskList from "./helpers/composeTaskList.js";
import logger from "@ui5/logger";
import composeTaskList from "./helpers/composeTaskList.js";
import {createReaderCollection} from "@ui5/fs/resourceFactory";

/**
Expand All @@ -15,22 +15,21 @@ class TaskRunner {
* @param {object} parameters
* @param {object} parameters.graph
* @param {object} parameters.project
* @param {@ui5/logger/GroupLogger} parameters.log Logger to use
* @param {@ui5/logger/ProjectBuildLogger} parameters.log Logger to use
* @param {@ui5/project/build/helpers/TaskUtil} parameters.taskUtil TaskUtil instance
* @param {@ui5/builder/tasks/taskRepository} parameters.taskRepository Task repository
* @param {@ui5/project/build/ProjectBuilder~BuildConfiguration} parameters.buildConfig
* Build configuration
*/
constructor({graph, project, log, taskUtil, taskRepository, buildConfig}) {
if (!graph || !project || !log || !taskUtil || !taskRepository || !buildConfig) {
throw new Error("One or more mandatory parameters not provided");
throw new Error("TaskRunner: One or more mandatory parameters not provided");
}
this._project = project;
this._graph = graph;
this._taskUtil = taskUtil;
this._taskRepository = taskRepository;
this._buildConfig = buildConfig;

this._log = log;

this._directDependencies = new Set(this._taskUtil.getDependencies());
Expand Down Expand Up @@ -115,6 +114,7 @@ class TaskRunner {
return tasksToRun.includes(taskWithoutSuffixCounter);
});

this._log.setTasks(allTasks);
for (const taskName of allTasks) {
const taskFunction = this._tasks[taskName].task;

Expand Down Expand Up @@ -359,7 +359,7 @@ class TaskRunner {
_createCustomTaskWrapper({
project, taskUtil, getDependenciesReader, task, taskName, taskConfiguration
}) {
return async function(log) {
return async function() {
/* Custom Task Interface
Parameters:
{Object} parameters Parameters
Expand All @@ -368,7 +368,7 @@ class TaskRunner {
Reader or Collection to read dependency files
{@ui5/project/build/helpers/TaskUtil} parameters.taskUtil Specification Version-dependent
interface of a [TaskUtil]{@link @ui5/project/build/helpers/TaskUtil} instance
{@ui5/logger/GroupLogger} [parameters.log] Logger instance to use by the custom task.
{@ui5/logger/Logger} [parameters.log] Logger instance to use by the custom task.
This parameter is only available to custom task extensions defining
<b>Specification Version 3.0 and above</b>.
{Object} parameters.options Options
Expand Down Expand Up @@ -421,12 +421,13 @@ class TaskRunner {
* @returns {Promise} Resolves when task has finished
*/
async _executeTask(taskName, taskFunction, taskParams) {
this._log.info(`Running task ${taskName}...`);
this._log.startTask(taskName);
this._taskStart = performance.now();
await taskFunction(taskParams, this._log);
if (this._log.isLevelEnabled("perf")) {
this._log.perf(`Task ${taskName} finished in ${Math.round((performance.now() - this._taskStart))} ms`);
}
this._log.endTask(taskName);
}

async _createDependenciesReader(requiredDirectDependencies) {
Expand Down
8 changes: 6 additions & 2 deletions lib/build/helpers/ProjectBuildContext.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ResourceTagCollection from "@ui5/fs/internal/ResourceTagCollection";
import ProjectBuildLogger from "@ui5/logger/ProjectBuildLogger";
import TaskUtil from "./TaskUtil.js";
import TaskRunner from "../TaskRunner.js";
import logger from "@ui5/logger";

/**
* Build context of a single project. Always part of an overall
Expand All @@ -20,7 +20,11 @@ class ProjectBuildContext {
}
this._buildContext = buildContext;
this._project = project;
this._log = logger.getLogger(`${project.getType()} ${project.getName()}`);
this._log = new ProjectBuildLogger({
moduleName: "Build",
projectName: project.getName(),
projectType: project.getType()
});
this._queues = {
cleanup: []
};
Expand Down
Loading

0 comments on commit 82b6ec1

Please sign in to comment.