forked from probot/adapter-github-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpino-transport-github-actions.js
More file actions
37 lines (30 loc) · 885 Bytes
/
Copy pathpino-transport-github-actions.js
File metadata and controls
37 lines (30 loc) · 885 Bytes
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
const { inspect } = require("util");
const through = require("through2");
const core = require("@actions/core");
const pino = require("pino");
const LEVEL_TO_ACTIONS_CORE_LOG_METHOD = {
trace: "debug",
debug: "debug",
info: "info",
warn: "warning",
error: "error",
fatal: "error",
};
const transport = through.obj(function (chunk, enc, cb) {
const { level, hostname, pid, msg, time, ...meta } = JSON.parse(chunk);
const levelLabel = pino.levels.labels[level] || level;
const logMethodName = LEVEL_TO_ACTIONS_CORE_LOG_METHOD[levelLabel];
const output = [
msg,
Object.keys(meta).length ? inspect(meta, { depth: Infinity }) : "",
]
.join("\n")
.trim();
if (logMethodName in core) {
core[logMethodName](output);
} else {
core.error(`"${level}" is not a known log level - ${output}`);
}
cb();
});
module.exports = { transport };