-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.js
More file actions
32 lines (30 loc) · 1.2 KB
/
lambda.js
File metadata and controls
32 lines (30 loc) · 1.2 KB
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
import getLogger from './lib/getLogger.js'
import finish from './lib/finish.js'
import extract from './lib/extract.js'
import getLogs from './lib/getLogs.js'
import { existsSync } from 'fs'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const hasCustomLogHandler = existsSync(join(__dirname, './customLogHandler.js'))
export const handler = async (event) => {
const logger = getLogger({
token: process.env.TOKEN,
host: process.env.HOST,
type: process.env.TYPE,
compress: process.env.COMPRESS === 'true'
})
const extracted = await extract(event)
let omit = []
if (process.env.OMIT && process.env.OMIT.length > 0) omit = process.env.OMIT.split(',')
const logs = getLogs(extracted, { omitStartAndEnd: process.env.OMIT_START_AND_END === 'true', reduceReport: process.env.REDUCE_REPORT !== 'false', omit })
try {
if (hasCustomLogHandler) {
const customLogHandler = (await import('./customLogHandler.js')).default
const ret = customLogHandler(logs)
if (ret && typeof ret.then === 'function') await ret
}
} catch (e) {}
logs.forEach((log) => logger.log(log))
return finish(logger)
}