Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 #3

Merged
merged 2 commits into from
Sep 17, 2023
Merged

v4 #3

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hatsy/log-z-request",
"version": "3.0.1",
"version": "4.0.0-pre.0",
"description": "Hatsy request logger",
"keywords": [
"http-middleware",
Expand All @@ -24,18 +24,19 @@
},
"sideEffects": false,
"dependencies": {
"@proc7ts/logger": "^1.3.2",
"@proc7ts/primitives": "^3.0.2"
"@proc7ts/logger": "^2.0.0",
"@proc7ts/primitives": "^4.0.1"
},
"peerDependencies": {
"@hatsy/hatsy": "^2.5.3",
"@run-z/log-z": "^2.2.1"
"@hatsy/hatsy": "^3.0.0",
"@run-z/log-z": "^3.0.0"
},
"devDependencies": {
"@hatsy/hatsy": "^2.5.3",
"@hatsy/hatsy": "^3.0.0",
"@jest/globals": "^29.7.0",
"@proc7ts/async": "^2.1.0",
"@run-z/eslint-config": "^3.5.0",
"@run-z/log-z": "^2.2.1",
"@run-z/log-z": "^3.0.0",
"@run-z/prettier-config": "^2.0.0",
"@run-z/project-config": "^0.20.0",
"@swc/core": "^1.3.85",
Expand Down
6 changes: 3 additions & 3 deletions src/error-logging.handler.impl.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ErrorMeans, LoggerMeans, RequestContext, RequestHandler } from '@hatsy/hatsy/core';
import { requestExtension } from '@hatsy/hatsy/core';
import type { ErrorMeans, LoggerMeans, RequestContext, RequestHandler } from '@hatsy/hatsy/core.js';
import { requestExtension } from '@hatsy/hatsy/core.js';
import type { ZLogger } from '@run-z/log-z';
import { zlogDetails } from '@run-z/log-z';
import type { RequestZLogConfig } from './logging';
import type { RequestZLogConfig } from './logging.js';

