diff --git a/package-lock.json b/package-lock.json index 70473ce..8fd4b3b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1718,6 +1718,11 @@ "@types/lodash": "*" } }, + "@types/loglevel": { + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/@types/loglevel/-/loglevel-1.5.4.tgz", + "integrity": "sha512-8dx4ckP0vndJeN+iKZwdGiapLqFjVQ3JLOt92uqK0C63acs5NcPLbUOpfXCJkKVRjZLBQjw8NIGNBSsnatFnFQ==" + }, "@types/marked": { "version": "0.4.2", "resolved": "https://registry.npmjs.org/@types/marked/-/marked-0.4.2.tgz", @@ -6859,6 +6864,11 @@ "integrity": "sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg==", "dev": true }, + "loglevel": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.6.1.tgz", + "integrity": "sha1-4PyVEztu8nbNyIh82vJKpvFW+Po=" + }, "longest": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", diff --git a/package.json b/package.json index 717870a..a40161f 100644 --- a/package.json +++ b/package.json @@ -100,8 +100,10 @@ "typescript": "^3.4.2" }, "dependencies": { + "@types/loglevel": "^1.5.4", "find-up": "^3.0.0", "lodash.clone": "^4.5.0", + "loglevel": "^1.6.1", "pify": "^4.0.1", "spawn-command": "0.0.2-1" }, diff --git a/src/constants.ts b/src/constants.ts index 9e2a8f7..fdc33d1 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,6 @@ // Default configuration file name export const FILE_NAME = 'kpo.scripts'; +// Default logging level +export const DEFAULT_LOG_LEVEL = 'info'; // Default stdio for spawned commands export const DEFAULT_STDIO = 'inherit'; diff --git a/src/index.ts b/src/index.ts index 8a1285f..fcb073f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export default function main(): void {} +export * from './types'; diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..41b8e28 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,3 @@ +import { LogLevelDesc } from 'loglevel'; + +export type TLogger = LogLevelDesc; diff --git a/src/utils/logger.ts b/src/utils/logger.ts new file mode 100644 index 0000000..c82c1ca --- /dev/null +++ b/src/utils/logger.ts @@ -0,0 +1,11 @@ +import loglevel from 'loglevel'; +import { DEFAULT_LOG_LEVEL } from '~/constants'; +import { TLogger } from '~/types'; + +const logger = loglevel.getLogger('_kpo_logger_'); +logger.setDefaultLevel(DEFAULT_LOG_LEVEL); + +export default logger; +export function setLevel(level: TLogger): void { + logger.setLevel(level); +}