-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlogger.ts
34 lines (32 loc) · 1.3 KB
/
logger.ts
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
import { LogFunction } from './types'
export const makeLogger = (name: string): LogFunction => {
return (tags: Array<string>, data?: string | object): void => {
const allTags: Array<string> = Array.from(new Set([name, ...tags]))
if (allTags.indexOf('error') > -1) {
if (data !== undefined) {
console.error(`[${allTags.join(',')}] `, data)
} else {
console.error(`[${allTags.join(',')}]`)
}
} else if (allTags.indexOf('warn') > -1) {
if (data !== undefined) {
console.warn(`[${allTags.join(',')}] `, data)
} else {
console.warn(`[${allTags.join(',')}]`)
}
} else if (allTags.indexOf('info') > -1) {
if (data !== undefined) {
console.info(`[${allTags.join(',')}] `, data)
} else {
console.info(`[${allTags.join(',')}]`)
}
} else {
if (data !== undefined && process.env.DEBUG !== undefined) {
console.log(`[${allTags.join(',')}] `, data)
} else if (process.env.DEBUG !== undefined) {
console.log(`[${allTags.join(',')}]`)
}
}
}
}
export const defaultLogger: LogFunction = makeLogger('thrift-server-core')