Skip to content

Commit

Permalink
chore(serve): rename "audit-log" to "access-log".
Browse files Browse the repository at this point in the history
- rename "AuditLoggingMiddleware" to "AccessLogMiddleware".
- rename option name from "audit-log" to "access-log".
- rename "AUDIT" to "ACCESS_LOG" in "getLogger" function.
  • Loading branch information
kokokuo committed Sep 12, 2022
1 parent 977e858 commit 916da3e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/lib/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export enum LoggingScope {
CORE = 'CORE',
BUILD = 'BUILD',
SERVE = 'SERVE',
AUDIT = 'AUDIT',
ACCESS_LOG = 'ACCESS_LOG',
}

type LoggingScopeTypes = keyof typeof LoggingScope;
Expand Down Expand Up @@ -53,7 +53,7 @@ const defaultMapConfig: LoggerMapConfig = {
displayFilePath: 'hideNodeModulesOnly',
displayFunctionName: true,
},
[LoggingScope.AUDIT]: {
[LoggingScope.ACCESS_LOG]: {
level: LoggingLevel.DEBUG,
displayRequestId: false,
displayFilePath: 'hidden',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
import * as bytes from 'bytes';
import { BuiltInMiddleware, KoaContext, Next } from '@vulcan-sql/serve/models';

@VulcanInternalExtension('audit-log')
export class AuditLoggingMiddleware extends BuiltInMiddleware<LoggerOptions> {
@VulcanInternalExtension('access-log')
export class AccessLogMiddleware extends BuiltInMiddleware<LoggerOptions> {
private logger = getLogger({
scopeName: 'AUDIT',
scopeName: 'ACCESS_LOG',
options: this.getOptions(),
});

Expand Down
6 changes: 3 additions & 3 deletions packages/serve/src/lib/middleware/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './corsMiddleware';
export * from './requestIdMiddleware';
export * from './auditLogMiddleware';
export * from './accessLogMiddleware';
export * from './rateLimitMiddleware';
export * from './authMiddleware';
export * from './response-format';
Expand All @@ -11,7 +11,7 @@ import { CorsMiddleware } from './corsMiddleware';
import { AuthMiddleware } from './authMiddleware';
import { RateLimitMiddleware } from './rateLimitMiddleware';
import { RequestIdMiddleware } from './requestIdMiddleware';
import { AuditLoggingMiddleware } from './auditLogMiddleware';
import { AccessLogMiddleware } from './accessLogMiddleware';
import { ResponseFormatMiddleware } from './response-format';
import { EnforceHttpsMiddleware } from './enforceHttpsMiddleware';
import { ClassType, ExtensionBase } from '@vulcan-sql/core';
Expand All @@ -22,7 +22,7 @@ export const BuiltInRouteMiddlewares: ClassType<ExtensionBase>[] = [
CorsMiddleware,
EnforceHttpsMiddleware,
RequestIdMiddleware,
AuditLoggingMiddleware,
AccessLogMiddleware,
RateLimitMiddleware,
AuthMiddleware,
ResponseFormatMiddleware,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { KoaContext } from '@vulcan-sql/serve/models';
import * as core from '@vulcan-sql/core';
import * as uuid from 'uuid';
import {
AuditLoggingMiddleware,
AccessLogMiddleware,
RequestIdMiddleware,
} from '@vulcan-sql/serve/middleware';
import bytes = require('bytes');

describe('Test audit logging middlewares', () => {
describe('Test access log middlewares', () => {
afterEach(() => {
sinon.default.restore();
});
Expand Down Expand Up @@ -63,9 +63,9 @@ describe('Test audit logging middlewares', () => {
` <- header: ${JSON.stringify(resp.header)}`,
];
// Act
const middleware = new AuditLoggingMiddleware({}, '');
// Use spy to trace the logger from getLogger( scopeName: 'AUDIT' }) to know in logger.info(...)
const spy = sinon.default.spy(core.getLogger({ scopeName: 'AUDIT' }));
const middleware = new AccessLogMiddleware({}, '');
// Use spy to trace the logger from getLogger( scopeName: 'ACCESS_LOG' }) to know in logger.info(...)
const spy = sinon.default.spy(core.getLogger({ scopeName: 'ACCESS_LOG' }));
await middleware.handle(ctx, async () => Promise.resolve());

// Assert
Expand Down Expand Up @@ -129,19 +129,19 @@ describe('Test audit logging middlewares', () => {

// setup request-id middleware run first.
const stubReqIdMiddleware = new RequestIdMiddleware({}, '');
const middleware = new AuditLoggingMiddleware(
const middleware = new AccessLogMiddleware(
{
options: {
displayRequestId: true,
},
},
''
);
// Use spy to trace the logger from getLogger( scopeName: 'AUDIT' }) to know in logger.info(...)
// it will get the setting of logger from above new audit logging middleware
// Use spy to trace the logger from getLogger( scopeName: 'ACCESS_LOG' }) to know in logger.info(...)
// it will get the setting of logger from above new ACCESS_LOG logging middleware
const spy = sinon.default.spy(
core.getLogger({
scopeName: 'AUDIT',
scopeName: 'ACCESS_LOG',
})
);
// Act
Expand Down

0 comments on commit 916da3e

Please sign in to comment.