Skip to content

Commit 5a449a0

Browse files
committed
Init - Nelify Build Logger for Axiom
0 parents  commit 5a449a0

File tree

6 files changed

+249
-0
lines changed

6 files changed

+249
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { createLogger } from "./logger.js";
2+
3+
export default {
4+
onEnd: async({constants, packageJson, error}) => {
5+
const payload = {
6+
env: process.env.ENVIRONMENT,
7+
appName: packageJson.name,
8+
siteId: constants.SITE_ID
9+
};
10+
const logger = createLogger({
11+
AXIOM:{
12+
DATASET: process.env.AXIOM_DATASET,
13+
TOKEN: process.env.AXIOM_TOKEN,
14+
ORG_ID: process.env.AXIOM_ORG_ID,
15+
},
16+
payload,
17+
});
18+
19+
if (error) {
20+
logger.info(`Deploy error: ${error.shortMessage}`);
21+
} else {
22+
logger.info(`Deploy success`);
23+
}
24+
await logger.send();
25+
}
26+
}

logger.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { WinstonTransport as AxiomTransport } from '@axiomhq/winston';
2+
3+
const Config = {
4+
EventSource: 'netlify',
5+
EventName: 'Netlify Build Logs',
6+
LoggerTimeoutInMS: 1000,
7+
}
8+
9+
function createLogger({
10+
AXIOM,
11+
payload,
12+
}) {
13+
const logger = winston.createLogger({
14+
level: 'info',
15+
format: winston.format.json(),
16+
exitOnError: false,
17+
defaultMeta: { service: `service-${payload.appName}`},
18+
transports: [
19+
new AxiomTransport({
20+
dataset: AXIOM.DATASET,
21+
token: AXIOM.TOKEN,
22+
orgId: AXIOM.ORG_ID
23+
}),
24+
],
25+
});
26+
const loggerPayload = {
27+
evt:{
28+
name: Config.EventName,
29+
},
30+
env: payload.env,
31+
appName: payload.appName,
32+
}
33+
return {
34+
info: (...args) => {
35+
loggerPayload.message = args;
36+
logger.info(loggerPayload)
37+
},
38+
warn: (...args) => {
39+
loggerPayload.message = args;
40+
logger.warn(loggerPayload)
41+
},
42+
send: () => {
43+
const timeout = setTimeout(() => {
44+
logger.end();
45+
}, Config.LoggerTimeoutInMS);
46+
47+
const completePromise = new Promise((resolve) => {
48+
logger.on('finish', (...args) => {
49+
clearTimeout(timeout);
50+
resolve();
51+
});
52+
});
53+
54+
return completePromise;
55+
}
56+
}
57+
}
58+
59+
export {
60+
createLogger
61+
}

manifest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: netlify-build-log-plugin

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "netlify-build-log-plugin",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"@axiomhq/winston": "^0.1.3"
15+
}
16+
}

