Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: merge staging to master #30

Merged
merged 13 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
"jest": true
},
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier"
],
"plugins": [
"import"
],
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"import"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"linebreak-style": ["error", "unix"],
"no-empty": 1,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ npm install
# build the dist
npm run build
# run the repl (this allows you to import from ./src)
npm run ts-node
npm run tsx
# run the tests
npm run test
# lint the source code
Expand Down
39 changes: 25 additions & 14 deletions benches/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
#!/usr/bin/env ts-node
#!/usr/bin/env tsx

import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';
import si from 'systeminformation';
import loggerText from './logger_text';
import loggerStructured from './logger_structured';
import loggerHierarchy from './logger_hierarchy';
import loggerFiltered from './logger_filtered';
import loggerHandlers from './logger_handlers';
import { benchesPath } from './utils/utils.js';
import loggerText from './logger_text.js';
import loggerStructured from './logger_structured.js';
import loggerHierarchy from './logger_hierarchy.js';
import loggerFiltered from './logger_filtered.js';
import loggerHandlers from './logger_handlers.js';

async function main(): Promise<void> {
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
await fs.promises.mkdir(path.join(benchesPath, 'results'), {
recursive: true,
});
await loggerText();
await loggerStructured();
await loggerHierarchy();
await loggerFiltered();
await loggerHandlers();
const resultFilenames = await fs.promises.readdir(
path.join(__dirname, 'results'),
path.join(benchesPath, 'results'),
);
const metricsFile = await fs.promises.open(
path.join(__dirname, 'results', 'metrics.txt'),
path.join(benchesPath, 'results', 'metrics.txt'),
'w',
);
let concatenating = false;
for (const resultFilename of resultFilenames) {
if (/.+_metrics\.txt$/.test(resultFilename)) {
const metricsData = await fs.promises.readFile(
path.join(__dirname, 'results', resultFilename),
path.join(benchesPath, 'results', resultFilename),
);
if (concatenating) {
await metricsFile.write('\n');
Expand All @@ -43,9 +47,16 @@ async function main(): Promise<void> {
system: 'model, manufacturer',
});
await fs.promises.writeFile(
path.join(__dirname, 'results', 'system.json'),
path.join(benchesPath, 'results', 'system.json'),
JSON.stringify(systemData, null, 2),
);
}

void main();
if (import.meta.url.startsWith('file:')) {
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
void main();
}
}

export default main;
18 changes: 12 additions & 6 deletions benches/logger_filtered.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import path from 'path';
import path from 'node:path';
import url from 'node:url';
import b from 'benny';
import Logger, { LogLevel, formatting } from '@';
import { BenchHandler, suiteCommon } from './utils';
import { BenchHandler, suiteCommon } from './utils/index.js';
import Logger, { LogLevel, formatting } from '#index.js';

const filePath = url.fileURLToPath(import.meta.url);

async function main() {
const msg = 'Hello World';
const data = { foo: 'bar', bar: () => 'foo' };
const summary = await b.suite(
path.basename(__filename, path.extname(__filename)),
path.basename(filePath, path.extname(filePath)),
b.add('log level', () => {
const logger = new Logger('root', LogLevel.WARN, [
new BenchHandler(formatting.formatter),
Expand All @@ -30,8 +33,11 @@ async function main() {
return summary;
}

if (require.main === module) {
void main();
if (import.meta.url.startsWith('file:')) {
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
void main();
}
}

export default main;
22 changes: 14 additions & 8 deletions benches/logger_handlers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os from 'os';
import path from 'path';
import fs from 'fs';
import os from 'node:os';
import path from 'node:path';
import url from 'node:url';
import fs from 'node:fs';
import b from 'benny';
import Logger, { LogLevel, StreamHandler, ConsoleErrHandler } from '@';
import { suiteCommon } from './utils';
import { suiteCommon } from './utils/index.js';
import Logger, { LogLevel, StreamHandler, ConsoleErrHandler } from '#index.js';

const filePath = url.fileURLToPath(import.meta.url);

async function main() {
const msg = 'Hello World';
Expand All @@ -18,7 +21,7 @@ async function main() {
const stderr = fs.createWriteStream(path.join(tmpDir, 'stderr'));
process.stderr.write = stderr.write.bind(stderr);
const summary = await b.suite(
path.basename(__filename, path.extname(__filename)),
path.basename(filePath, path.extname(filePath)),
b.add('console.error', () => {
const logger = new Logger('root', LogLevel.NOTSET, [
new ConsoleErrHandler(),
Expand All @@ -43,8 +46,11 @@ async function main() {
return summary;
}

if (require.main === module) {
void main();
if (import.meta.url.startsWith('file:')) {
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
void main();
}
}

export default main;
18 changes: 12 additions & 6 deletions benches/logger_hierarchy.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import path from 'path';
import path from 'node:path';
import url from 'node:url';
import b from 'benny';
import Logger, { LogLevel, formatting } from '@';
import { BenchHandler, suiteCommon } from './utils';
import { BenchHandler, suiteCommon } from './utils/index.js';
import Logger, { LogLevel, formatting } from '#index.js';

const filePath = url.fileURLToPath(import.meta.url);

async function main() {
const msg = 'Hello World';
const data = { foo: 'bar', bar: () => 'foo' };
const summary = await b.suite(
path.basename(__filename, path.extname(__filename)),
path.basename(filePath, path.extname(filePath)),
b.add('1-levels', () => {
const logger1 = new Logger('1', LogLevel.NOTSET, [
new BenchHandler(formatting.formatter),
Expand Down Expand Up @@ -51,8 +54,11 @@ async function main() {
return summary;
}

if (require.main === module) {
void main();
if (import.meta.url.startsWith('file:')) {
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
void main();
}
}

export default main;
20 changes: 13 additions & 7 deletions benches/logger_structured.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import type { LogRecord } from '@/types';
import path from 'path';
import type { LogRecord } from '#types.js';
import path from 'node:path';
import url from 'node:url';
import b from 'benny';
import { BenchHandler, suiteCommon } from './utils/index.js';
import Logger, {
LogLevel,
formatting,
levelToString,
evalLogDataValue,
} from '@';
import { BenchHandler, suiteCommon } from './utils';
} from '#index.js';

const filePath = url.fileURLToPath(import.meta.url);

async function main() {
const msg = 'Hello World';
const data = { foo: 'bar', bar: () => 'foo' };
const summary = await b.suite(
path.basename(__filename, path.extname(__filename)),
path.basename(filePath, path.extname(filePath)),
b.add('formatting default', () => {
const logger = new Logger('root', LogLevel.NOTSET, [
new BenchHandler(formatting.jsonFormatter),
Expand Down Expand Up @@ -82,8 +85,11 @@ async function main() {
return summary;
}

if (require.main === module) {
void main();
if (import.meta.url.startsWith('file:')) {
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
void main();
}
}

export default main;
18 changes: 12 additions & 6 deletions benches/logger_text.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import path from 'path';
import path from 'node:path';
import url from 'node:url';
import b from 'benny';
import Logger, { LogLevel, formatting } from '@';
import { BenchHandler, suiteCommon } from './utils';
import { BenchHandler, suiteCommon } from './utils/index.js';
import Logger, { LogLevel, formatting } from '#index.js';

const filePath = url.fileURLToPath(import.meta.url);

async function main() {
const msg = 'Hello World';
const data = { foo: 'bar', bar: () => 'foo' };
const summary = await b.suite(
path.basename(__filename, path.extname(__filename)),
path.basename(filePath, path.extname(filePath)),
b.add('formatting default', () => {
const logger = new Logger('root', LogLevel.NOTSET, [
new BenchHandler(formatting.formatter),
Expand Down Expand Up @@ -62,8 +65,11 @@ async function main() {
return summary;
}

if (require.main === module) {
void main();
if (import.meta.url.startsWith('file:')) {
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
void main();
}
}

export default main;
14 changes: 7 additions & 7 deletions benches/results/logger_filtered.chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</head>
<body>
<div class="container">
<canvas id="chart1687502300189" width="16" height="9"></canvas>
<canvas id="chart1691771219101" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -51,18 +51,18 @@
chunked.map((chunk) => chunk.join('')).join(' ') + fractionStr
)
}
const ctx1687502300189 = document
.getElementById('chart1687502300189')
const ctx1691771219101 = document
.getElementById('chart1691771219101')
.getContext('2d')
const chart1687502300189 = new Chart(ctx1687502300189, {
const chart1691771219101 = new Chart(ctx1691771219101, {
type: 'bar',
data: {
labels: ["log level","keys regex"],
datasets: [
{
data: [167936103,166306609],
backgroundColor: ["hsl(120, 85%, 55%)","hsl(118.836, 85%, 55%)"],
borderColor: ["hsl(120, 85%, 55%)","hsl(118.836, 85%, 55%)"],
data: [162982111,165489057],
backgroundColor: ["hsl(118.188, 85%, 55%)","hsl(120, 85%, 55%)"],
borderColor: ["hsl(118.188, 85%, 55%)","hsl(120, 85%, 55%)"],
borderWidth: 2,
},
],
Expand Down
Loading