@ui5/logger 3.0.0-beta.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.reuse/dep5 +1 -1
- package/CHANGELOG.md +35 -41
- package/LICENSE.txt +1 -1
- package/README.md +6 -5
- package/jsdoc.json +1 -1
- package/lib/index.js +51 -0
- package/lib/loggers/Build.js +91 -0
- package/lib/loggers/Logger.js +240 -0
- package/lib/loggers/ProjectBuild.js +88 -0
- package/lib/writers/Console.js +378 -0
- package/package.json +21 -19
- package/lib/logger.js +0 -170
package/.reuse/dep5
CHANGED
|
@@ -25,5 +25,5 @@ Disclaimer: The code in this project may include calls to APIs (“API Calls”)
|
|
|
25
25
|
parties the right to use of access any SAP External Product, through API Calls.
|
|
26
26
|
|
|
27
27
|
Files: *
|
|
28
|
-
Copyright: 2018-
|
|
28
|
+
Copyright: 2018-2023 SAP SE or an SAP affiliate company and UI5 Tooling contributors
|
|
29
29
|
License: Apache-2.0
|
package/CHANGELOG.md
CHANGED
|
@@ -2,58 +2,62 @@
|
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
4
4
|
|
|
5
|
-
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-logger/compare/v3.0.0
|
|
5
|
+
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-logger/compare/v3.0.0...HEAD).
|
|
6
6
|
|
|
7
|
-
<a name="v3.0.0
|
|
8
|
-
## [v3.0.0
|
|
9
|
-
|
|
10
|
-
<a name="v3.0.1-alpha.3"></a>
|
|
11
|
-
## [v3.0.1-alpha.3] - 2022-10-24
|
|
7
|
+
<a name="v3.0.0"></a>
|
|
8
|
+
## [v3.0.0] - 2023-02-09
|
|
12
9
|
### Breaking Changes
|
|
13
|
-
|
|
10
|
+
|
|
11
|
+
- Replace npmlog with @ui5/logger/Logger (#363) [`66a159a`](https://github.com/SAP/ui5-logger/commit/66a159acd9b67a27dd66d1e8056c362585f51bcf)
|
|
12
|
+
- Deprecate advanced APIs in preparation of refactoring [`3aea5e7`](https://github.com/SAP/ui5-logger/commit/3aea5e766f9bda156e8c7e62a2e8c65f613ef7e9)
|
|
13
|
+
- Transform to ES Modules ([#306](https://github.com/SAP/ui5-logger/issues/306)) [`c79608b`](https://github.com/SAP/ui5-logger/commit/c79608b0e432168ca8570530b63a456b9ddd12cb)
|
|
14
|
+
- Require Node.js ^16.18.0, >=18.12.0 / npm >= 8 [`a8af8a7`](https://github.com/SAP/ui5-logger/commit/a8af8a7a82c6f657ac10b5018e654939d90fd81f)
|
|
14
15
|
|
|
15
16
|
### BREAKING CHANGE
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
If your project uses CommonJS, it needs to be converted to ESM or use a dynamic import.
|
|
18
|
+
The @ui5/logger got refactored and as a result its API went public.
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
- https://sap.github.io/ui5-tooling/updates/migrate-v3/
|
|
22
|
-
- https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
|
20
|
+
Remove the usage of npmlog and refactor @ui5/logger modules to emit log events which are then caught in dedicated handlers. This is somewhat inspired by npm's proc-log module.
|
|
23
21
|
|
|
22
|
+
This breaking change removes capabilities that are likely to change and should not be part of a public API.
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
### Features
|
|
28
|
-
- Add new log level "perf" [`acf0c71`](https://github.com/SAP/ui5-logger/commit/acf0c717612f440ea7a114e757c05d358ae523a7)
|
|
24
|
+
This will ensure that later changes to the module can be donen in a
|
|
25
|
+
compatible manner.
|
|
29
26
|
|
|
27
|
+
Relevant changes:
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
- Restrict log-methods to two argument only. The use of placeholders
|
|
30
|
+
like '%s' is no longer supported. A warning will be logged if more
|
|
31
|
+
than two argument is supplied. Placeholders will be replaced with a
|
|
32
|
+
deprecation message. We suggest the use of template literals.
|
|
33
|
+
- Deprecate #getGroupLogger method. Calling it throws an error.
|
|
34
|
+
It will be removed in one of the next patch releases
|
|
35
|
+
- Deprecate #setShowProgress method. Calling it throws an error.
|
|
36
|
+
It will be removed in one of the next patch releases
|
|
37
|
+
- Remove GroupLogger and TaskLogger classes. Similar functionality might
|
|
38
|
+
be re-added in a later release.
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
This package has been transformed to ES Modules. Therefore it no longer provides a CommonJS export.
|
|
41
|
+
If your project uses CommonJS, it needs to be converted to ES Modules or use a dynamic import.
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
Only Node.js v16.13.2 and npm v8 or higher are supported.
|
|
43
|
+
For more information see also:
|
|
40
44
|
|
|
45
|
+
- https://sap.github.io/ui5-tooling/updates/migrate-v3/
|
|
46
|
+
- https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
|
47
|
+
|
|
48
|
+
Support for older Node.js and npm releases has been dropped.
|
|
49
|
+
Only Node.js versions v16.18.0, v18.12.0 or higher as well as npm v8 or higher are supported.
|
|
41
50
|
|
|
42
|
-
|
|
43
|
-
## [v3.0.1-alpha.0] - 2021-12-14
|
|
51
|
+
### Features
|
|
44
52
|
|
|
45
|
-
|
|
46
|
-
## [v3.0.0-next.0] - 2021-11-29
|
|
53
|
+
- Add new log level "perf" [`acf0c71`](https://github.com/SAP/ui5-logger/commit/acf0c717612f440ea7a114e757c05d358ae523a7)
|
|
47
54
|
|
|
48
|
-
<a name="v3.0.0-alpha.0"></a>
|
|
49
|
-
## [v3.0.0-alpha.0] - 2021-12-14
|
|
50
55
|
|
|
51
56
|
<a name="v2.0.1"></a>
|
|
52
57
|
## [v2.0.1] - 2020-10-22
|
|
53
58
|
### Bug Fixes
|
|
54
59
|
- Typos in error messages [`1d25902`](https://github.com/SAP/ui5-logger/commit/1d2590223c4332f5ea6f1326b23ecf584fea5934)
|
|
55
60
|
|
|
56
|
-
|
|
57
61
|
<a name="v2.0.0"></a>
|
|
58
62
|
## [v2.0.0] - 2020-03-31
|
|
59
63
|
### Breaking Changes
|
|
@@ -64,13 +68,11 @@ Only Node.js v16.13.2 and npm v8 or higher are supported.
|
|
|
64
68
|
Support for older Node.js releases has been dropped.
|
|
65
69
|
Only Node.js v10 or higher is supported.
|
|
66
70
|
|
|
67
|
-
|
|
68
71
|
<a name="v1.0.2"></a>
|
|
69
72
|
## [v1.0.2] - 2019-10-14
|
|
70
73
|
### Bug Fixes
|
|
71
74
|
- Fix handling of log level "silent" [`020ced8`](https://github.com/SAP/ui5-logger/commit/020ced85a82d33c94e429aa28983affa0d8341ba)
|
|
72
75
|
|
|
73
|
-
|
|
74
76
|
<a name="v1.0.1"></a>
|
|
75
77
|
## [v1.0.1] - 2019-03-21
|
|
76
78
|
|
|
@@ -82,7 +84,6 @@ Only Node.js v10 or higher is supported.
|
|
|
82
84
|
### Features
|
|
83
85
|
- Add UI5_LOG_LVL environment variable [`c3e65c4`](https://github.com/SAP/ui5-logger/commit/c3e65c444045832773e4dc43ffa2baf903a27e52)
|
|
84
86
|
|
|
85
|
-
|
|
86
87
|
<a name="v0.2.1"></a>
|
|
87
88
|
## [v0.2.1] - 2018-10-29
|
|
88
89
|
|
|
@@ -94,14 +95,7 @@ Only Node.js v10 or higher is supported.
|
|
|
94
95
|
|
|
95
96
|
<a name="v0.0.1"></a>
|
|
96
97
|
## v0.0.1 - 2018-06-06
|
|
97
|
-
|
|
98
|
-
[v3.0.0-beta.1]: https://github.com/SAP/ui5-logger/compare/v3.0.1-alpha.3...v3.0.0-beta.1
|
|
99
|
-
[v3.0.1-alpha.3]: https://github.com/SAP/ui5-logger/compare/v3.0.1-alpha.2...v3.0.1-alpha.3
|
|
100
|
-
[v3.0.1-alpha.2]: https://github.com/SAP/ui5-logger/compare/v3.0.1-alpha.1...v3.0.1-alpha.2
|
|
101
|
-
[v3.0.1-alpha.1]: https://github.com/SAP/ui5-logger/compare/v3.0.1-alpha.0...v3.0.1-alpha.1
|
|
102
|
-
[v3.0.1-alpha.0]: https://github.com/SAP/ui5-logger/compare/v3.0.0-next.0...v3.0.1-alpha.0
|
|
103
|
-
[v3.0.0-next.0]: https://github.com/SAP/ui5-logger/compare/v3.0.0-alpha.0...v3.0.0-next.0
|
|
104
|
-
[v3.0.0-alpha.0]: https://github.com/SAP/ui5-logger/compare/v2.0.1...v3.0.0-alpha.0
|
|
98
|
+
[v3.0.0]: https://github.com/SAP/ui5-logger/compare/v2.0.1...v3.0.0
|
|
105
99
|
[v2.0.1]: https://github.com/SAP/ui5-logger/compare/v2.0.0...v2.0.1
|
|
106
100
|
[v2.0.0]: https://github.com/SAP/ui5-logger/compare/v1.0.2...v2.0.0
|
|
107
101
|
[v1.0.2]: https://github.com/SAP/ui5-logger/compare/v1.0.1...v1.0.2
|
package/LICENSE.txt
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright 2018-
|
|
189
|
+
Copyright 2018-2023 SAP SE or an SAP affiliate company and UI5 Tooling contributors
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
3
|
# ui5-logger
|
|
4
|
-
>
|
|
5
|
-
>
|
|
4
|
+
> Providing logging functionality for all UI5 Tooling modules and extensions.
|
|
5
|
+
> Features log levels and rendering of a progress bar.
|
|
6
|
+
> Part of [UI5 Tooling](https://github.com/SAP/ui5-tooling)
|
|
6
7
|
|
|
7
8
|
[](https://api.reuse.software/info/github.com/SAP/ui5-logger)
|
|
8
9
|
[](https://dev.azure.com/sap/opensource/_build/latest?definitionId=37&branchName=main)
|
|
9
10
|
[](https://www.npmjs.com/package/@ui5/logger)
|
|
11
|
+
[](https://coveralls.io/github/SAP/ui5-logger)
|
|
10
12
|
|
|
11
13
|
## Documentation
|
|
12
|
-
General
|
|
14
|
+
General UI5 Tooling documentation can be found here: [sap.github.io/ui5-tooling](https://sap.github.io/ui5-tooling/)
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
Used for logging purposes across the UI5 Tooling and plugins. Features log levels and progress logging. Basically, it is a wrapper of [npmlog](https://github.com/npm/npmlog).
|
|
16
|
+
The UI5 Logger API Reference can be found here: [`@ui5/logger`](https://sap.github.io/ui5-tooling/v3/api/module-@ui5_logger.html)
|
|
16
17
|
|
|
17
18
|
## Contributing
|
|
18
19
|
Please check our [Contribution Guidelines](https://github.com/SAP/ui5-tooling/blob/main/CONTRIBUTING.md).
|
package/jsdoc.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"openGraph": {
|
|
28
28
|
"title": "UI5 Tooling - API Reference",
|
|
29
29
|
"type": "website",
|
|
30
|
-
"image": "https://sap.github.io/ui5-tooling/
|
|
30
|
+
"image": "https://sap.github.io/ui5-tooling/v3/images/UI5_logo_wide.png",
|
|
31
31
|
"site_name": "UI5 Tooling - API Reference",
|
|
32
32
|
"url": "https://sap.github.io/ui5-tooling/"
|
|
33
33
|
},
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Logger from "./loggers/Logger.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interface for the UI5 Tooling logging module
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
* @module @ui5/logger
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Convenience function to create an instance of [@ui5/logger/Logger]{@link @ui5/logger/Logger}
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
* @param {string} moduleName Identifier for messages created by the logger.
|
|
15
|
+
* Example: <code>module:submodule:Class</code>
|
|
16
|
+
* @returns {@ui5/logger/Logger}
|
|
17
|
+
*/
|
|
18
|
+
export function getLogger(moduleName) {
|
|
19
|
+
return new Logger(moduleName);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Tests whether the provided log level is enabled by the current log level
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
* @function
|
|
27
|
+
* @param {string} levelName Log level to test
|
|
28
|
+
* @returns {boolean} True if the provided level is enabled
|
|
29
|
+
*/
|
|
30
|
+
export const isLogLevelEnabled = Logger.isLevelEnabled;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Sets the standard log level.
|
|
34
|
+
* <br>
|
|
35
|
+
* <b>Example:</b> Setting it to <code>perf</code> would suppress all <code>silly</code> and <code>verbose</code>
|
|
36
|
+
* logging, and only show <code>perf</code>, <code>info</code>, <code>warn</code> and <code>error</code> logs.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
* @function
|
|
40
|
+
* @param {string} levelName New log level
|
|
41
|
+
*/
|
|
42
|
+
export const setLogLevel = Logger.setLevel;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Gets the current log level
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
* @function
|
|
49
|
+
* @returns {string} The current log level. Defaults to <code>info</code>
|
|
50
|
+
*/
|
|
51
|
+
export const getLogLevel = Logger.getLevel;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import Logger from "./Logger.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Logger for emitting status events on the progress a UI5 Tooling build process.
|
|
5
|
+
* <br><br>
|
|
6
|
+
* Emits <code>ui5.log</code>, <code>ui5.build-metadata</code> and <code>ui5.build-status</code> events on the
|
|
7
|
+
* [<code>process</code>]{@link https://nodejs.org/api/process.html} object, which can which can be handled
|
|
8
|
+
* by dedicated writers, like [@ui5/logger/writers/Console]{@link @ui5/logger/writers/Console}.
|
|
9
|
+
* <br><br>
|
|
10
|
+
* If no listener is attached to the the event, messages are written directly to the <code>process.stderr</code> stream.
|
|
11
|
+
*
|
|
12
|
+
* @private
|
|
13
|
+
* @class
|
|
14
|
+
* @alias @ui5/logger/loggers/Build
|
|
15
|
+
*/
|
|
16
|
+
class Build extends Logger {
|
|
17
|
+
#projectsToBuild;
|
|
18
|
+
|
|
19
|
+
static BUILD_METADATA_EVENT_NAME = "ui5.build-metadata";
|
|
20
|
+
static BUILD_STATUS_EVENT_NAME = "ui5.build-status";
|
|
21
|
+
|
|
22
|
+
setProjects(projects) {
|
|
23
|
+
if (!projects || !Array.isArray(projects)) {
|
|
24
|
+
throw new Error("loggers/Build#setProjects: Missing or incorrect projects parameter");
|
|
25
|
+
}
|
|
26
|
+
this.#projectsToBuild = projects;
|
|
27
|
+
|
|
28
|
+
this._emit(Build.BUILD_METADATA_EVENT_NAME, {
|
|
29
|
+
projectsToBuild: projects
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
startProjectBuild(projectName, projectType) {
|
|
34
|
+
if (!this.#projectsToBuild || !this.#projectsToBuild.includes(projectName)) {
|
|
35
|
+
throw new Error(`loggers/Build#startProjectBuild: Unknown project ${projectName}`);
|
|
36
|
+
}
|
|
37
|
+
if (!projectType) {
|
|
38
|
+
throw new Error(`loggers/Build#startProjectBuild: Missing projectType parameter`);
|
|
39
|
+
}
|
|
40
|
+
const level = "info";
|
|
41
|
+
const hasListeners = this._emit(Build.BUILD_STATUS_EVENT_NAME, {
|
|
42
|
+
level,
|
|
43
|
+
projectName,
|
|
44
|
+
projectType,
|
|
45
|
+
status: "project-build-start",
|
|
46
|
+
});
|
|
47
|
+
if (!hasListeners) {
|
|
48
|
+
this._log(level, `Building ${projectType} project ${projectName}...`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
endProjectBuild(projectName, projectType) {
|
|
53
|
+
if (!this.#projectsToBuild || !this.#projectsToBuild.includes(projectName)) {
|
|
54
|
+
throw new Error(`loggers/Build#endProjectBuild: Unknown project ${projectName}`);
|
|
55
|
+
}
|
|
56
|
+
if (!projectType) {
|
|
57
|
+
throw new Error(`loggers/Build#endProjectBuild: Missing projectType parameter`);
|
|
58
|
+
}
|
|
59
|
+
const level = "verbose";
|
|
60
|
+
const hasListeners = this._emit(Build.BUILD_STATUS_EVENT_NAME, {
|
|
61
|
+
level,
|
|
62
|
+
projectName,
|
|
63
|
+
projectType,
|
|
64
|
+
status: "project-build-end",
|
|
65
|
+
});
|
|
66
|
+
if (!hasListeners) {
|
|
67
|
+
this._log(level, `Finished building ${projectType} project ${projectName}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
skipProjectBuild(projectName, projectType) {
|
|
72
|
+
if (!this.#projectsToBuild || !this.#projectsToBuild.includes(projectName)) {
|
|
73
|
+
throw new Error(`loggers/Build#skipProjectBuild: Unknown project ${projectName}`);
|
|
74
|
+
}
|
|
75
|
+
if (!projectType) {
|
|
76
|
+
throw new Error(`loggers/Build#skipProjectBuild: Missing projectType parameter`);
|
|
77
|
+
}
|
|
78
|
+
const level = "info";
|
|
79
|
+
const hasListeners = this._emit(Build.BUILD_STATUS_EVENT_NAME, {
|
|
80
|
+
level,
|
|
81
|
+
projectName,
|
|
82
|
+
projectType,
|
|
83
|
+
status: "project-build-skip",
|
|
84
|
+
});
|
|
85
|
+
if (!hasListeners) {
|
|
86
|
+
this._log(level, `Skipping build of ${projectType} project ${projectName}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default Build;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import {inspect} from "node:util";
|
|
3
|
+
|
|
4
|
+
// Module name must not contain any other characters than alphanumerical and some specials
|
|
5
|
+
const rIllegalModuleNameChars = /[^0-9a-zA-Z-_:@./]/i;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Standard logging module for UI5 Tooling and extensions.
|
|
9
|
+
* <br><br>
|
|
10
|
+
* Emits <code>ui5.log</code> events on the [<code>process</code>]{@link https://nodejs.org/api/process.html} object,
|
|
11
|
+
* which can be handled by dedicated writers,
|
|
12
|
+
* like [@ui5/logger/writers/Console]{@link @ui5/logger/writers/Console}.
|
|
13
|
+
* <br><br>
|
|
14
|
+
* If no listener is attached to an event, messages are written directly to the <code>process.stderr</code> stream.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
* @class
|
|
18
|
+
* @alias @ui5/logger/Logger
|
|
19
|
+
*/
|
|
20
|
+
class Logger {
|
|
21
|
+
/**
|
|
22
|
+
* Available log levels, ordered by priority:
|
|
23
|
+
* <br>
|
|
24
|
+
* <ol>
|
|
25
|
+
* <li>silly</li>
|
|
26
|
+
* <li>verbose</li>
|
|
27
|
+
* <li>perf</li>
|
|
28
|
+
* <li>info <i>(default)</i></li>
|
|
29
|
+
* <li>warn</li>
|
|
30
|
+
* <li>error</li>
|
|
31
|
+
* <li>silent</li>
|
|
32
|
+
* </ol>
|
|
33
|
+
*
|
|
34
|
+
* Log level <code>silent</code> is special in the sense that no messages can be submitted with that level.
|
|
35
|
+
* It can be used to suppress all logging.
|
|
36
|
+
*
|
|
37
|
+
* @member {string[]}
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
static LOG_LEVELS = ["silly", "verbose", "perf", "info", "warn", "error", "silent"];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Event name used for emitting new log-message event on the
|
|
44
|
+
* [<code>process</code>]{@link https://nodejs.org/api/process.html} object
|
|
45
|
+
*
|
|
46
|
+
* @member {string}
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
static LOG_EVENT_NAME = "ui5.log";
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Sets the standard log level.
|
|
53
|
+
* <br>
|
|
54
|
+
* <b>Example:</b> Setting it to <code>perf</code> would suppress all <code>silly</code> and <code>verbose</code>
|
|
55
|
+
* logging, and only show <code>perf</code>, <code>info</code>, <code>warn</code> and <code>error</code> logs.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
* @param {string} levelName New log level
|
|
59
|
+
*/
|
|
60
|
+
static setLevel(levelName) {
|
|
61
|
+
process.env.UI5_LOG_LVL = levelName;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Gets the current log level
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
* @returns {string} The current log level. Defaults to <code>info</code>
|
|
69
|
+
*/
|
|
70
|
+
static getLevel() {
|
|
71
|
+
if (process.env.UI5_LOG_LVL) {
|
|
72
|
+
// Check whether set log level is valid
|
|
73
|
+
const levelName = process.env.UI5_LOG_LVL;
|
|
74
|
+
if (!Logger.LOG_LEVELS.includes(levelName)) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`UI5 Logger: Environment variable UI5_LOG_LVL is set to an unknown log level "${levelName}". ` +
|
|
77
|
+
`Valid levels are ${Logger.LOG_LEVELS.join(", ")}`);
|
|
78
|
+
}
|
|
79
|
+
return levelName;
|
|
80
|
+
} else {
|
|
81
|
+
return "info";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Tests whether the provided log level is enabled by the current log level
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
* @param {string} levelName Log level to test
|
|
90
|
+
* @returns {boolean} True if the provided level is enabled
|
|
91
|
+
*/
|
|
92
|
+
static isLevelEnabled(levelName) {
|
|
93
|
+
const currIdx = Logger.LOG_LEVELS.indexOf(Logger.getLevel());
|
|
94
|
+
const reqIdx = Logger.LOG_LEVELS.indexOf(levelName);
|
|
95
|
+
if (reqIdx === -1) {
|
|
96
|
+
throw new Error(`Unknown log level "${levelName}"`);
|
|
97
|
+
}
|
|
98
|
+
return reqIdx >= currIdx;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Formats a given parameter into a string
|
|
103
|
+
*
|
|
104
|
+
* @param {any} message Single log message parameter passed by a program
|
|
105
|
+
* @returns {string} String representation for the given message
|
|
106
|
+
*/
|
|
107
|
+
static _formatMessage(message) {
|
|
108
|
+
if (typeof message === "string" || message instanceof String) {
|
|
109
|
+
return message;
|
|
110
|
+
}
|
|
111
|
+
return inspect(message, {
|
|
112
|
+
depth: 3,
|
|
113
|
+
compact: 2,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#moduleName;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
*
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
* @param {string} moduleName Identifier for messages created by this logger.
|
|
124
|
+
* Example: <code>module:submodule:Class</code>
|
|
125
|
+
*/
|
|
126
|
+
constructor(moduleName) {
|
|
127
|
+
if (!moduleName) {
|
|
128
|
+
throw new Error("Logger: Missing moduleName parameter");
|
|
129
|
+
}
|
|
130
|
+
if (rIllegalModuleNameChars.test(moduleName)) {
|
|
131
|
+
throw new Error(`Logger: Invalid module name: ${moduleName}`);
|
|
132
|
+
}
|
|
133
|
+
this.#moduleName = moduleName;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Tests whether the provided log level is enabled by the current log level
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
* @param {string} levelName Log level to test
|
|
141
|
+
* @returns {boolean} True if the provided level is enabled
|
|
142
|
+
*/
|
|
143
|
+
isLevelEnabled(levelName) {
|
|
144
|
+
return Logger.isLevelEnabled(levelName);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
_emit(eventName, payload) {
|
|
148
|
+
return process.emit(eventName, payload);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_log(level, message) {
|
|
152
|
+
if (this.isLevelEnabled(level)) {
|
|
153
|
+
process.stderr.write(`[${level}] ${message}\n`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
_emitOrLog(level, message) {
|
|
158
|
+
const hasListeners = this._emit(Logger.LOG_EVENT_NAME, {
|
|
159
|
+
level,
|
|
160
|
+
message,
|
|
161
|
+
moduleName: this.#moduleName,
|
|
162
|
+
});
|
|
163
|
+
if (!hasListeners) {
|
|
164
|
+
this._log(level, `${this.#moduleName}: ${message}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Create a log entry with the <code>silly</code> level
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
* @name @ui5/logger/Logger#silly
|
|
174
|
+
* @function
|
|
175
|
+
* @memberof @ui5/logger/Logger
|
|
176
|
+
* @param {...any} message Messages to log. An automatic string conversion is applied if necessary
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Create a log entry with the <code>verbose</code> level
|
|
181
|
+
*
|
|
182
|
+
* @public
|
|
183
|
+
* @name @ui5/logger/Logger#verbose
|
|
184
|
+
* @function
|
|
185
|
+
* @memberof @ui5/logger/Logger
|
|
186
|
+
* @param {...any} message Messages to log. An automatic string conversion is applied if necessary
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Create a log entry with the <code>perf</code> level
|
|
191
|
+
*
|
|
192
|
+
* @public
|
|
193
|
+
* @name @ui5/logger/Logger#perf
|
|
194
|
+
* @function
|
|
195
|
+
* @memberof @ui5/logger/Logger
|
|
196
|
+
* @param {...any} message Messages to log. An automatic string conversion is applied if necessary
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Create a log entry with the <code>info</code> level
|
|
201
|
+
*
|
|
202
|
+
* @public
|
|
203
|
+
* @name @ui5/logger/Logger#info
|
|
204
|
+
* @function
|
|
205
|
+
* @memberof @ui5/logger/Logger
|
|
206
|
+
* @param {...any} message Messages to log. An automatic string conversion is applied if necessary
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Create a log entry with the <code>warn</code> level
|
|
211
|
+
*
|
|
212
|
+
* @public
|
|
213
|
+
* @name @ui5/logger/Logger#warn
|
|
214
|
+
* @function
|
|
215
|
+
* @memberof @ui5/logger/Logger
|
|
216
|
+
* @param {...any} message Messages to log. An automatic string conversion is applied if necessary
|
|
217
|
+
*/
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Create a log entry with the <code>error</code> level
|
|
221
|
+
*
|
|
222
|
+
* @public
|
|
223
|
+
* @name @ui5/logger/Logger#error
|
|
224
|
+
* @function
|
|
225
|
+
* @memberof @ui5/logger/Logger
|
|
226
|
+
* @param {...any} message Messages to log. An automatic string conversion is applied if necessary
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
Logger.LOG_LEVELS.forEach((logLevel) => {
|
|
230
|
+
if (logLevel === "silent") {
|
|
231
|
+
// This level is to suppress any logging. Hence we do not provide a dedicated log-function
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
Logger.prototype[logLevel] = function(...args) {
|
|
235
|
+
const message = args.map(Logger._formatMessage).join(" ");
|
|
236
|
+
this._emitOrLog(logLevel, message);
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
export default Logger;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import Logger from "./Logger.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Logger for emitting status events on the progress a single project's build process.
|
|
5
|
+
* <br><br>
|
|
6
|
+
* Emits <code>ui5.log</code>, <code>ui5.project-build-metadata</code> and <code>ui5.project-build-status</code>
|
|
7
|
+
* events on the [<code>process</code>]{@link https://nodejs.org/api/process.html} object,
|
|
8
|
+
* which can be handled by dedicated writers,
|
|
9
|
+
* like [@ui5/logger/writers/Console]{@link @ui5/logger/writers/Console}.
|
|
10
|
+
* <br><br>
|
|
11
|
+
* If no listener is attached to the the event, messages are written directly to the <code>process.stderr</code> stream.
|
|
12
|
+
*
|
|
13
|
+
* @private
|
|
14
|
+
* @class
|
|
15
|
+
* @alias @ui5/logger/loggers/ProjectBuild
|
|
16
|
+
*/
|
|
17
|
+
class ProjectBuild extends Logger {
|
|
18
|
+
#projectName;
|
|
19
|
+
#projectType;
|
|
20
|
+
#tasksToRun;
|
|
21
|
+
|
|
22
|
+
static PROJECT_BUILD_METADATA_EVENT_NAME = "ui5.project-build-metadata";
|
|
23
|
+
static PROJECT_BUILD_STATUS_EVENT_NAME = "ui5.project-build-status";
|
|
24
|
+
|
|
25
|
+
constructor({moduleName, projectName, projectType}) {
|
|
26
|
+
super(moduleName);
|
|
27
|
+
|
|
28
|
+
if (!projectName) {
|
|
29
|
+
throw new Error("loggers/ProjectBuild: Missing projectName parameter");
|
|
30
|
+
}
|
|
31
|
+
if (!projectType) {
|
|
32
|
+
throw new Error("loggers/ProjectBuild: Missing projectType parameter");
|
|
33
|
+
}
|
|
34
|
+
this.#projectName = projectName;
|
|
35
|
+
this.#projectType = projectType;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
setTasks(tasks) {
|
|
39
|
+
if (!tasks || !Array.isArray(tasks)) {
|
|
40
|
+
throw new Error("loggers/ProjectBuild#setTasks: Missing or incorrect tasks parameter");
|
|
41
|
+
}
|
|
42
|
+
this.#tasksToRun = tasks;
|
|
43
|
+
|
|
44
|
+
this._emit(ProjectBuild.PROJECT_BUILD_METADATA_EVENT_NAME, {
|
|
45
|
+
projectName: this.#projectName,
|
|
46
|
+
projectType: this.#projectType,
|
|
47
|
+
tasksToRun: tasks
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
startTask(taskName) {
|
|
52
|
+
if (!this.#tasksToRun || !this.#tasksToRun.includes(taskName)) {
|
|
53
|
+
throw new Error(`loggers/ProjectBuild#startTask: Unknown task ${taskName}`);
|
|
54
|
+
}
|
|
55
|
+
const level = "info";
|
|
56
|
+
const hasListeners = this._emit(ProjectBuild.PROJECT_BUILD_STATUS_EVENT_NAME, {
|
|
57
|
+
level,
|
|
58
|
+
projectName: this.#projectName,
|
|
59
|
+
projectType: this.#projectType,
|
|
60
|
+
taskName,
|
|
61
|
+
status: "task-start",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!hasListeners) {
|
|
65
|
+
this._log(level, `${this.#projectName}: Running task ${taskName}...`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
endTask(taskName) {
|
|
70
|
+
if (!this.#tasksToRun || !this.#tasksToRun.includes(taskName)) {
|
|
71
|
+
throw new Error(`loggers/ProjectBuild#endTask: Unknown task ${taskName}`);
|
|
72
|
+
}
|
|
73
|
+
const level = "verbose";
|
|
74
|
+
const hasListeners = this._emit(ProjectBuild.PROJECT_BUILD_STATUS_EVENT_NAME, {
|
|
75
|
+
level,
|
|
76
|
+
projectName: this.#projectName,
|
|
77
|
+
projectType: this.#projectType,
|
|
78
|
+
taskName,
|
|
79
|
+
status: "task-end",
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (!hasListeners) {
|
|
83
|
+
this._log(level, `${this.#projectName}: Finished task ${taskName}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export default ProjectBuild;
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import {chalkStderr as chalk} from "chalk";
|
|
3
|
+
import figures from "figures";
|
|
4
|
+
import {MultiBar} from "cli-progress";
|
|
5
|
+
import Logger from "../loggers/Logger.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Standard handler for events emitted by @ui5/logger modules. Writes messages to
|
|
9
|
+
* [<code>process.stderr</code>]{@link https://nodejs.org/api/process.html#processstderr} stream
|
|
10
|
+
* and renders a progress bar for UI5 Tooling build processes.
|
|
11
|
+
* <br><br>
|
|
12
|
+
* The progress bar is only used in interactive terminals. If verbose logging is enabled, the progress
|
|
13
|
+
* bar is disabled.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
* @class
|
|
17
|
+
* @alias @ui5/logger/writers/Console
|
|
18
|
+
*/
|
|
19
|
+
class Console {
|
|
20
|
+
#projectMetadata = new Map();
|
|
21
|
+
#progressBarContainer;
|
|
22
|
+
#progressBar;
|
|
23
|
+
#progressProjectWeight;
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
this._handleLogEvent = this.#handleLogEvent.bind(this);
|
|
27
|
+
this._handleBuildStatusEvent = this.#handleBuildStatusEvent.bind(this);
|
|
28
|
+
this._handleProjectBuildStatusEvent = this.#handleProjectBuildStatusEvent.bind(this);
|
|
29
|
+
this._handleBuildMetadataEvent = this.#handleBuildMetadataEvent.bind(this);
|
|
30
|
+
this._handleProjectBuildMetadataEvent = this.#handleProjectBuildMetadataEvent.bind(this);
|
|
31
|
+
this._handleStop = this.disable.bind(this);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Attaches all event listeners and starts writing to output stream
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
enable() {
|
|
40
|
+
process.on("ui5.log", this._handleLogEvent);
|
|
41
|
+
process.on("ui5.build-metadata", this._handleBuildMetadataEvent);
|
|
42
|
+
process.on("ui5.project-build-metadata", this._handleProjectBuildMetadataEvent);
|
|
43
|
+
process.on("ui5.build-status", this._handleBuildStatusEvent);
|
|
44
|
+
process.on("ui5.project-build-status", this._handleProjectBuildStatusEvent);
|
|
45
|
+
process.on("ui5.log.stop-console", this._handleStop);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Detaches all event listeners and stops writing to output stream
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
disable() {
|
|
54
|
+
process.off("ui5.log", this._handleLogEvent);
|
|
55
|
+
process.off("ui5.build-metadata", this._handleBuildMetadataEvent);
|
|
56
|
+
process.off("ui5.project-build-metadata", this._handleProjectBuildMetadataEvent);
|
|
57
|
+
process.off("ui5.build-status", this._handleBuildStatusEvent);
|
|
58
|
+
process.off("ui5.project-build-status", this._handleProjectBuildStatusEvent);
|
|
59
|
+
process.off("ui5.log.stop-console", this._handleStop);
|
|
60
|
+
if (this.#progressBarContainer) {
|
|
61
|
+
this.#progressBar.stop();
|
|
62
|
+
this.#progressBarContainer.stop(); // Will fire internal stop event
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
* Progress bar is only required when building projects. So we create it lazily
|
|
68
|
+
*/
|
|
69
|
+
_getProgressBar() {
|
|
70
|
+
// Do not use a progress bar if there is no text terminal attached or verbose logging is enabled
|
|
71
|
+
// * If log output is piped to a static output (= no TTY), no progress bar should be rendered
|
|
72
|
+
// * Since logging through the progress bar is asynchronous (controlled by the FPS setting),
|
|
73
|
+
// exceptions might lead to log messages being dropped. Therefore do not use a progress bar
|
|
74
|
+
// for verbose logging
|
|
75
|
+
// * If log-level is set to "silent", we should never render a progress bar
|
|
76
|
+
if (process.stderr.isTTY !== true || Logger.isLevelEnabled("verbose") || Logger.getLevel() === "silent") {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
if (!this.#progressBarContainer) {
|
|
80
|
+
// We use a "MultiBar" instance even though we intend to only render a single progress bar
|
|
81
|
+
// This is because only MultiBar provides a "log" method as of today
|
|
82
|
+
this.#progressBarContainer = new MultiBar({
|
|
83
|
+
format: `{bar} {message}`,
|
|
84
|
+
barsize: 20,
|
|
85
|
+
linewrap: true,
|
|
86
|
+
emptyOnZero: 0,
|
|
87
|
+
hideCursor: true,
|
|
88
|
+
|
|
89
|
+
// FPS also controls how fast a log message will be rendered above the progress bar
|
|
90
|
+
fps: 120,
|
|
91
|
+
|
|
92
|
+
// Disable progress bar explicitly for non-TTY, even though this is already checked above
|
|
93
|
+
noTTYOutput: false,
|
|
94
|
+
|
|
95
|
+
// Graceful exit is required to ensure all terminal settings (e.g. hideCursor)
|
|
96
|
+
// are restored on SIGINT
|
|
97
|
+
gracefulExit: true,
|
|
98
|
+
|
|
99
|
+
// Required to prevent flickering when logging
|
|
100
|
+
forceRedraw: true,
|
|
101
|
+
|
|
102
|
+
clearOnComplete: true,
|
|
103
|
+
stopOnComplete: true,
|
|
104
|
+
|
|
105
|
+
barCompleteChar: figures.square,
|
|
106
|
+
barIncompleteChar: figures.squareLightShade,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Initialize empty progress bar to enable logging through the multibar instance
|
|
110
|
+
this.#progressBar = this.#progressBarContainer.create(0, 0, {message: ""});
|
|
111
|
+
|
|
112
|
+
this.#progressBarContainer.on("stop", () => {
|
|
113
|
+
// Progress bar has finished and will remove itself from the output.
|
|
114
|
+
// Therefore, further logging needs to be done directly to process.stderr. Otherwise it would disappear.
|
|
115
|
+
// Therefore, we de-reference all instances now
|
|
116
|
+
this.#progressBarContainer = null;
|
|
117
|
+
this.#progressBar = null;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return this.#progressBar;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
#writeMessage(level, message) {
|
|
124
|
+
if (!Logger.isLevelEnabled(level)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const levelPrefix = this.#getLevelPrefix(level);
|
|
128
|
+
const msg = `${levelPrefix} ${message}\n`;
|
|
129
|
+
|
|
130
|
+
if (this.#progressBarContainer) {
|
|
131
|
+
// If a progress bar is in use, we have to log through it's API
|
|
132
|
+
// cli-progress requires full control of the stderr output to ensure correct rendering
|
|
133
|
+
this.#progressBarContainer.log(msg);
|
|
134
|
+
} else {
|
|
135
|
+
process.stderr.write(msg);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#handleLogEvent({level, message, moduleName}) {
|
|
140
|
+
this.#writeMessage(level, `${chalk.blue(moduleName)} ${message}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
#handleBuildMetadataEvent({projectsToBuild}) {
|
|
144
|
+
projectsToBuild.forEach((projectName) => {
|
|
145
|
+
this.#projectMetadata.set(projectName, {
|
|
146
|
+
buildStarted: false,
|
|
147
|
+
buildSkipped: false,
|
|
148
|
+
buildEnded: false,
|
|
149
|
+
buildStartIndex: null,
|
|
150
|
+
projectTasks: new Map(),
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
this.#updateProgressBarTotal();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
#handleProjectBuildMetadataEvent({tasksToRun, projectName, projectType}) {
|
|
157
|
+
const projectMetadata = this.#getProjectMetadata(projectName);
|
|
158
|
+
tasksToRun.forEach((taskName) => {
|
|
159
|
+
projectMetadata.projectTasks.set(taskName, {
|
|
160
|
+
executionStarted: false,
|
|
161
|
+
executionEnded: false,
|
|
162
|
+
executionStartIndex: null,
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
this.#updateProgressBarTotal();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
#getProjectMetadata(projectName) {
|
|
169
|
+
const projectMetadata = this.#projectMetadata.get(projectName);
|
|
170
|
+
if (!projectMetadata) {
|
|
171
|
+
throw new Error(`writers/Console: Unknown project ${projectName}`);
|
|
172
|
+
}
|
|
173
|
+
return projectMetadata;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
#updateProgressBarTotal() {
|
|
177
|
+
let numberOfTasks = 0;
|
|
178
|
+
this.#projectMetadata.forEach(({projectTasks}) => {
|
|
179
|
+
numberOfTasks += projectTasks.size;
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// Project progress should weigh more than single task progress
|
|
183
|
+
// This is proportional to the number of projects (since that also multiplies the number of tasks)
|
|
184
|
+
this.#progressProjectWeight = this.#projectMetadata.size;
|
|
185
|
+
this._getProgressBar()?.setTotal(
|
|
186
|
+
(this.#progressProjectWeight * this.#projectMetadata.size) + numberOfTasks);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
#handleBuildStatusEvent({level, projectName, projectType, status}) {
|
|
190
|
+
const projectMetadata = this.#getProjectMetadata(projectName);
|
|
191
|
+
if (projectMetadata.buildStartIndex === null) {
|
|
192
|
+
let nextIdx = 1;
|
|
193
|
+
this.#projectMetadata.forEach((metadata) => {
|
|
194
|
+
if (metadata.buildStartIndex !== null && metadata.buildStartIndex >= nextIdx) {
|
|
195
|
+
nextIdx = metadata.buildStartIndex + 1;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
projectMetadata.buildStartIndex = nextIdx;
|
|
199
|
+
}
|
|
200
|
+
const buildIndex = `Project ${projectMetadata.buildStartIndex} of ${this.#projectMetadata.size}`;
|
|
201
|
+
|
|
202
|
+
let message;
|
|
203
|
+
switch (status) {
|
|
204
|
+
case "project-build-start":
|
|
205
|
+
if (projectMetadata.buildEnded) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
`writers/Console: Unexpected project-build-start event for project ${projectName}. ` +
|
|
208
|
+
`Project build already ended`);
|
|
209
|
+
}
|
|
210
|
+
if (projectMetadata.buildStarted) {
|
|
211
|
+
throw new Error(
|
|
212
|
+
`writers/Console: Unexpected duplicate project-build-start event for project ${projectName}`);
|
|
213
|
+
}
|
|
214
|
+
if (projectMetadata.buildSkipped) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
`writers/Console: Unexpected project-build-start event for project ${projectName}. ` +
|
|
217
|
+
`Project build already skipped`);
|
|
218
|
+
}
|
|
219
|
+
projectMetadata.buildStarted = true;
|
|
220
|
+
message = `${chalk.blue(figures.pointer)} ` +
|
|
221
|
+
`Building ${projectType} project ${chalk.bold(projectName)}...`;
|
|
222
|
+
|
|
223
|
+
// Update progress bar message with current project
|
|
224
|
+
this._getProgressBar()?.update({
|
|
225
|
+
message: `${figures.pointer} Building ${projectType} project ${projectName}...`
|
|
226
|
+
});
|
|
227
|
+
break;
|
|
228
|
+
case "project-build-end":
|
|
229
|
+
if (projectMetadata.buildEnded) {
|
|
230
|
+
throw new Error(
|
|
231
|
+
`writers/Console: Unexpected duplicate project-build-end event for project ${projectName}`);
|
|
232
|
+
}
|
|
233
|
+
if (projectMetadata.buildSkipped) {
|
|
234
|
+
throw new Error(
|
|
235
|
+
`writers/Console: Unexpected project-build-end event for project ${projectName}. ` +
|
|
236
|
+
`Project build already skipped`);
|
|
237
|
+
}
|
|
238
|
+
if (!projectMetadata.buildStarted) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`writers/Console: Unexpected project-build-end event for project ${projectName}. ` +
|
|
241
|
+
`No corresponding project-build-start event handled`);
|
|
242
|
+
}
|
|
243
|
+
projectMetadata.buildEnded = true;
|
|
244
|
+
message = `${chalk.green(figures.tick)} ` +
|
|
245
|
+
`Finished building ${projectType} project ${chalk.bold(projectName)}`;
|
|
246
|
+
|
|
247
|
+
// Update progress bar (if used)
|
|
248
|
+
this._getProgressBar()?.increment(this.#progressProjectWeight);
|
|
249
|
+
break;
|
|
250
|
+
case "project-build-skip":
|
|
251
|
+
if (projectMetadata.buildSkipped) {
|
|
252
|
+
throw new Error(
|
|
253
|
+
`writers/Console: Unexpected duplicate project-build-skip event for project ${projectName}`);
|
|
254
|
+
}
|
|
255
|
+
if (projectMetadata.buildEnded) {
|
|
256
|
+
throw new Error(
|
|
257
|
+
`writers/Console: Unexpected project-build-skip event for project ${projectName}. ` +
|
|
258
|
+
`Project build already ended`);
|
|
259
|
+
}
|
|
260
|
+
if (projectMetadata.buildStarted) {
|
|
261
|
+
throw new Error(
|
|
262
|
+
`writers/Console: Unexpected project-build-skip event for project ${projectName}. ` +
|
|
263
|
+
`Project build already started`);
|
|
264
|
+
}
|
|
265
|
+
projectMetadata.buildSkipped = true;
|
|
266
|
+
message = `${chalk.yellow(figures.tick)} ` +
|
|
267
|
+
`Skipping build of ${projectType} project ${chalk.bold(projectName)}`;
|
|
268
|
+
|
|
269
|
+
// Update progress bar (if used)
|
|
270
|
+
// All tasks of this projects are completed
|
|
271
|
+
this._getProgressBar()?.increment(this.#progressProjectWeight + projectMetadata.projectTasks.size);
|
|
272
|
+
break;
|
|
273
|
+
default:
|
|
274
|
+
this.#writeMessage("verbose",
|
|
275
|
+
`writers/Console: Received unknown build-status ${status} for project ${projectName}`);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
this.#writeMessage(level, `${chalk.grey(buildIndex)}: ${message}`);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
#handleProjectBuildStatusEvent({level, projectName, projectType, taskName, status}) {
|
|
283
|
+
const {projectTasks} = this.#getProjectMetadata(projectName);
|
|
284
|
+
const taskMetadata = projectTasks.get(taskName);
|
|
285
|
+
if (!taskMetadata) {
|
|
286
|
+
throw new Error(`writers/Console: Unknown task ${taskName} for project ${projectName}`);
|
|
287
|
+
}
|
|
288
|
+
if (taskMetadata.executionStartIndex === null) {
|
|
289
|
+
let nextIdx = 1;
|
|
290
|
+
projectTasks.forEach((metadata) => {
|
|
291
|
+
if (metadata.executionStartIndex !== null && metadata.executionStartIndex >= nextIdx) {
|
|
292
|
+
nextIdx = metadata.executionStartIndex + 1;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
taskMetadata.executionStartIndex = nextIdx;
|
|
296
|
+
}
|
|
297
|
+
let taskIndex = "";
|
|
298
|
+
if (Logger.isLevelEnabled("verbose")) {
|
|
299
|
+
taskIndex = chalk.grey(`Task ${taskMetadata.executionStartIndex} of ${projectTasks.size} `);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
let message;
|
|
303
|
+
switch (status) {
|
|
304
|
+
case "task-start":
|
|
305
|
+
if (taskMetadata.executionEnded) {
|
|
306
|
+
throw new Error(
|
|
307
|
+
`writers/Console: Unexpected task-start event for project ${projectName}, task ${taskName}. ` +
|
|
308
|
+
`Task execution already ended`);
|
|
309
|
+
}
|
|
310
|
+
if (taskMetadata.executionStarted) {
|
|
311
|
+
throw new Error(`writers/Console: Unexpected duplicate task-start event ` +
|
|
312
|
+
`for project ${projectName}, task ${taskName}`);
|
|
313
|
+
}
|
|
314
|
+
taskMetadata.executionStarted = true;
|
|
315
|
+
message = `${chalk.blue(figures.pointerSmall)} Running task ${chalk.bold(taskName)}...`;
|
|
316
|
+
break;
|
|
317
|
+
case "task-end":
|
|
318
|
+
if (taskMetadata.executionEnded) {
|
|
319
|
+
throw new Error(`writers/Console: ` +
|
|
320
|
+
`Unexpected duplicate task-end event for project ${projectName}, task ${taskName}`);
|
|
321
|
+
}
|
|
322
|
+
if (!taskMetadata.executionStarted) {
|
|
323
|
+
throw new Error(
|
|
324
|
+
`writers/Console: Unexpected task-end event for project ${projectName}, task ${taskName}. ` +
|
|
325
|
+
`No corresponding task-start event handled`);
|
|
326
|
+
}
|
|
327
|
+
taskMetadata.executionEnded = true;
|
|
328
|
+
message = `${chalk.green(figures.tick)} Finished task ${chalk.bold(taskName)}`;
|
|
329
|
+
|
|
330
|
+
// Update progress bar (if used)
|
|
331
|
+
this._getProgressBar()?.increment(1);
|
|
332
|
+
break;
|
|
333
|
+
default:
|
|
334
|
+
this.#writeMessage("verbose",
|
|
335
|
+
`writers/Console: Received unknown project-build-status ${status} for project ${projectName}`);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
this.#writeMessage(level, `${chalk.blue(`${(projectName)}`)} ${taskIndex}${message}`);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
#getLevelPrefix(level) {
|
|
343
|
+
switch (level) {
|
|
344
|
+
case "silly":
|
|
345
|
+
return chalk.inverse(level);
|
|
346
|
+
case "verbose":
|
|
347
|
+
return chalk.cyan("verb");
|
|
348
|
+
case "perf":
|
|
349
|
+
return chalk.bgYellow.red(level);
|
|
350
|
+
case "info":
|
|
351
|
+
return chalk.green(level);
|
|
352
|
+
case "warn":
|
|
353
|
+
return chalk.yellow(level);
|
|
354
|
+
case "error":
|
|
355
|
+
return chalk.bgRed.white(level);
|
|
356
|
+
// Log level silent does not produce messages
|
|
357
|
+
default:
|
|
358
|
+
return level;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Creates a new instance and subscribes it to all events
|
|
364
|
+
*
|
|
365
|
+
* @public
|
|
366
|
+
*/
|
|
367
|
+
static init() {
|
|
368
|
+
const cH = new Console();
|
|
369
|
+
cH.enable();
|
|
370
|
+
return cH;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
static stop() {
|
|
374
|
+
process.emit("ui5.log.stop-console");
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export default Console;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui5/logger",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "UI5 Tooling - Internal Logger",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SAP SE",
|
|
@@ -18,11 +18,14 @@
|
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
20
|
"exports": {
|
|
21
|
-
".": "./lib/
|
|
22
|
-
"./
|
|
21
|
+
".": "./lib/index.js",
|
|
22
|
+
"./Logger": "./lib/loggers/Logger.js",
|
|
23
|
+
"./writers/*": "./lib/writers/*.js",
|
|
24
|
+
"./package.json": "./package.json",
|
|
25
|
+
"./internal/loggers/*": "./lib/loggers/*.js"
|
|
23
26
|
},
|
|
24
27
|
"engines": {
|
|
25
|
-
"node": "
|
|
28
|
+
"node": "^16.18.0 || >=18.12.0",
|
|
26
29
|
"npm": ">= 8"
|
|
27
30
|
},
|
|
28
31
|
"scripts": {
|
|
@@ -32,7 +35,6 @@
|
|
|
32
35
|
"unit": "rimraf test/tmp && ava",
|
|
33
36
|
"unit-verbose": "rimraf test/tmp && cross-env UI5_LOG_LVL=verbose ava --verbose --serial",
|
|
34
37
|
"unit-watch": "npm run unit -- --watch",
|
|
35
|
-
"unit-nyan": "npm run unit -- --tap | tnyan",
|
|
36
38
|
"unit-xunit": "rimraf test/tmp && ava --node-arguments=\"--experimental-loader=@istanbuljs/esm-loader-hook\" --tap | tap-xunit --dontUseCommentsAsTestNames=true > test-results.xml",
|
|
37
39
|
"unit-inspect": "cross-env UI5_LOG_LVL=verbose ava debug --break",
|
|
38
40
|
"coverage": "rimraf test/tmp && nyc ava --node-arguments=\"--experimental-loader=@istanbuljs/esm-loader-hook\"",
|
|
@@ -41,10 +43,10 @@
|
|
|
41
43
|
"jsdoc-generate": "jsdoc -c ./jsdoc.json -t $(node -p 'path.dirname(require.resolve(\"docdash\"))') ./lib/ || (echo 'Error during JSDoc generation! Check log.' && exit 1)",
|
|
42
44
|
"jsdoc-watch": "npm run jsdoc && chokidar \"./lib/**/*.js\" -c \"npm run jsdoc-generate\"",
|
|
43
45
|
"preversion": "npm test",
|
|
44
|
-
"version": "git-chglog --sort semver --next-tag v$npm_package_version -o CHANGELOG.md && git add CHANGELOG.md",
|
|
46
|
+
"version": "git-chglog --sort semver --next-tag v$npm_package_version -o CHANGELOG.md v3.0.0.. && git add CHANGELOG.md",
|
|
45
47
|
"postversion": "git push --follow-tags",
|
|
46
48
|
"release-note": "git-chglog --sort semver -c .chglog/release-config.yml v$npm_package_version",
|
|
47
|
-
"depcheck": "depcheck --ignores docdash,@istanbuljs/esm-loader-hook"
|
|
49
|
+
"depcheck": "depcheck --ignores @ui5/logger,rimraf,docdash,@istanbuljs/esm-loader-hook"
|
|
48
50
|
},
|
|
49
51
|
"files": [
|
|
50
52
|
"CHANGELOG.md",
|
|
@@ -59,7 +61,6 @@
|
|
|
59
61
|
"test/lib/**/*.js"
|
|
60
62
|
],
|
|
61
63
|
"nodeArguments": [
|
|
62
|
-
"--loader=esmock",
|
|
63
64
|
"--no-warnings"
|
|
64
65
|
]
|
|
65
66
|
},
|
|
@@ -108,26 +109,27 @@
|
|
|
108
109
|
"url": "git@github.com:SAP/ui5-logger.git"
|
|
109
110
|
},
|
|
110
111
|
"dependencies": {
|
|
111
|
-
"
|
|
112
|
+
"chalk": "^5.2.0",
|
|
113
|
+
"cli-progress": "^3.11.2",
|
|
114
|
+
"figures": "^5.0.0"
|
|
112
115
|
},
|
|
113
116
|
"devDependencies": {
|
|
114
117
|
"@istanbuljs/esm-loader-hook": "^0.2.0",
|
|
115
|
-
"ava": "^5.0
|
|
118
|
+
"ava": "^5.2.0",
|
|
116
119
|
"chokidar-cli": "^3.0.0",
|
|
117
120
|
"cross-env": "^7.0.3",
|
|
118
121
|
"depcheck": "^1.4.3",
|
|
119
|
-
"docdash": "^
|
|
120
|
-
"eslint": "^8.
|
|
122
|
+
"docdash": "^2.0.1",
|
|
123
|
+
"eslint": "^8.33.0",
|
|
121
124
|
"eslint-config-google": "^0.14.0",
|
|
122
|
-
"eslint-plugin-ava": "^
|
|
123
|
-
"eslint-plugin-jsdoc": "^39.
|
|
124
|
-
"
|
|
125
|
-
"jsdoc": "^3.6.7",
|
|
125
|
+
"eslint-plugin-ava": "^14.0.0",
|
|
126
|
+
"eslint-plugin-jsdoc": "^39.8.0",
|
|
127
|
+
"jsdoc": "^4.0.0",
|
|
126
128
|
"nyc": "^15.1.0",
|
|
127
129
|
"open-cli": "^7.1.0",
|
|
128
|
-
"rimraf": "^
|
|
129
|
-
"sinon": "^
|
|
130
|
-
"
|
|
130
|
+
"rimraf": "^4.1.2",
|
|
131
|
+
"sinon": "^15.0.1",
|
|
132
|
+
"strip-ansi": "^7.0.1",
|
|
131
133
|
"tap-xunit": "^2.4.1"
|
|
132
134
|
}
|
|
133
135
|
}
|
package/lib/logger.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import npmlog from "npmlog";
|
|
2
|
-
|
|
3
|
-
const levels = ["silly", "verbose", "perf", "info", "warn", "error", "silent"];
|
|
4
|
-
if (process.env.UI5_LOG_LVL) {
|
|
5
|
-
const logLvl = process.env.UI5_LOG_LVL;
|
|
6
|
-
if (!levels.includes(logLvl)) {
|
|
7
|
-
throw new Error(`UI5 Logger: Environment variable UI5_LOG_LVL is set to an unknown log level "${logLvl}". ` +
|
|
8
|
-
`Valid levels are ${levels.join(", ")}`);
|
|
9
|
-
}
|
|
10
|
-
npmlog.level = logLvl;
|
|
11
|
-
} else {
|
|
12
|
-
npmlog.level = "info"; // Our default
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
npmlog.enableUnicode(); // TODO: Check whether unicode is actually supported
|
|
16
|
-
npmlog.prefixStyle = {fg: "blue"};
|
|
17
|
-
npmlog.headingStyle = {fg: "white", bg: "black"};
|
|
18
|
-
|
|
19
|
-
// Verbose is at level 1000, info at 2000
|
|
20
|
-
npmlog.addLevel("perf", 1500, {fg: "white", bg: "red"}, "PERF");
|
|
21
|
-
|
|
22
|
-
npmlog.on("error", (err) => {
|
|
23
|
-
console.log(err);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
function isLevelEnabled(levelName) {
|
|
27
|
-
const currIdx = levels.indexOf(npmlog.level);
|
|
28
|
-
const reqIdx = levels.indexOf(levelName);
|
|
29
|
-
if (currIdx === -1) {
|
|
30
|
-
throw new Error(`Failed to find current log level "${npmlog.level}" in list of expected log levels`);
|
|
31
|
-
}
|
|
32
|
-
if (reqIdx === -1) {
|
|
33
|
-
throw new Error(`Unknown log level "${levelName}"`);
|
|
34
|
-
}
|
|
35
|
-
if (reqIdx >= currIdx) {
|
|
36
|
-
return true;
|
|
37
|
-
} else {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
class Logger {
|
|
43
|
-
constructor(moduleName) {
|
|
44
|
-
this._moduleName = moduleName;
|
|
45
|
-
this._logger = npmlog;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
isLevelEnabled(levelName) {
|
|
49
|
-
return logger.isLevelEnabled(levelName);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
silly(...messages) {
|
|
53
|
-
return this._logger.silly(this._moduleName, ...messages);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
verbose(...messages) {
|
|
57
|
-
return this._logger.verbose(this._moduleName, ...messages);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
perf(...messages) {
|
|
61
|
-
return this._logger.perf(this._moduleName, ...messages);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
info(...messages) {
|
|
65
|
-
return this._logger.info(this._moduleName, ...messages);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
warn(...messages) {
|
|
69
|
-
return this._logger.warn(this._moduleName, ...messages);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
error(...messages) {
|
|
73
|
-
return this._logger.error(this._moduleName, ...messages);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
_getLogger() {
|
|
77
|
-
return this._logger;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
class GroupLogger extends Logger {
|
|
82
|
-
constructor(moduleName, weight = 0, parentLogger) {
|
|
83
|
-
super(moduleName);
|
|
84
|
-
|
|
85
|
-
if (parentLogger) {
|
|
86
|
-
this._logger = parentLogger._getLogger().newGroup("", weight);
|
|
87
|
-
} else {
|
|
88
|
-
this._logger = npmlog.newGroup("", weight);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
createSubLogger(name, weight) {
|
|
93
|
-
return new GroupLogger(this._moduleName + " " + name, weight, this);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
createTaskLogger(name, todo, weight) {
|
|
97
|
-
return new TaskLogger(this._moduleName + " " + name, todo, weight, this);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
class TaskLogger extends Logger {
|
|
103
|
-
constructor(moduleName, todo, weight, parentLogger) {
|
|
104
|
-
super(moduleName);
|
|
105
|
-
this._todo = todo || 0;
|
|
106
|
-
this._completed = 0;
|
|
107
|
-
|
|
108
|
-
if (parentLogger) {
|
|
109
|
-
this._logger = parentLogger._getLogger().newItem("", todo, weight);
|
|
110
|
-
} else {
|
|
111
|
-
this._logger = npmlog.newItem(this._moduleName, todo, weight);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
addWork(todo) {
|
|
116
|
-
this._logger.addWork(todo);
|
|
117
|
-
this._todo += todo;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
startWork(...messages) {
|
|
121
|
-
// Current job number is completed + 1
|
|
122
|
-
this.info(`(${this._completed + 1}/${this._todo})`, ...messages);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
completeWork(completed) {
|
|
126
|
-
this._completed += completed;
|
|
127
|
-
this._logger.completeWork(completed);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
finish() {
|
|
131
|
-
return this._logger.finish();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const logger = {
|
|
136
|
-
getLogger: function(moduleName) {
|
|
137
|
-
return new Logger(moduleName);
|
|
138
|
-
},
|
|
139
|
-
|
|
140
|
-
getGroupLogger: function(moduleName) {
|
|
141
|
-
return new GroupLogger(moduleName);
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
setLevel(level) {
|
|
145
|
-
if (!levels.includes(level)) {
|
|
146
|
-
throw new Error(`Unknown log level "${level}"`);
|
|
147
|
-
}
|
|
148
|
-
return npmlog.level = level;
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
isLevelEnabled,
|
|
152
|
-
|
|
153
|
-
setShowProgress(showProgress) {
|
|
154
|
-
if (showProgress) {
|
|
155
|
-
npmlog.enableProgress();
|
|
156
|
-
} else {
|
|
157
|
-
npmlog.disableProgress();
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// Export internal classes for testing only
|
|
163
|
-
/* istanbul ignore else */
|
|
164
|
-
if (process.env.NODE_ENV === "test") {
|
|
165
|
-
logger.__test__ = {
|
|
166
|
-
Logger, GroupLogger, TaskLogger
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export default logger;
|