yarn.lock

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@axiomhq/[email protected]":
6+
version "0.1.3"
7+
resolved "https://registry.yarnpkg.com/@axiomhq/js/-/js-0.1.3.tgz#0c13b4ded031f01f5ffdaba10e29f99c2c487702"
8+
integrity sha512-2HIHYHBw40V8Qu642aKvP6ZFNoeS0oTtsZNe9Fxv0lQgC2XxR6E9aiPmIuzmJIRKzhFMtyu1MLez15seYzyInw==
9+
dependencies:
10+
cross-fetch "^3.1.5"
11+
fetch-retry "^5.0.3"
12+
uuid "^8.3.2"
13+
14+
"@axiomhq/winston@^0.1.3":
15+
version "0.1.3"
16+
resolved "https://registry.yarnpkg.com/@axiomhq/winston/-/winston-0.1.3.tgz#77746b93dd7148451e6202fc2c55cc80c29610b7"
17+
integrity sha512-l8v5Zxq7rpKm9i9+tRbOZeDN+2eECazy9xLWIIarLOrBC0o036eSAbykNrATIo9BV/s38e4i1fMuyrmZAXi3JQ==
18+
dependencies:
19+
"@axiomhq/js" "0.1.3"
20+
winston-transport "^4.5.0"
21+
22+
23+
version "1.5.0"
24+
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
25+
integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==
26+
27+
"@types/triple-beam@^1.3.2":
28+
version "1.3.2"
29+
resolved "https://registry.yarnpkg.com/@types/triple-beam/-/triple-beam-1.3.2.tgz#38ecb64f01aa0d02b7c8f4222d7c38af6316fef8"
30+
integrity sha512-txGIh+0eDFzKGC25zORnswy+br1Ha7hj5cMVwKIU7+s0U2AxxJru/jZSMU6OC9MJWP6+pc/hc6ZjyZShpsyY2g==
31+
32+
cross-fetch@^3.1.5:
33+
version "3.1.8"
34+
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.8.tgz#0327eba65fd68a7d119f8fb2bf9334a1a7956f82"
35+
integrity sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==
36+
dependencies:
37+
node-fetch "^2.6.12"
38+
39+
fecha@^4.2.0:
40+
version "4.2.3"
41+
resolved "https://registry.yarnpkg.com/fecha/-/fecha-4.2.3.tgz#4d9ccdbc61e8629b259fdca67e65891448d569fd"
42+
integrity sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==
43+
44+
fetch-retry@^5.0.3:
45+
version "5.0.6"
46+
resolved "https://registry.yarnpkg.com/fetch-retry/-/fetch-retry-5.0.6.tgz#17d0bc90423405b7a88b74355bf364acd2a7fa56"
47+
integrity sha512-3yurQZ2hD9VISAhJJP9bpYFNQrHHBXE2JxxjY5aLEcDi46RmAzJE2OC9FAde0yis5ElW0jTTzs0zfg/Cca4XqQ==
48+
49+
inherits@^2.0.3:
50+
version "2.0.4"
51+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
52+
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
53+
54+
logform@^2.3.2:
55+
version "2.5.1"
56+
resolved "https://registry.yarnpkg.com/logform/-/logform-2.5.1.tgz#44c77c34becd71b3a42a3970c77929e52c6ed48b"
57+
integrity sha512-9FyqAm9o9NKKfiAKfZoYo9bGXXuwMkxQiQttkT4YjjVtQVIQtK6LmVtlxmCaFswo6N4AfEkHqZTV0taDtPotNg==
58+
dependencies:
59+
"@colors/colors" "1.5.0"
60+
"@types/triple-beam" "^1.3.2"
61+
fecha "^4.2.0"
62+
ms "^2.1.1"
63+
safe-stable-stringify "^2.3.1"
64+
triple-beam "^1.3.0"
65+
66+
ms@^2.1.1:
67+
version "2.1.3"
68+
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
69+
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
70+
71+
node-fetch@^2.6.12:
72+
version "2.6.12"
73+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.12.tgz#02eb8e22074018e3d5a83016649d04df0e348fba"
74+
integrity sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==
75+
dependencies:
76+
whatwg-url "^5.0.0"
77+
78+
readable-stream@^3.6.0:
79+
version "3.6.2"
80+
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967"
81+
integrity sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==
82+
dependencies:
83+
inherits "^2.0.3"
84+
string_decoder "^1.1.1"
85+
util-deprecate "^1.0.1"
86+
87+
safe-buffer@~5.2.0:
88+
version "5.2.1"
89+
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
90+
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
91+
92+
safe-stable-stringify@^2.3.1:
93+
version "2.4.3"
94+
resolved "https://registry.yarnpkg.com/safe-stable-stringify/-/safe-stable-stringify-2.4.3.tgz#138c84b6f6edb3db5f8ef3ef7115b8f55ccbf886"
95+
integrity sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==
96+
97+
string_decoder@^1.1.1:
98+
version "1.3.0"
99+
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
100+
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
101+
dependencies:
102+
safe-buffer "~5.2.0"
103+
104+
tr46@~0.0.3:
105+
version "0.0.3"
106+
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
107+
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
108+
109+
triple-beam@^1.3.0:
110+
version "1.4.1"
111+
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.4.1.tgz#6fde70271dc6e5d73ca0c3b24e2d92afb7441984"
112+
integrity sha512-aZbgViZrg1QNcG+LULa7nhZpJTZSLm/mXnHXnbAbjmN5aSa0y7V+wvv6+4WaBtpISJzThKy+PIPxc1Nq1EJ9mg==
113+
114+
util-deprecate@^1.0.1:
115+
version "1.0.2"
116+
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
117+
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==
118+
119+
uuid@^8.3.2:
120+
version "8.3.2"
121+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
122+
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
123+
124+
webidl-conversions@^3.0.0:
125+
version "3.0.1"
126+
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
127+
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==
128+
129+
whatwg-url@^5.0.0:
130+
version "5.0.0"
131+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
132+
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
133+
dependencies:
134+
tr46 "~0.0.3"
135+
webidl-conversions "^3.0.0"
136+
137+
winston-transport@^4.5.0:
138+
version "4.5.0"
139+
resolved "https://registry.yarnpkg.com/winston-transport/-/winston-transport-4.5.0.tgz#6e7b0dd04d393171ed5e4e4905db265f7ab384fa"
140+
integrity sha512-YpZzcUzBedhlTAfJg6vJDlyEai/IFMIVcaEZZyl3UXIl4gmqRpU7AE89AHLkbzLUsv0NVmw7ts+iztqKxxPW1Q==
141+
dependencies:
142+
logform "^2.3.2"
143+
readable-stream "^3.6.0"
144+
triple-beam "^1.3.0"

0 commit comments

Comments
 (0)