From 34b6c9b16e4bcd042d032261f2b4564469301ff6 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Wed, 22 Sep 2021 16:21:12 +0300 Subject: [PATCH] Made logger interface --- package-lock.json | 5 +++++ package.json | 4 +++- src/utils/logger-utils.ts | 33 +++++++++++++++++++++++++++++++++ src/utils/logger.ts | 7 +++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/utils/logger-utils.ts create mode 100644 src/utils/logger.ts diff --git a/package-lock.json b/package-lock.json index 6aec70b..32dbc70 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,11 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@actions/core": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.5.0.tgz", + "integrity": "sha512-eDOLH1Nq9zh+PJlYLqEMkS/jLQxhksPNmUGNBHfa4G+tQmnIhzpctxmchETtVGyBOvXgOVVpYuE40+eS4cUnwQ==" + }, "@babel/code-frame": { "version": "7.12.11", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.11.tgz", diff --git a/package.json b/package.json index feeb928..ccabf0a 100644 --- a/package.json +++ b/package.json @@ -38,5 +38,7 @@ "jest": "^27.2.2", "typescript": "^4.4.3" }, - "dependencies": {} + "dependencies": { + "@actions/core": "^1.5.0" + } } diff --git a/src/utils/logger-utils.ts b/src/utils/logger-utils.ts new file mode 100644 index 0000000..a755b22 --- /dev/null +++ b/src/utils/logger-utils.ts @@ -0,0 +1,33 @@ +import * as actions from "@actions/core"; +import * as console from "console"; +import Logger from "./logger"; + +export function getDefaultLogger(): Logger { + return { + fatal: actions.setFailed, + error: actions.warning, + warn: actions.warning, + info: actions.info, + debug: actions.debug + }; +} + +export function getConsoleLogger(): Logger { + return { + fatal: console.error, + error: console.error, + warn: console.warn, + info: console.info, + debug: console.debug + }; +} + +export function getEmptyLogger(): Logger { + return { + fatal: () => {}, + error: () => {}, + warn: () => {}, + info: () => {}, + debug: () => {} + }; +} diff --git a/src/utils/logger.ts b/src/utils/logger.ts new file mode 100644 index 0000000..7ea82db --- /dev/null +++ b/src/utils/logger.ts @@ -0,0 +1,7 @@ +export default interface Logger { + fatal(message: string | Error): void; + error(message: string | Error): void; + warn(message: string | Error): void; + info(message: string | Error): void; + debug(message: string | Error): void; +}