@release-change/logger 0.1.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/LICENSE +21 -0
- package/README.md +34 -0
- package/dist/add-error-to-context.d.ts +8 -0
- package/dist/add-error-to-context.d.ts.map +1 -0
- package/dist/add-error-to-context.js +20 -0
- package/dist/add-error-to-context.js.map +1 -0
- package/dist/check-error-type.d.ts +7 -0
- package/dist/check-error-type.d.ts.map +1 -0
- package/dist/check-error-type.js +11 -0
- package/dist/check-error-type.js.map +1 -0
- package/dist/format-message.d.ts +15 -0
- package/dist/format-message.d.ts.map +1 -0
- package/dist/format-message.js +25 -0
- package/dist/format-message.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/is-detailed-error.d.ts +8 -0
- package/dist/is-detailed-error.d.ts.map +1 -0
- package/dist/is-detailed-error.js +19 -0
- package/dist/is-detailed-error.js.map +1 -0
- package/dist/logger.types.d.ts +22 -0
- package/dist/logger.types.d.ts.map +1 -0
- package/dist/logger.types.js +2 -0
- package/dist/logger.types.js.map +1 -0
- package/dist/set-logger.d.ts +8 -0
- package/dist/set-logger.d.ts.map +1 -0
- package/dist/set-logger.js +42 -0
- package/dist/set-logger.js.map +1 -0
- package/dist/set-prefix.d.ts +15 -0
- package/dist/set-prefix.d.ts.map +1 -0
- package/dist/set-prefix.js +32 -0
- package/dist/set-prefix.js.map +1 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Victor Brito
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @release-change/logger
|
|
2
|
+
|
|
3
|
+
Print messages in the terminal for release-change
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
[](https://nodejs.org/api/esm.html)
|
|
7
|
+
[](https://conventionalcommits.org)
|
|
8
|
+
[](https://biomejs.dev/)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { setLogger } from "@release-change/logger";
|
|
17
|
+
|
|
18
|
+
const logger = setLogger();
|
|
19
|
+
logger.logSuccess("Everything done successfully.");
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## `setLogger` methods
|
|
23
|
+
|
|
24
|
+
- `setScope`: to print the scope concerned by any non-debug messages,
|
|
25
|
+
- `setDebugScope`: to print the scope concerned by any debug messages,
|
|
26
|
+
- `logDebug`: to print debug messages (`setLogger()` must be called with the `isDebug` argument set to `true`),
|
|
27
|
+
- `logInfo`: to print informational messages,
|
|
28
|
+
- `logError`: to print error messages,
|
|
29
|
+
- `logWarn`: to print warning messages,
|
|
30
|
+
- `logSuccess`: to assert to users that their instructions have completed successfully.
|
|
31
|
+
|
|
32
|
+
## Copyright & licence
|
|
33
|
+
|
|
34
|
+
© 2025-present Victor Brito — Released under the [MIT licence](./LICENSE).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Context, ContextBase } from "@release-change/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Adds an error to the context.
|
|
4
|
+
* @param error - The error to add.
|
|
5
|
+
* @param context - The context where the CLI is running.
|
|
6
|
+
*/
|
|
7
|
+
export declare const addErrorToContext: (error: unknown, context: Context | ContextBase) => void;
|
|
8
|
+
//# sourceMappingURL=add-error-to-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-error-to-context.d.ts","sourceRoot":"","sources":["../src/add-error-to-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAInE;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,OAAO,EAAE,SAAS,OAAO,GAAG,WAAW,KAAG,IAYlF,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isDetailedError } from "./is-detailed-error.js";
|
|
2
|
+
/**
|
|
3
|
+
* Adds an error to the context.
|
|
4
|
+
* @param error - The error to add.
|
|
5
|
+
* @param context - The context where the CLI is running.
|
|
6
|
+
*/
|
|
7
|
+
export const addErrorToContext = (error, context) => {
|
|
8
|
+
if (error instanceof Error) {
|
|
9
|
+
const { cause } = error;
|
|
10
|
+
if (cause && isDetailedError(cause)) {
|
|
11
|
+
const { title, message, details } = cause;
|
|
12
|
+
context.errors.push({
|
|
13
|
+
title,
|
|
14
|
+
message,
|
|
15
|
+
details
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=add-error-to-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-error-to-context.js","sourceRoot":"","sources":["../src/add-error-to-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAE,OAA8B,EAAQ,EAAE;IACxF,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QACxB,IAAI,KAAK,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;YACpC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;YAC1C,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;gBAClB,KAAK;gBACL,OAAO;gBACP,OAAO;aACR,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks the error type.
|
|
3
|
+
* @param error - The error caught.
|
|
4
|
+
* @return The message from the `message` property if `error` is an instance of `Error`, the error itself within a string otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare const checkErrorType: (error: unknown) => string;
|
|
7
|
+
//# sourceMappingURL=check-error-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-error-type.d.ts","sourceRoot":"","sources":["../src/check-error-type.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,KAAG,MAG/C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks the error type.
|
|
3
|
+
* @param error - The error caught.
|
|
4
|
+
* @return The message from the `message` property if `error` is an instance of `Error`, the error itself within a string otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export const checkErrorType = (error) => {
|
|
7
|
+
if (error instanceof Error)
|
|
8
|
+
return error.message;
|
|
9
|
+
return `Unknown error: ${error}`;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=check-error-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-error-type.js","sourceRoot":"","sources":["../src/check-error-type.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAc,EAAU,EAAE;IACvD,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjD,OAAO,kBAAkB,KAAK,EAAE,CAAC;AACnC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LoggerContext } from "./logger.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Formats the message according to the context provided by `loggerContext`:
|
|
4
|
+
* - if the debug mode is activated, the message is formatted with the prefix;
|
|
5
|
+
* - otherwise, the message is formatted with the prefix and the appropriate symbol according to its type:
|
|
6
|
+
* - `\u2139` if the message is of type `info`,
|
|
7
|
+
* - `\u2718` if the message is of type `error`,
|
|
8
|
+
* - `\u26a0` if the message is of type `warn`,
|
|
9
|
+
* - `\u2714` if the message is of type `success`.
|
|
10
|
+
* @param message - The message to format.
|
|
11
|
+
* @param loggerContext - The logger context: whether the debug mode is activated or not, what scope is concerned (optional) and the message type (optional).
|
|
12
|
+
* @return The formatted message.
|
|
13
|
+
*/
|
|
14
|
+
export declare const formatMessage: (message: string, loggerContext: LoggerContext) => string;
|
|
15
|
+
//# sourceMappingURL=format-message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-message.d.ts","sourceRoot":"","sources":["../src/format-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAsB,MAAM,mBAAmB,CAAC;AAI3E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,EAAE,eAAe,aAAa,KAAG,MAU7E,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { setPrefix } from "./set-prefix.js";
|
|
2
|
+
/**
|
|
3
|
+
* Formats the message according to the context provided by `loggerContext`:
|
|
4
|
+
* - if the debug mode is activated, the message is formatted with the prefix;
|
|
5
|
+
* - otherwise, the message is formatted with the prefix and the appropriate symbol according to its type:
|
|
6
|
+
* - `\u2139` if the message is of type `info`,
|
|
7
|
+
* - `\u2718` if the message is of type `error`,
|
|
8
|
+
* - `\u26a0` if the message is of type `warn`,
|
|
9
|
+
* - `\u2714` if the message is of type `success`.
|
|
10
|
+
* @param message - The message to format.
|
|
11
|
+
* @param loggerContext - The logger context: whether the debug mode is activated or not, what scope is concerned (optional) and the message type (optional).
|
|
12
|
+
* @return The formatted message.
|
|
13
|
+
*/
|
|
14
|
+
export const formatMessage = (message, loggerContext) => {
|
|
15
|
+
const prefix = setPrefix(Date.now(), loggerContext);
|
|
16
|
+
const symbols = {
|
|
17
|
+
info: "\u2139",
|
|
18
|
+
error: "\u2718",
|
|
19
|
+
warn: "\u26a0",
|
|
20
|
+
success: "\u2714"
|
|
21
|
+
};
|
|
22
|
+
const { type } = loggerContext;
|
|
23
|
+
return type ? `${prefix} ${symbols[type]} ${message}` : `${prefix} ${message}`;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=format-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-message.js","sourceRoot":"","sources":["../src/format-message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAe,EAAE,aAA4B,EAAU,EAAE;IACrF,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAC;IACpD,MAAM,OAAO,GAAuB;QAClC,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,QAAQ;QACf,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,QAAQ;KAClB,CAAC;IACF,MAAM,EAAE,IAAI,EAAE,GAAG,aAAa,CAAC;IAC/B,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC;AACjF,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { Logger } from "./logger.types.js";
|
|
2
|
+
export { addErrorToContext } from "./add-error-to-context.js";
|
|
3
|
+
export { checkErrorType } from "./check-error-type.js";
|
|
4
|
+
export { isDetailedError } from "./is-detailed-error.js";
|
|
5
|
+
export { setLogger } from "./set-logger.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DetailedError } from "@release-change/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Checks if an unknown value satisfies the `DetailedError` type.
|
|
4
|
+
* @param value - The value to check.
|
|
5
|
+
* @return `true` if the value is of type `DetailedError`, `false` otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isDetailedError: (value: unknown) => value is DetailedError;
|
|
8
|
+
//# sourceMappingURL=is-detailed-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-detailed-error.d.ts","sourceRoot":"","sources":["../src/is-detailed-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,aAazD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if an unknown value satisfies the `DetailedError` type.
|
|
3
|
+
* @param value - The value to check.
|
|
4
|
+
* @return `true` if the value is of type `DetailedError`, `false` otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export const isDetailedError = (value) => {
|
|
7
|
+
if (!value || typeof value !== "object")
|
|
8
|
+
return false;
|
|
9
|
+
const candidate = value;
|
|
10
|
+
const { title, message, details } = candidate;
|
|
11
|
+
return (typeof title === "string" &&
|
|
12
|
+
typeof message === "string" &&
|
|
13
|
+
typeof details === "object" &&
|
|
14
|
+
details !== null &&
|
|
15
|
+
typeof candidate.details.output === "string" &&
|
|
16
|
+
(typeof candidate.details.command === "string" ||
|
|
17
|
+
candidate.details.command === undefined));
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=is-detailed-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-detailed-error.js","sourceRoot":"","sources":["../src/is-detailed-error.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAc,EAA0B,EAAE;IACxE,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,SAAS,GAAG,KAAgC,CAAC;IACnD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;IAC9C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,KAAK,IAAI;QAChB,OAAQ,SAAS,CAAC,OAAmC,CAAC,MAAM,KAAK,QAAQ;QACzE,CAAC,OAAQ,SAAS,CAAC,OAAmC,CAAC,OAAO,KAAK,QAAQ;YACxE,SAAS,CAAC,OAAmC,CAAC,OAAO,KAAK,SAAS,CAAC,CACxE,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type ScopeFunction = (scope: string) => string;
|
|
2
|
+
type LoggerFunction = (message: string) => void;
|
|
3
|
+
export type LoggerContext = {
|
|
4
|
+
isDebug: boolean;
|
|
5
|
+
scope?: string;
|
|
6
|
+
debugScope?: string;
|
|
7
|
+
type?: MessageType;
|
|
8
|
+
};
|
|
9
|
+
type MessageType = "info" | "error" | "warn" | "success";
|
|
10
|
+
export type MessageTypeSymbols = Record<MessageType, string>;
|
|
11
|
+
export type Logger = {
|
|
12
|
+
setScope: ScopeFunction;
|
|
13
|
+
setDebugScope: ScopeFunction;
|
|
14
|
+
logDebug: LoggerFunction;
|
|
15
|
+
logInfo: LoggerFunction;
|
|
16
|
+
logError: LoggerFunction;
|
|
17
|
+
logWarn: LoggerFunction;
|
|
18
|
+
logSuccess: LoggerFunction;
|
|
19
|
+
logWithoutFormatting: LoggerFunction;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=logger.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.types.d.ts","sourceRoot":"","sources":["../src/logger.types.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;AAC/C,KAAK,cAAc,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAChD,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB,CAAC;AACF,KAAK,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AACzD,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AAC7D,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,aAAa,CAAC;IACxB,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;IACxB,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;IACxB,UAAU,EAAE,cAAc,CAAC;IAC3B,oBAAoB,EAAE,cAAc,CAAC;CACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.types.js","sourceRoot":"","sources":["../src/logger.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Logger } from "./logger.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Sets the logger object.
|
|
4
|
+
* @param [isDebug] - Whether the debug mode is activated or not.
|
|
5
|
+
* @return The logger object.
|
|
6
|
+
*/
|
|
7
|
+
export declare const setLogger: (isDebug?: boolean) => Logger;
|
|
8
|
+
//# sourceMappingURL=set-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-logger.d.ts","sourceRoot":"","sources":["../src/set-logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIhD;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,iBAAe,KAAG,MA2C3C,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { formatMessage } from "./format-message.js";
|
|
2
|
+
/**
|
|
3
|
+
* Sets the logger object.
|
|
4
|
+
* @param [isDebug] - Whether the debug mode is activated or not.
|
|
5
|
+
* @return The logger object.
|
|
6
|
+
*/
|
|
7
|
+
export const setLogger = (isDebug = false) => {
|
|
8
|
+
const loggerContext = {
|
|
9
|
+
isDebug
|
|
10
|
+
};
|
|
11
|
+
let normalScope = "";
|
|
12
|
+
let debugScope = "";
|
|
13
|
+
return {
|
|
14
|
+
setScope: (scope) => {
|
|
15
|
+
normalScope = scope;
|
|
16
|
+
return scope;
|
|
17
|
+
},
|
|
18
|
+
setDebugScope: (scope) => {
|
|
19
|
+
debugScope = scope;
|
|
20
|
+
return scope;
|
|
21
|
+
},
|
|
22
|
+
logDebug: (message) => {
|
|
23
|
+
console.debug(formatMessage(message, { ...loggerContext, debugScope: debugScope }));
|
|
24
|
+
},
|
|
25
|
+
logInfo: (message) => {
|
|
26
|
+
console.info(formatMessage(message, { ...loggerContext, scope: normalScope, type: "info" }));
|
|
27
|
+
},
|
|
28
|
+
logError: (message) => {
|
|
29
|
+
console.error("\x1b[1;31m%s\x1b[0m", formatMessage(message, { ...loggerContext, scope: normalScope, type: "error" }));
|
|
30
|
+
},
|
|
31
|
+
logWarn: (message) => {
|
|
32
|
+
console.warn("\x1b[33m%s\x1b[0m", formatMessage(message, { ...loggerContext, scope: normalScope, type: "warn" }));
|
|
33
|
+
},
|
|
34
|
+
logSuccess: (message) => {
|
|
35
|
+
console.log("\x1b[32m%s\x1b[0m", formatMessage(message, { ...loggerContext, scope: normalScope, type: "success" }));
|
|
36
|
+
},
|
|
37
|
+
logWithoutFormatting: (message) => {
|
|
38
|
+
console.log(message);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=set-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-logger.js","sourceRoot":"","sources":["../src/set-logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAO,GAAG,KAAK,EAAU,EAAE;IACnD,MAAM,aAAa,GAAG;QACpB,OAAO;KACR,CAAC;IACF,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,OAAO;QACL,QAAQ,EAAE,CAAC,KAAa,EAAU,EAAE;YAClC,WAAW,GAAG,KAAK,CAAC;YACpB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,aAAa,EAAE,CAAC,KAAa,EAAU,EAAE;YACvC,UAAU,GAAG,KAAK,CAAC;YACnB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,QAAQ,EAAE,CAAC,OAAe,EAAQ,EAAE;YAClC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,GAAG,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;QACtF,CAAC;QACD,OAAO,EAAE,CAAC,OAAe,EAAQ,EAAE;YACjC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,GAAG,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QAC/F,CAAC;QACD,QAAQ,EAAE,CAAC,OAAe,EAAQ,EAAE;YAClC,OAAO,CAAC,KAAK,CACX,qBAAqB,EACrB,aAAa,CAAC,OAAO,EAAE,EAAE,GAAG,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAChF,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,CAAC,OAAe,EAAQ,EAAE;YACjC,OAAO,CAAC,IAAI,CACV,mBAAmB,EACnB,aAAa,CAAC,OAAO,EAAE,EAAE,GAAG,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAC/E,CAAC;QACJ,CAAC;QACD,UAAU,EAAE,CAAC,OAAe,EAAQ,EAAE;YACpC,OAAO,CAAC,GAAG,CACT,mBAAmB,EACnB,aAAa,CAAC,OAAO,EAAE,EAAE,GAAG,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAClF,CAAC;QACJ,CAAC;QACD,oBAAoB,EAAE,CAAC,OAAe,EAAQ,EAAE;YAC9C,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LoggerContext } from "./logger.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Sets prefix for messages logged to the console according to the context provided by `loggerContext`:
|
|
4
|
+
* - if the debug mode is activated and `debugScope` is defined as a string (even empty), the prefix uses one of the following formats:
|
|
5
|
+
* -`\x1b[1;34m[debug] <package name>\x1b[0m`,
|
|
6
|
+
* -`\x1b[1;34m[debug] <package name>:<scope name>\x1b[0m`;
|
|
7
|
+
* - otherwise, the prefix uses one of the following formats:
|
|
8
|
+
* -`[HH:MM:SS] [<package name>] \u203a`,
|
|
9
|
+
* -`[HH:MM:SS] [<package name>] [@<package name>/<scope name>] \u203a`.
|
|
10
|
+
* @param timestamp - The timestamp when the message is logged.
|
|
11
|
+
* @param loggerContext - The logger context (whether the debug mode is activated or not, what scope is concerned).
|
|
12
|
+
* @return The prefix in the appropriate format.
|
|
13
|
+
*/
|
|
14
|
+
export declare const setPrefix: (timestamp: number, loggerContext: LoggerContext) => string;
|
|
15
|
+
//# sourceMappingURL=set-prefix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-prefix.d.ts","sourceRoot":"","sources":["../src/set-prefix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,GAAI,WAAW,MAAM,EAAE,eAAe,aAAa,KAAG,MAe3E,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WORKSPACE_NAME } from "@release-change/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Sets prefix for messages logged to the console according to the context provided by `loggerContext`:
|
|
4
|
+
* - if the debug mode is activated and `debugScope` is defined as a string (even empty), the prefix uses one of the following formats:
|
|
5
|
+
* -`\x1b[1;34m[debug] <package name>\x1b[0m`,
|
|
6
|
+
* -`\x1b[1;34m[debug] <package name>:<scope name>\x1b[0m`;
|
|
7
|
+
* - otherwise, the prefix uses one of the following formats:
|
|
8
|
+
* -`[HH:MM:SS] [<package name>] \u203a`,
|
|
9
|
+
* -`[HH:MM:SS] [<package name>] [@<package name>/<scope name>] \u203a`.
|
|
10
|
+
* @param timestamp - The timestamp when the message is logged.
|
|
11
|
+
* @param loggerContext - The logger context (whether the debug mode is activated or not, what scope is concerned).
|
|
12
|
+
* @return The prefix in the appropriate format.
|
|
13
|
+
*/
|
|
14
|
+
export const setPrefix = (timestamp, loggerContext) => {
|
|
15
|
+
const { isDebug, scope, debugScope } = loggerContext;
|
|
16
|
+
if (isDebug && typeof debugScope === "string") {
|
|
17
|
+
if (debugScope)
|
|
18
|
+
return `\x1b[1;34m[debug] ${WORKSPACE_NAME}:${debugScope}\x1b[0m`;
|
|
19
|
+
return `\x1b[1;34m[debug] ${WORKSPACE_NAME}\x1b[0m`;
|
|
20
|
+
}
|
|
21
|
+
const time = Intl.DateTimeFormat(undefined, {
|
|
22
|
+
hour: "2-digit",
|
|
23
|
+
minute: "2-digit",
|
|
24
|
+
second: "2-digit",
|
|
25
|
+
hour12: false,
|
|
26
|
+
timeZone: "UTC"
|
|
27
|
+
}).format(timestamp);
|
|
28
|
+
if (scope)
|
|
29
|
+
return `[${time}] [${WORKSPACE_NAME}] [@${WORKSPACE_NAME}/${scope}] \u203a`;
|
|
30
|
+
return `[${time}] [${WORKSPACE_NAME}] \u203a`;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=set-prefix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-prefix.js","sourceRoot":"","sources":["../src/set-prefix.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,SAAiB,EAAE,aAA4B,EAAU,EAAE;IACnF,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;IACrD,IAAI,OAAO,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC9C,IAAI,UAAU;YAAE,OAAO,qBAAqB,cAAc,IAAI,UAAU,SAAS,CAAC;QAClF,OAAO,qBAAqB,cAAc,SAAS,CAAC;IACtD,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE;QAC1C,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACrB,IAAI,KAAK;QAAE,OAAO,IAAI,IAAI,MAAM,cAAc,OAAO,cAAc,IAAI,KAAK,UAAU,CAAC;IACvF,OAAO,IAAI,IAAI,MAAM,cAAc,UAAU,CAAC;AAChD,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@release-change/logger",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Print messages in the terminal for release-change",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"homepage": "https://github.com/release-change/release-change",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/release-change/release-change/issues"
|
|
9
|
+
},
|
|
10
|
+
"author": "Victor Brito (https://victor-brito.dev)",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/release-change/release-change.git"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": "^20.18.3 || ^22.12.0 || ^24.0.0",
|
|
26
|
+
"npm": ">=10.8.2",
|
|
27
|
+
"pnpm": ">=10.28.0"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@release-change/shared": "0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"dev": "tsc --watch --preserveWatchOutput & vitest"
|
|
35
|
+
}
|
|
36
|
+
}
|