Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
denwilliams committed Sep 10, 2024
1 parent f8eb399 commit fb65571
Show file tree
Hide file tree
Showing 15 changed files with 3,868 additions and 99 deletions.
7 changes: 1 addition & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier/@typescript-eslint",
],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
ignorePatterns: ["dist/**/*"],
};
33 changes: 13 additions & 20 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,27 @@ on: push

jobs:
test-prom-client-versions:
strategy:
matrix:
prom-client-version: [11, 12, 13, 14, 15]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 12
- run: npm install

- run: npm install prom-client@12
- run: npm run build
- run: npm test

- run: npm install prom-client@13
- run: npm run build
- run: npm test

- run: npm install prom-client@14
node-version: 20
- run: npm ci
- run: npm i -D prom-client@${{matrix.prom-client-version}}
- run: npm run build
- run: npm test
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 12
- run: npm install
- run: npm test
- uses: JS-DevTools/npm-publish@v1
node-version: 20
- run: npm cit
- uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,4 @@ node_modules
# Users Environment Variables
.lock-wscript

# Ignore lock because this is a module
package-lock.json

.vscode
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
12 changes: 6 additions & 6 deletions lib/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { format } from "./common";
test("formatting", (t) => {
t.is(
format(undefined, "level", ["example %s", 100, "after"]),
"level example 100 after"
"level example 100 after",
);

t.is(
format("prefix", "level", ["example %s", 100, "after"]),
`level ${yellow("prefix")}: example 100 after`
`level ${yellow("prefix")}: example 100 after`,
);

t.is(
format("prefix", "level", ["example %s", 100, { prop: "value" }]),
`level ${yellow("prefix")}: example 100 { prop: 'value' }`
`level ${yellow("prefix")}: example 100 { prop: 'value' }`,
);

const err = new Error("message");
Expand All @@ -27,14 +27,14 @@ test("formatting", (t) => {

t.is(
format("prefix", "level", [err]),
`level ${yellow("prefix")}: ${err.stack}`
`level ${yellow("prefix")}: ${err.stack}`,
);

// Node 12 now logs stack, not just message.
// Check startsWith for consistency between versions.
t.true(
format("prefix", "level", ["example %s", err]).startsWith(
`level ${yellow("prefix")}: example Error: message`
)
`level ${yellow("prefix")}: example Error: message`,
),
);
});
4 changes: 2 additions & 2 deletions lib/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import util from "util";
import util from "node:util";
import { cyan, blue, yellow, red } from "chalk";

const formatPrefix = (prefix?: string) => (prefix ? yellow(prefix) + ": " : "");
Expand All @@ -17,7 +17,7 @@ export function format(
prefix: string | undefined,
level: string,
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any
args: any
args: any,
): string {
return level + " " + formatPrefix(prefix) + util.format.apply(null, args);
}
4 changes: 2 additions & 2 deletions lib/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test("logger metrics", async (t) => {
},
});
const logger = metricsMiddleware(registry)(
new LokeLogger({ streams: [stream] })
new LokeLogger({ streams: [stream] }),
);

logger.debug();
Expand All @@ -38,7 +38,7 @@ test("prefix passes through", (t) => {
});

const logger = metricsMiddleware(registry)(
new LokeLogger({ streams: [stream], prefix: "PREFIX" })
new LokeLogger({ streams: [stream], prefix: "PREFIX" }),
);

logger.log("prefixed message");
Expand Down
Binary file modified lib/metrics.test.ts.snap
Binary file not shown.
3 changes: 3 additions & 0 deletions lib/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Counter, Registry } from "prom-client";
import chalk from "chalk";
import { LokeLogger } from "./logger";

chalk.level = 0;

type Middleware = (next: LokeLogger) => LokeLogger;

const wrap = (next: LokeLogger, wrapper: Partial<LokeLogger>): LokeLogger =>
Expand Down
2 changes: 1 addition & 1 deletion lib/streams/console.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Writable } from "node:stream";
import test from "ava";
import { Writable } from "stream";
import { yellow } from "chalk";
import { LokeLogger } from "../logger";
import { DEBUG, INFO, WARN, ERROR } from "../common";
Expand Down
4 changes: 2 additions & 2 deletions lib/streams/console.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Writable } from "stream";
import { Writable } from "node:stream";

import { DEBUG, INFO, WARN, ERROR, Log } from "../common";