/**
* @internal
Expand Down
5 changes: 0 additions & 5 deletions src/index.ts

This file was deleted.

39 changes: 20 additions & 19 deletions src/logging.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { RequestContext, RequestProcessor } from '@hatsy/hatsy/core';
import { LoggerMeans, RequestHandler, requestProcessor } from '@hatsy/hatsy/core';
import type { RequestContext, RequestProcessor } from '@hatsy/hatsy/core.js';
import { LoggerMeans, RequestHandler, requestProcessor } from '@hatsy/hatsy/core.js';
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals';
import { PromiseResolver } from '@proc7ts/async';
import { consoleLogger, processingLogger } from '@proc7ts/logger';
import { asis, newPromiseResolver, noop, valueProvider } from '@proc7ts/primitives';
import type { ZLogger, ZLogRecorder } from '@run-z/log-z';
import { logZToLogger, zlogDetails, zlogINFO, ZLogLevel } from '@run-z/log-z';
import { asis, noop, valueProvider } from '@proc7ts/primitives';
import type { ZLogRecorder, ZLogger } from '@run-z/log-z';
import { ZLogLevel, logZToLogger, zlogDetails, zlogINFO } from '@run-z/log-z';
import type { Mock } from 'jest-mock';
import type { RequestZLogConfig } from './logging';
import { ZLogging } from './logging';
import type { RequestZLogConfig } from './logging.js';
import { ZLogging } from './logging.js';

describe('ZLogging', () => {
let infoSpy: Mock<(...args: unknown[]) => void>;
Expand All @@ -23,19 +24,19 @@ describe('ZLogging', () => {
});

it('logs nothing until error logged', async () => {
const whenLogged1 = newPromiseResolver<boolean>();
const whenLogged2 = newPromiseResolver<boolean>();
const whenLogged1 = new PromiseResolver<boolean>();
const whenLogged2 = new PromiseResolver<boolean>();
const handler: RequestHandler<LoggerMeans<ZLogger>> = async ({ log }) => {
log.info('Info');
whenLogged1.resolve(log.whenLogged());
await whenLogged2.promise();
await whenLogged2.whenDone();
log.error('Error');
await log.whenLogged();
};

const promise = processor(handler)({});

await whenLogged1.promise();
await whenLogged1.whenDone();

expect(infoSpy).not.toHaveBeenCalled();

Expand All @@ -46,19 +47,19 @@ describe('ZLogging', () => {
expect(errorSpy).toHaveBeenCalledWith('Error');
});
it('allows to trigger immediate logging', async () => {
const whenLogged1 = newPromiseResolver<boolean>();
const whenLogged2 = newPromiseResolver<boolean>();
const whenLogged1 = new PromiseResolver<boolean>();
const whenLogged2 = new PromiseResolver<boolean>();
const handler: RequestHandler<LoggerMeans<ZLogger>> = async ({ log }) => {
log.info('Deferred');
whenLogged1.resolve(log.whenLogged());
await whenLogged2.promise();
await whenLogged2.whenDone();
log.info('Immediate', zlogDetails({ immediate: true }));
await log.whenLogged();
};

const promise = processor(handler)({});

await whenLogged1.promise();
await whenLogged1.whenDone();

expect(infoSpy).not.toHaveBeenCalled();

Expand All @@ -69,17 +70,17 @@ describe('ZLogging', () => {
expect(infoSpy).toHaveBeenCalledWith('Immediate');
});
it('triggers immediate logging on error', async () => {
const whenLogged = newPromiseResolver<boolean>();
const whenError = newPromiseResolver();
const whenLogged = new PromiseResolver<boolean>();
const whenError = new PromiseResolver();
const handler: RequestHandler<LoggerMeans<ZLogger>> = async ({ log }) => {
log.info('Deferred');
whenLogged.resolve(log.whenLogged());
await whenError.promise();
await whenError.whenDone();
};

const promise = processor(handler, { by: logZToLogger(processingLogger(consoleLogger)) })({});

await whenLogged.promise();
await whenLogged.whenDone();

expect(infoSpy).not.toHaveBeenCalled();

Expand Down
10 changes: 5 additions & 5 deletions src/logging.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ErrorMeans, LoggerMeans, RequestContext, RequestHandler } from '@hatsy/hatsy/core';
import { RequestCapability, requestExtension } from '@hatsy/hatsy/core';
import type { ZLogger, ZLogLevel, ZLogRecorder } from '@run-z/log-z';
import type { ErrorMeans, LoggerMeans, RequestContext, RequestHandler } from '@hatsy/hatsy/core.js';
import { RequestCapability, requestExtension } from '@hatsy/hatsy/core.js';
import type { ZLogLevel, ZLogRecorder, ZLogger } from '@run-z/log-z';
import { logZ, logZAtopOf, logZBy } from '@run-z/log-z';
import { errorLoggingHandler } from './error-logging.handler.impl';
import { logZRequest } from './request.log.impl';
import { errorLoggingHandler } from './error-logging.handler.impl.js';
import { logZRequest } from './request.log.impl.js';

/**
* Logger configuration.
Expand Down
4 changes: 4 additions & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* @module @hatsy/log-z-request
*/
export * from './logging.js';
2 changes: 1 addition & 1 deletion src/request.log.impl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ZLogMessage, ZLogRecorder } from '@run-z/log-z';
import { ZLogLevel } from '@run-z/log-z';
import type { RequestZLogConfig } from './logging';
import type { RequestZLogConfig } from './logging.js';

/**
* @internal
Expand Down
6 changes: 1 addition & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"extends": "@run-z/project-config/tsconfig.lib.json",
"compilerOptions": {
"lib": ["ES2019"],
"module": "ES2015",
"moduleResolution": "Node",
"outDir": "target/js",
"target": "ES2019"
"outDir": "target/js"
},
"include": ["src/**/*"]
}
5 changes: 3 additions & 2 deletions typedoc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"entryPoints": ["src/index.ts"],
"entryPoints": ["src/mod.ts"],
"name": "Hatsy request logger",
"out": "./target/typedoc"
"out": "./target/typedoc",
"sort": ["static-first", "visibility", "enum-value-ascending", "alphabetical", "kind"]
}