File size: 872 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import config from '@automattic/calypso-config';
import debug from 'debug';
import { logToLogstash } from 'calypso/lib/logstash';
import type { SiteId } from 'calypso/types';

const debugLog = debug( 'calypso:data:site-migration' );

function safeLogToLogstash( params: Parameters< typeof logToLogstash >[ 0 ] ): void {
	if ( process.env.NODE_ENV === 'test' ) {
		return;
	}

	try {
		logToLogstash( params );
	} catch ( error ) {
		// Fail silently
	}
}

interface LogParams {
	message: string;
	siteId?: SiteId | null;
	extra?: Parameters< typeof logToLogstash >[ 0 ][ 'extra' ];
}

export const log = ( { message, siteId, extra }: LogParams ) => {
	debugLog( message, siteId );
	safeLogToLogstash( {
		feature: 'calypso_client',
		tags: [ 'site-migration' ],
		message,
		site_id: siteId || undefined,
		extra,
		properties: {
			env: config( 'env_id' ),
		},
	} );
};