Expand All @@ -17,7 +17,7 @@ export class ConsoleStream extends Writable {
constructor(
stdout: NodeJS.WritableStream = process.stdout,
stderr: NodeJS.WritableStream = process.stderr,
systemdPrefix = false
systemdPrefix = false,
) {
super({ objectMode: true });
this.stdout = stdout;
Expand Down
74 changes: 37 additions & 37 deletions lib/streams/syslog.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dgram from "dgram";
import dgram from "node:dgram";
import test from "ava";
import { yellow } from "chalk";
import { LokeLogger } from "../logger";
Expand All @@ -12,10 +12,10 @@ async function createTestSocket() {

const next = (): Promise<string> =>
new Promise((resolve) =>
socket.once("message", (buf) => resolve(buf.toString("utf8")))
socket.once("message", (buf) => resolve(buf.toString("utf8"))),
);

const done = () => socket.close();
const done = () => new Promise<void>((resolve) => socket.close(resolve));

await new Promise<void>((resolve) => socket.bind(resolve));

Expand All @@ -33,86 +33,85 @@ mockable.Date = FakeDate as never;

test("logger with debug true", async (t) => {
const { next, done, port } = await createTestSocket();
const syslog = new SyslogStream({
port,
pid: 2607,
hostname: "ip-10-0-0-115",
appName: "test",
});
const logger = new LokeLogger({
showDebug: true,
streams: [
new SyslogStream({
port,
pid: 2607,
hostname: "ip-10-0-0-115",
appName: "test",
}),
],
streams: [syslog],
});

logger.debug("debug message");
t.is(
await next(),
`<135>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${DEBUG} debug message`
`<135>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${DEBUG} debug message`,
);

logger.log("log message");
t.is(
await next(),
`<134>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${INFO} log message`
`<134>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${INFO} log message`,
);

logger.info("info message");
t.is(
await next(),
`<134>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${INFO} info message`
`<134>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${INFO} info message`,
);

logger.warn("warn message");
t.is(
await next(),
`<132>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${WARN} warn message`
`<132>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${WARN} warn message`,
);

logger.error("error message");
t.is(
await next(),
`<131>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${ERROR} error message`
`<131>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${ERROR} error message`,
);

done();
syslog.close();
await done();
});

test("formatted messages", async (t) => {
const { next, done, port } = await createTestSocket();
const syslog = new SyslogStream({
port,
pid: 2607,
hostname: "ip-10-0-0-115",
appName: "test",
});
const logger = new LokeLogger({
showDebug: true,
streams: [
new SyslogStream({
port,
pid: 2607,
hostname: "ip-10-0-0-115",
appName: "test",
}),
],
streams: [syslog],
});

logger.info("%s message", 1, "other");
t.is(
await next(),
`<134>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${INFO} 1 message other`
`<134>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${INFO} 1 message other`,
);

done();
syslog.close();
await done();
});

test("with prefix", async (t) => {
const { next, done, port } = await createTestSocket();
const syslog = new SyslogStream({
port,
pid: 2607,
hostname: "ip-10-0-0-115",
appName: "test",
});
const logger = new LokeLogger({
showDebug: true,
streams: [
new SyslogStream({
port,
pid: 2607,
hostname: "ip-10-0-0-115",
appName: "test",
}),
],
streams: [syslog],
});

logger.withPrefix("PREFIX").info("prefixed message");
Expand All @@ -121,8 +120,9 @@ test("with prefix", async (t) => {

t.is(
await next(),
`<134>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${INFO} ${PREFIX}: prefixed message`
`<134>1 2018-02-23T11:46:24.00Z ip-10-0-0-115 test 2607 - - ${INFO} ${PREFIX}: prefixed message`,
);

done();
syslog.close();
await done();
});
10 changes: 7 additions & 3 deletions lib/streams/syslog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from "os";
import dgram from "dgram";
import { Writable } from "stream";
import os from "node:os";
import dgram from "node:dgram";
import { Writable } from "node:stream";
import glossy from "glossy";

import { DEBUG, INFO, WARN, ERROR, Log } from "../common";
Expand Down Expand Up @@ -65,4 +65,8 @@ export class SyslogStream extends Writable {

callback();
}

close(): void {
this.socket.close();
}
}
Loading

0 comments on commit fb65571

Please sign in to comment.