@gasket/plugin-logger
Advanced tools
Comparing version 7.0.9 to 7.0.15
@@ -1,7 +0,18 @@ | ||
import type { MaybeAsync, Plugin } from '@gasket/core'; | ||
import type { MaybeAsync, Plugin, Hook, HookId } from '@gasket/core'; | ||
import type { Logger } from '@gasket/plugin-logger'; | ||
export type LogLevel = 'error' | 'warn' | 'info' | 'debug'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
type LogMethods = Record<LogLevel, (...args: any[]) => void>; | ||
export function createChildLogger( | ||
parent: { | ||
[K in HookId]?: Hook<K>; | ||
}, | ||
metadata: Record<string, any> | ||
): Logger; | ||
export function verifyLoggerLevels(logger: Logger): void; | ||
declare module '@gasket/plugin-logger' { | ||
@@ -22,4 +33,8 @@ export interface Logger extends LogMethods { | ||
export interface HookExecTypes { | ||
createLogger(): Logger | ||
createLogger(): Logger; | ||
} | ||
export interface GasketActions { | ||
getLogger(): Logger; | ||
} | ||
} | ||
@@ -26,0 +41,0 @@ |
@@ -0,24 +1,11 @@ | ||
/// <reference types="create-gasket-app" /> | ||
/// <reference types="@gasket/plugin-https" /> | ||
/// <reference types="@gasket/plugin-metadata" /> | ||
/* eslint-disable no-console, no-sync */ | ||
const { name, version, description } = require('../package.json'); | ||
const { createChildLogger, verifyLoggerLevels } = require('./utils'); | ||
function createChildLogger(parent, metadata) { | ||
return { | ||
...parent, | ||
debug: (...args) => console.debug(...args, metadata), | ||
error: (...args) => console.error(...args, metadata), | ||
info: (...args) => console.info(...args, metadata), | ||
warn: (...args) => console.warn(...args, metadata), | ||
child: (meta) => createChildLogger(this, { ...metadata, ...meta }) | ||
}; | ||
} | ||
function verifyLoggerLevels(logger) { | ||
['debug', 'error', 'info', 'warn', 'child'].forEach((level) => { | ||
if (typeof logger[level] !== 'function') { | ||
throw new Error(`Logger is missing required level: ${level}`); | ||
} | ||
}); | ||
} | ||
module.exports = { | ||
/** @type {import('@gasket/core').Plugin} */ | ||
const plugin = { | ||
name, | ||
@@ -28,3 +15,3 @@ version, | ||
actions: { | ||
getLogger: gasket => gasket.logger | ||
getLogger: (gasket) => gasket.logger | ||
}, | ||
@@ -39,6 +26,8 @@ hooks: { | ||
init(gasket) { | ||
// eslint-disable-next-line no-sync | ||
const loggers = gasket.execSync('createLogger'); | ||
if (loggers && loggers.some((logger) => logger && logger instanceof Promise)) { | ||
if ( | ||
loggers && | ||
loggers.some((logger) => logger && logger instanceof Promise) | ||
) { | ||
throw new Error('createLogger hooks must be synchronous'); | ||
@@ -90,1 +79,3 @@ } | ||
}; | ||
module.exports = plugin; |
{ | ||
"name": "@gasket/plugin-logger", | ||
"version": "7.0.9", | ||
"version": "7.0.15", | ||
"description": "Gasket plugin for logging", | ||
@@ -39,8 +39,9 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@gasket/core": "^7.0.9", | ||
"@gasket/plugin-https": "^7.0.9", | ||
"@gasket/plugin-metadata": "^7.0.9", | ||
"@gasket/core": "^7.0.15", | ||
"@gasket/plugin-https": "^7.0.15", | ||
"@gasket/plugin-metadata": "^7.0.15", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.56.0", | ||
"eslint-config-godaddy": "^7.1.1", | ||
"eslint-config-godaddy-typescript": "^4.0.3", | ||
"eslint-plugin-jest": "^28.6.0", | ||
@@ -63,5 +64,15 @@ "eslint-plugin-unicorn": "^55.0.0", | ||
"unicorn/filename-case": "error" | ||
} | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"*.ts" | ||
], | ||
"extends": [ | ||
"godaddy-typescript" | ||
] | ||
} | ||
] | ||
}, | ||
"gitHead": "ff3acd042a9a22cd43ac29c6b064bd2f49304b9e" | ||
"gitHead": "2b1cd27bf8e7532c510260915cec8b4ad08496fe" | ||
} |
8719
6
140
11