@ui5/logger 3.0.1-rc.0 → 3.0.1-rc.2
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 +17 -2
- package/LICENSE.txt +1 -1
- package/README.md +6 -5
- 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 +371 -0
- package/package.json +17 -15
- package/lib/logger.js +0 -136
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,10 +2,23 @@
|
|
|
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.1-rc.
|
|
5
|
+
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-logger/compare/v3.0.1-rc.2...HEAD).
|
|
6
|
+
|
|
7
|
+
<a name="v3.0.1-rc.2"></a>
|
|
8
|
+
## [v3.0.1-rc.2] - 2023-01-24
|
|
9
|
+
|
|
10
|
+
<a name="v3.0.1-rc.1"></a>
|
|
11
|
+
## [v3.0.1-rc.1] - 2023-01-18
|
|
12
|
+
### Breaking Changes
|
|
13
|
+
- Replace npmlog with [@ui5](https://github.com/ui5)/logger/Logger ([#363](https://github.com/SAP/ui5-logger/issues/363)) [`66a159a`](https://github.com/SAP/ui5-logger/commit/66a159acd9b67a27dd66d1e8056c362585f51bcf)
|
|
14
|
+
|
|
15
|
+
### BREAKING CHANGE
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
6
19
|
|
|
7
20
|
<a name="v3.0.1-rc.0"></a>
|
|
8
|
-
## [v3.0.1-rc.0] - 2022-12-
|
|
21
|
+
## [v3.0.1-rc.0] - 2022-12-23
|
|
9
22
|
### Breaking Changes
|
|
10
23
|
- Deprecate advanced APIs in preparation of refactoring [`3aea5e7`](https://github.com/SAP/ui5-logger/commit/3aea5e766f9bda156e8c7e62a2e8c65f613ef7e9)
|
|
11
24
|
|
|
@@ -133,6 +146,8 @@ Only Node.js v10 or higher is supported.
|
|
|
133
146
|
<a name="v0.0.1"></a>
|
|
134
147
|
## v0.0.1 - 2018-06-06
|
|
135
148
|
|
|
149
|
+
[v3.0.1-rc.2]: https://github.com/SAP/ui5-logger/compare/v3.0.1-rc.1...v3.0.1-rc.2
|
|
150
|
+
[v3.0.1-rc.1]: https://github.com/SAP/ui5-logger/compare/v3.0.1-rc.0...v3.0.1-rc.1
|
|
136
151
|
[v3.0.1-rc.0]: https://github.com/SAP/ui5-logger/compare/v3.0.1-beta.1...v3.0.1-rc.0
|
|
137
152
|
[v3.0.1-beta.1]: https://github.com/SAP/ui5-logger/compare/v3.0.1-beta.0...v3.0.1-beta.1
|
|
138
153
|
[v3.0.1-beta.0]: https://github.com/SAP/ui5-logger/compare/v3.0.1-alpha.3...v3.0.1-beta.0
|
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/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/loggers/Logger]{@link @ui5/logger/loggers/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,371 @@
|
|
|
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
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Attaches all event listeners and starts writing to output stream
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
enable() {
|
|
39
|
+
process.on("ui5.log", this._handleLogEvent);
|
|
40
|
+
process.on("ui5.build-metadata", this._handleBuildMetadataEvent);
|
|
41
|
+
process.on("ui5.project-build-metadata", this._handleProjectBuildMetadataEvent);
|
|
42
|
+
process.on("ui5.build-status", this._handleBuildStatusEvent);
|
|
43
|
+
process.on("ui5.project-build-status", this._handleProjectBuildStatusEvent);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Detaches all event listeners and stops writing to output stream
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
disable() {
|
|
52
|
+
process.off("ui5.log", this._handleLogEvent);
|
|
53
|
+
process.off("ui5.build-metadata", this._handleBuildMetadataEvent);
|
|
54
|
+
process.off("ui5.project-build-metadata", this._handleProjectBuildMetadataEvent);
|
|
55
|
+
process.off("ui5.build-status", this._handleBuildStatusEvent);
|
|
56
|
+
process.off("ui5.project-build-status", this._handleProjectBuildStatusEvent);
|
|
57
|
+
if (this.#progressBarContainer) {
|
|
58
|
+
this.#progressBar.stop();
|
|
59
|
+
this.#progressBarContainer.stop(); // Will fire internal stop event
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* Progress bar is only required when building projects. So we create it lazily
|
|
65
|
+
*/
|
|
66
|
+
_getProgressBar() {
|
|
67
|
+
// Do not use a progress bar if there is no text terminal attached or verbose logging is enabled
|
|
68
|
+
// * If log output is piped to a static output (= no TTY), no progress bar should be rendered
|
|
69
|
+
// * Since logging through the progress bar is asynchronous (controlled by the FPS setting),
|
|
70
|
+
// exceptions might lead to log messages being dropped. Therefore do not use a progress bar
|
|
71
|
+
// for verbose logging
|
|
72
|
+
// * If log-level is set to "silent", we should never render a progress bar
|
|
73
|
+
if (process.stderr.isTTY !== true || Logger.isLevelEnabled("verbose") || Logger.getLevel() === "silent") {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
if (!this.#progressBarContainer) {
|
|
77
|
+
// We use a "MultiBar" instance even though we intend to only render a single progress bar
|
|
78
|
+
// This is because only MultiBar provides a "log" method as of today
|
|
79
|
+
this.#progressBarContainer = new MultiBar({
|
|
80
|
+
format: `{bar} {message}`,
|
|
81
|
+
barsize: 20,
|
|
82
|
+
linewrap: true,
|
|
83
|
+
emptyOnZero: 0,
|
|
84
|
+
hideCursor: true,
|
|
85
|
+
|
|
86
|
+
// FPS also controls how fast a log message will be rendered above the progress bar
|
|
87
|
+
fps: 120,
|
|
88
|
+
|
|
89
|
+
// Disable progress bar explicitly for non-TTY, even though this is already checked above
|
|
90
|
+
noTTYOutput: false,
|
|
91
|
+
|
|
92
|
+
// Graceful exit is required to ensure all terminal settings (e.g. hideCursor)
|
|
93
|
+
// are restored on SIGINT
|
|
94
|
+
gracefulExit: true,
|
|
95
|
+
|
|
96
|
+
// Required to prevent flickering when logging
|
|
97
|
+
forceRedraw: true,
|
|
98
|
+
|
|
99
|
+
clearOnComplete: true,
|
|
100
|
+
stopOnComplete: true,
|
|
101
|
+
|
|
102
|
+
barCompleteChar: figures.square,
|
|
103
|
+
barIncompleteChar: figures.squareLightShade,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Initialize empty progress bar to enable logging through the multibar instance
|
|
107
|
+
this.#progressBar = this.#progressBarContainer.create(0, 0, {message: ""});
|
|
108
|
+
|
|
109
|
+
this.#progressBarContainer.on("stop", () => {
|
|
110
|
+
// Progress bar has finished and will remove itself from the output.
|
|
111
|
+
// Therefore, further logging needs to be done directly to process.stderr. Otherwise it would disappear.
|
|
112
|
+
// Therefore, we de-reference all instances now
|
|
113
|
+
this.#progressBarContainer = null;
|
|
114
|
+
this.#progressBar = null;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return this.#progressBar;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#writeMessage(level, message) {
|
|
121
|
+
if (!Logger.isLevelEnabled(level)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const levelPrefix = this.#getLevelPrefix(level);
|
|
125
|
+
const msg = `${levelPrefix} ${message}\n`;
|
|
126
|
+
|
|
127
|
+
if (this.#progressBarContainer) {
|
|
128
|
+
// If a progress bar is in use, we have to log through it's API
|
|
129
|
+
// cli-progress requires full control of the stderr output to ensure correct rendering
|
|
130
|
+
this.#progressBarContainer.log(msg);
|
|
131
|
+
} else {
|
|
132
|
+
process.stderr.write(msg);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
#handleLogEvent({level, message, moduleName}) {
|
|
137
|
+
this.#writeMessage(level, `${chalk.blue(moduleName)} ${message}`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#handleBuildMetadataEvent({projectsToBuild}) {
|
|
141
|
+
projectsToBuild.forEach((projectName) => {
|
|
142
|
+
this.#projectMetadata.set(projectName, {
|
|
143
|
+
buildStarted: false,
|
|
144
|
+
buildSkipped: false,
|
|
145
|
+
buildEnded: false,
|
|
146
|
+
buildStartIndex: null,
|
|
147
|
+
projectTasks: new Map(),
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
this.#updateProgressBarTotal();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
#handleProjectBuildMetadataEvent({tasksToRun, projectName, projectType}) {
|
|
154
|
+
const projectMetadata = this.#getProjectMetadata(projectName);
|
|
155
|
+
tasksToRun.forEach((taskName) => {
|
|
156
|
+
projectMetadata.projectTasks.set(taskName, {
|
|
157
|
+
executionStarted: false,
|
|
158
|
+
executionEnded: false,
|
|
159
|
+
executionStartIndex: null,
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
this.#updateProgressBarTotal();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
#getProjectMetadata(projectName) {
|
|
166
|
+
const projectMetadata = this.#projectMetadata.get(projectName);
|
|
167
|
+
if (!projectMetadata) {
|
|
168
|
+
throw new Error(`writers/Console: Unknown project ${projectName}`);
|
|
169
|
+
}
|
|
170
|
+
return projectMetadata;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
#updateProgressBarTotal() {
|
|
174
|
+
let numberOfTasks = 0;
|
|
175
|
+
this.#projectMetadata.forEach(({projectTasks}) => {
|
|
176
|
+
numberOfTasks += projectTasks.size;
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Project progress should weigh more than single task progress
|
|
180
|
+
// This is proportional to the number of projects (since that also multiplies the number of tasks)
|
|
181
|
+
this.#progressProjectWeight = this.#projectMetadata.size;
|
|
182
|
+
this._getProgressBar()?.setTotal(
|
|
183
|
+
(this.#progressProjectWeight * this.#projectMetadata.size) + numberOfTasks);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#handleBuildStatusEvent({level, projectName, projectType, status}) {
|
|
187
|
+
const projectMetadata = this.#getProjectMetadata(projectName);
|
|
188
|
+
if (projectMetadata.buildStartIndex === null) {
|
|
189
|
+
let nextIdx = 1;
|
|
190
|
+
this.#projectMetadata.forEach((metadata) => {
|
|
191
|
+
if (metadata.buildStartIndex !== null && metadata.buildStartIndex >= nextIdx) {
|
|
192
|
+
nextIdx = metadata.buildStartIndex + 1;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
projectMetadata.buildStartIndex = nextIdx;
|
|
196
|
+
}
|
|
197
|
+
const buildIndex = `Project ${projectMetadata.buildStartIndex} of ${this.#projectMetadata.size}`;
|
|
198
|
+
|
|
199
|
+
let message;
|
|
200
|
+
switch (status) {
|
|
201
|
+
case "project-build-start":
|
|
202
|
+
if (projectMetadata.buildEnded) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
`writers/Console: Unexpected project-build-start event for project ${projectName}. ` +
|
|
205
|
+
`Project build already ended`);
|
|
206
|
+
}
|
|
207
|
+
if (projectMetadata.buildStarted) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`writers/Console: Unexpected duplicate project-build-start event for project ${projectName}`);
|
|
210
|
+
}
|
|
211
|
+
if (projectMetadata.buildSkipped) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
`writers/Console: Unexpected project-build-start event for project ${projectName}. ` +
|
|
214
|
+
`Project build already skipped`);
|
|
215
|
+
}
|
|
216
|
+
projectMetadata.buildStarted = true;
|
|
217
|
+
message = `${chalk.blue(figures.pointer)} ` +
|
|
218
|
+
`Building ${projectType} project ${chalk.bold(projectName)}...`;
|
|
219
|
+
|
|
220
|
+
// Update progress bar message with current project
|
|
221
|
+
this._getProgressBar()?.update({
|
|
222
|
+
message: `${figures.pointer} Building ${projectType} project ${projectName}...`
|
|
223
|
+
});
|
|
224
|
+
break;
|
|
225
|
+
case "project-build-end":
|
|
226
|
+
if (projectMetadata.buildEnded) {
|
|
227
|
+
throw new Error(
|
|
228
|
+
`writers/Console: Unexpected duplicate project-build-end event for project ${projectName}`);
|
|
229
|
+
}
|
|
230
|
+
if (projectMetadata.buildSkipped) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
`writers/Console: Unexpected project-build-end event for project ${projectName}. ` +
|
|
233
|
+
`Project build already skipped`);
|
|
234
|
+
}
|
|
235
|
+
if (!projectMetadata.buildStarted) {
|
|
236
|
+
throw new Error(
|
|
237
|
+
`writers/Console: Unexpected project-build-end event for project ${projectName}. ` +
|
|
238
|
+
`No corresponding project-build-start event handled`);
|
|
239
|
+
}
|
|
240
|
+
projectMetadata.buildEnded = true;
|
|
241
|
+
message = `${chalk.green(figures.tick)} ` +
|
|
242
|
+
`Finished building ${projectType} project ${chalk.bold(projectName)}`;
|
|
243
|
+
|
|
244
|
+
// Update progress bar (if used)
|
|
245
|
+
this._getProgressBar()?.increment(this.#progressProjectWeight);
|
|
246
|
+
break;
|
|
247
|
+
case "project-build-skip":
|
|
248
|
+
if (projectMetadata.buildSkipped) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
`writers/Console: Unexpected duplicate project-build-skip event for project ${projectName}`);
|
|
251
|
+
}
|
|
252
|
+
if (projectMetadata.buildEnded) {
|
|
253
|
+
throw new Error(
|
|
254
|
+
`writers/Console: Unexpected project-build-skip event for project ${projectName}. ` +
|
|
255
|
+
`Project build already ended`);
|
|
256
|
+
}
|
|
257
|
+
if (projectMetadata.buildStarted) {
|
|
258
|
+
throw new Error(
|
|
259
|
+
`writers/Console: Unexpected project-build-skip event for project ${projectName}. ` +
|
|
260
|
+
`Project build already started`);
|
|
261
|
+
}
|
|
262
|
+
projectMetadata.buildSkipped = true;
|
|
263
|
+
message = `${chalk.yellow(figures.tick)} ` +
|
|
264
|
+
`Skipping build of ${projectType} project ${chalk.bold(projectName)}`;
|
|
265
|
+
|
|
266
|
+
// Update progress bar (if used)
|
|
267
|
+
// All tasks of this projects are completed
|
|
268
|
+
this._getProgressBar()?.increment(this.#progressProjectWeight + projectMetadata.projectTasks.size);
|
|
269
|
+
break;
|
|
270
|
+
default:
|
|
271
|
+
this.#writeMessage("verbose",
|
|
272
|
+
`writers/Console: Received unknown build-status ${status} for project ${projectName}`);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
this.#writeMessage(level, `${chalk.grey(buildIndex)}: ${message}`);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
#handleProjectBuildStatusEvent({level, projectName, projectType, taskName, status}) {
|
|
280
|
+
const {projectTasks} = this.#getProjectMetadata(projectName);
|
|
281
|
+
const taskMetadata = projectTasks.get(taskName);
|
|
282
|
+
if (!taskMetadata) {
|
|
283
|
+
throw new Error(`writers/Console: Unknown task ${taskName} for project ${projectName}`);
|
|
284
|
+
}
|
|
285
|
+
if (taskMetadata.executionStartIndex === null) {
|
|
286
|
+
let nextIdx = 1;
|
|
287
|
+
projectTasks.forEach((metadata) => {
|
|
288
|
+
if (metadata.executionStartIndex !== null && metadata.executionStartIndex >= nextIdx) {
|
|
289
|
+
nextIdx = metadata.executionStartIndex + 1;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
taskMetadata.executionStartIndex = nextIdx;
|
|
293
|
+
}
|
|
294
|
+
let taskIndex = "";
|
|
295
|
+
if (Logger.isLevelEnabled("verbose")) {
|
|
296
|
+
taskIndex = chalk.grey(`Task ${taskMetadata.executionStartIndex} of ${projectTasks.size} `);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
let message;
|
|
300
|
+
switch (status) {
|
|
301
|
+
case "task-start":
|
|
302
|
+
if (taskMetadata.executionEnded) {
|
|
303
|
+
throw new Error(
|
|
304
|
+
`writers/Console: Unexpected task-start event for project ${projectName}, task ${taskName}. ` +
|
|
305
|
+
`Task execution already ended`);
|
|
306
|
+
}
|
|
307
|
+
if (taskMetadata.executionStarted) {
|
|
308
|
+
throw new Error(`writers/Console: Unexpected duplicate task-start event ` +
|
|
309
|
+
`for project ${projectName}, task ${taskName}`);
|
|
310
|
+
}
|
|
311
|
+
taskMetadata.executionStarted = true;
|
|
312
|
+
message = `${chalk.blue(figures.pointerSmall)} Running task ${chalk.bold(taskName)}...`;
|
|
313
|
+
break;
|
|
314
|
+
case "task-end":
|
|
315
|
+
if (taskMetadata.executionEnded) {
|
|
316
|
+
throw new Error(`writers/Console: ` +
|
|
317
|
+
`Unexpected duplicate task-end event for project ${projectName}, task ${taskName}`);
|
|
318
|
+
}
|
|
319
|
+
if (!taskMetadata.executionStarted) {
|
|
320
|
+
throw new Error(
|
|
321
|
+
`writers/Console: Unexpected task-end event for project ${projectName}, task ${taskName}. ` +
|
|
322
|
+
`No corresponding task-start event handled`);
|
|
323
|
+
}
|
|
324
|
+
taskMetadata.executionEnded = true;
|
|
325
|
+
message = `${chalk.green(figures.tick)} Finished task ${chalk.bold(taskName)}`;
|
|
326
|
+
|
|
327
|
+
// Update progress bar (if used)
|
|
328
|
+
this._getProgressBar()?.increment(1);
|
|
329
|
+
break;
|
|
330
|
+
default:
|
|
331
|
+
this.#writeMessage("verbose",
|
|
332
|
+
`writers/Console: Received unknown project-build-status ${status} for project ${projectName}`);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
this.#writeMessage(level, `${chalk.blue(`${(projectName)}`)} ${taskIndex}${message}`);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
#getLevelPrefix(level) {
|
|
340
|
+
switch (level) {
|
|
341
|
+
case "silly":
|
|
342
|
+
return chalk.inverse(level);
|
|
343
|
+
case "verbose":
|
|
344
|
+
return chalk.cyan("verb");
|
|
345
|
+
case "perf":
|
|
346
|
+
return chalk.bgYellow.red(level);
|
|
347
|
+
case "info":
|
|
348
|
+
return chalk.green(level);
|
|
349
|
+
case "warn":
|
|
350
|
+
return chalk.yellow(level);
|
|
351
|
+
case "error":
|
|
352
|
+
return chalk.bgRed.white(level);
|
|
353
|
+
// Log level silent does not produce messages
|
|
354
|
+
default:
|
|
355
|
+
return level;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Creates a new instance and subscribes it to all events
|
|
361
|
+
*
|
|
362
|
+
* @public
|
|
363
|
+
*/
|
|
364
|
+
static init() {
|
|
365
|
+
const cH = new Console();
|
|
366
|
+
cH.enable();
|
|
367
|
+
return cH;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export default Console;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui5/logger",
|
|
3
|
-
"version": "3.0.1-rc.
|
|
3
|
+
"version": "3.0.1-rc.2",
|
|
4
4
|
"description": "UI5 Tooling - Internal Logger",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SAP SE",
|
|
@@ -18,8 +18,11 @@
|
|
|
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
28
|
"node": "^16.18.0 || >=18.0.0",
|
|
@@ -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\"",
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
"version": "git-chglog --sort semver --next-tag v$npm_package_version -o CHANGELOG.md && 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.1.
|
|
118
|
+
"ava": "^5.1.1",
|
|
116
119
|
"chokidar-cli": "^3.0.0",
|
|
117
120
|
"cross-env": "^7.0.3",
|
|
118
121
|
"depcheck": "^1.4.3",
|
|
119
|
-
"docdash": "^2.0.
|
|
120
|
-
"eslint": "^8.
|
|
122
|
+
"docdash": "^2.0.1",
|
|
123
|
+
"eslint": "^8.32.0",
|
|
121
124
|
"eslint-config-google": "^0.14.0",
|
|
122
|
-
"eslint-plugin-ava": "^
|
|
123
|
-
"eslint-plugin-jsdoc": "^39.6.
|
|
124
|
-
"esmock": "^2.1.0",
|
|
125
|
+
"eslint-plugin-ava": "^14.0.0",
|
|
126
|
+
"eslint-plugin-jsdoc": "^39.6.7",
|
|
125
127
|
"jsdoc": "^3.6.11",
|
|
126
128
|
"nyc": "^15.1.0",
|
|
127
129
|
"open-cli": "^7.1.0",
|
|
128
|
-
"rimraf": "^
|
|
130
|
+
"rimraf": "^4.1.1",
|
|
129
131
|
"sinon": "^15.0.1",
|
|
130
|
-
"
|
|
132
|
+
"strip-ansi": "^7.0.1",
|
|
131
133
|
"tap-xunit": "^2.4.1"
|
|
132
134
|
}
|
|
133
135
|
}
|
package/lib/logger.js
DELETED
|
@@ -1,136 +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
|
-
const substitutionPlaceholders = /%[oOdisfc]/g;
|
|
43
|
-
function handleLogArguments(mode, messages) {
|
|
44
|
-
if (messages.length > 1) {
|
|
45
|
-
messages[0] = messages[0].replaceAll(substitutionPlaceholders, "<deprecated string substitution char>");
|
|
46
|
-
}
|
|
47
|
-
if (messages.length > 2) {
|
|
48
|
-
console.log(`⚠️ @ui5/logger: Deprecated log.${mode}() call with multiple arguments. ` +
|
|
49
|
-
`@ui5/logger version 3 does not accept more than two argument. Call stack of this invocation:`);
|
|
50
|
-
console.trace();
|
|
51
|
-
return [messages[0], messages[1]];
|
|
52
|
-
}
|
|
53
|
-
return messages;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
class Logger {
|
|
57
|
-
constructor(moduleName) {
|
|
58
|
-
this._moduleName = moduleName;
|
|
59
|
-
this._logger = npmlog;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
isLevelEnabled(levelName) {
|
|
63
|
-
return logger.isLevelEnabled(levelName);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
silly(...messages) {
|
|
67
|
-
return this._logger.silly(this._moduleName, ...handleLogArguments("silly", messages));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
verbose(...messages) {
|
|
71
|
-
return this._logger.verbose(this._moduleName, ...handleLogArguments("verbose", messages));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
perf(...messages) {
|
|
75
|
-
return this._logger.perf(this._moduleName, ...handleLogArguments("perf", messages));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
info(...messages) {
|
|
79
|
-
return this._logger.info(this._moduleName, ...handleLogArguments("info", messages));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
warn(...messages) {
|
|
83
|
-
return this._logger.warn(this._moduleName, ...handleLogArguments("warn", messages));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
error(...messages) {
|
|
87
|
-
return this._logger.error(this._moduleName, ...handleLogArguments("error", messages));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
_getLogger() {
|
|
91
|
-
// TODO 3.0: Remove this function
|
|
92
|
-
console.log("⚠️ Deprecated call to Logger#_getLogger. " +
|
|
93
|
-
"Internal method Logger#_getLogger has been deprecated and will be removed.");
|
|
94
|
-
console.trace();
|
|
95
|
-
return this._logger;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const logger = {
|
|
100
|
-
getLogger: function(moduleName) {
|
|
101
|
-
return new Logger(moduleName);
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
getGroupLogger: function(moduleName) {
|
|
105
|
-
// TODO 3.0: Remove this function
|
|
106
|
-
throw new Error("Deprecated call to @ui5/logger#getGroupLogger. " +
|
|
107
|
-
"This function has been deprecated in @ui5/logger version 3 and will be " +
|
|
108
|
-
"removed in the final release");
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
setLevel(level) {
|
|
112
|
-
if (!levels.includes(level)) {
|
|
113
|
-
throw new Error(`Unknown log level "${level}"`);
|
|
114
|
-
}
|
|
115
|
-
return npmlog.level = level;
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
isLevelEnabled,
|
|
119
|
-
|
|
120
|
-
setShowProgress(showProgress) {
|
|
121
|
-
// TODO 3.0: Remove this function
|
|
122
|
-
throw new Error("Deprecated call to @ui5/logger#setShowProgress. " +
|
|
123
|
-
"This function has been deprecated in @ui5/logger version 3 and will be " +
|
|
124
|
-
"removed in the final release");
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
// Export internal classes for testing only
|
|
129
|
-
/* istanbul ignore else */
|
|
130
|
-
if (process.env.NODE_ENV === "test") {
|
|
131
|
-
logger.__test__ = {
|
|
132
|
-
Logger
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export default logger;
|