Skip to content

Commit

Permalink
add netlify? to LogEvent interface
Browse files Browse the repository at this point in the history
  • Loading branch information
schehata committed Nov 28, 2022
1 parent 67b7403 commit 206e429
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/logger.ts
@@ -1,16 +1,18 @@
import config, { isVercel } from './config';
import { NetlifyInfo } from './platform/netlify';
import { isNoPrettyPrint, throttle } from './shared';

const url = config.getLogsEndpoint();

interface LogEvent {
export interface LogEvent {
level: string;
message: string;
fields: {};
_time: string;
request?: RequestReport;
platform?: PlatformInfo;
vercel?: PlatformInfo;
netlify?: NetlifyInfo;
}

export interface RequestReport {
Expand All @@ -25,12 +27,11 @@ export interface RequestReport {
userAgent?: string | null;
}

interface PlatformInfo {
export interface PlatformInfo {
environment?: string;
region?: string;
route?: string;
source?: string;
provider: string;
}

export class Logger {
Expand Down
10 changes: 9 additions & 1 deletion src/platform/netlify.ts
@@ -1,6 +1,14 @@
import { LogEvent, PlatformInfo } from '../logger';
import type Provider from './base';
import GenericConfig from './generic';

export interface NetlifyInfo extends PlatformInfo {
buildId?: string;
context?: string;
deploymentUrl?: string;
deploymentId?: string;
}

export default class NetlifyConfig extends GenericConfig implements Provider {
netlifyBuildId = process.env.BUILD_ID;
netlifyContext = process.env.CONTEXT;
Expand All @@ -22,7 +30,7 @@ export default class NetlifyConfig extends GenericConfig implements Provider {
}))
}

injectPlatformMetadata(logEvent: any, source: string) {
injectPlatformMetadata(logEvent: LogEvent, source: string) {
logEvent.netlify = {
environment: this.environment,
region: this.region,
Expand Down
3 changes: 2 additions & 1 deletion src/platform/vercel.ts
@@ -1,3 +1,4 @@
import { LogEvent } from '../logger';
import { EndpointType } from '../shared';
import type Provider from './base';
import GenericConfig from './generic';
Expand Down Expand Up @@ -33,7 +34,7 @@ export default class VercelConfig extends GenericConfig implements Provider {
};
}

injectPlatformMetadata(logEvent: any, source: string) {
injectPlatformMetadata(logEvent: LogEvent, source: string) {
logEvent.vercel = {
environment: this.environment,
region: this.region,
Expand Down

0 comments on commit 206e429

Please sign in to comment.