Skip to content

Commit

Permalink
retrieve log by tag
Browse files Browse the repository at this point in the history
added github workflow
  • Loading branch information
carvilsi committed Mar 25, 2024
1 parent c5702d8 commit 7d2ff13
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 64 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: tests

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "main", "develop" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: nodejs
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: dependencies
run: |
npm install
- name: tests
run: npm test
- name: benchmarking
run: npm run benchmark
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# node-systemd-journal
# node-systemd-journal


25 changes: 25 additions & 0 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Bench } from 'tinybench';
import { jjournal, jlogger } from './../src/index.js';

const bench = new Bench({ time: 100 });

const TAG = 'NODE_SYSTEMD_JOURNAL';
const MESSAGE = 'a foo at the bar for lol';

bench
.add('add an entry to systemd-journal', () => {
jlogger(MESSAGE);
})
.add('add an entry to systemd-journal with a tag', () => {
jlogger(MESSAGE, TAG);
})
.add('retrieve an entry from systemd-journal by tag', () => {
jjournal(TAG);
})
;

await bench.warmup();
await bench.run();

console.table(bench.table());

7 changes: 7 additions & 0 deletions benchmark/report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
┌─────────┬─────────────────────────────────────────────────┬─────────┬────────────────────┬───────────┬─────────┐
│ (index) │ Task Name │ ops/sec │ Average Time (ns) │ Margin │ Samples │
├─────────┼─────────────────────────────────────────────────┼─────────┼────────────────────┼───────────┼─────────┤
│ 0 │ 'add an entry to systemd-journal' │ '92' │ 10757970.000000006 │ '±58.89%' │ 10 │
│ 1 │ 'add an entry to systemd-journal with a tag' │ '379' │ 2637071.631578945 │ '±8.10%' │ 38 │
│ 2 │ 'retrieve an entry from systemd-journal by tag' │ '124' │ 8053321.769230766 │ '±37.90%' │ 13 │
└─────────┴─────────────────────────────────────────────────┴─────────┴────────────────────┴───────────┴─────────┘
15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,17 @@
"lint-fix": "./node_modules/eslint/bin/eslint.js src/ --ext .js --fix",
"lint-test-fix": "./node_modules/eslint/bin/eslint.js tests/ --ext .js --fix",
"benchmark": "node ./benchmark/benchmark.js > ./benchmark/report.txt && cat ./benchmark/report.txt",
"dev": "nodemon -w . -x 'npm test'",
"dev": "nodemon -w . -x 'npm test && npm run benchmark'",
"pre-release": "npm audit && ./pre-release.sh",
"release": "tag=$(node -e \"console.log(require('./package.json').version)\"); git tag v${tag}; git push origin v${tag} && npm publish"
},
"keywords": [
"textfaces",
"systemd",
"nodejs",
"emoji",
"linux",
"npm",
"ascii-art",
"emoticons",
"text-based",
"kaomoji",
"emoticon",
"kaomoji-emoticons",
"text-faces"
"logger",
"journalctl"
],
"author": "[email protected]",
"license": "MIT",
Expand Down
7 changes: 2 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function checkPlatform() {
}

export async function jlogger(message, tag) {
checkPlatform();
checkPlatform();
if (typeof message === 'undefined' || !message.trim().length) {
throw new Error('\'message\' parameter is mandatory');
}
Expand All @@ -26,16 +26,13 @@ export async function jlogger(message, tag) {
return await exec(loggerCommand);
}

/* eslint no-console: "off" */
export async function jjournal(tag) {
checkPlatform();
if (typeof tag === 'undefined' || !tag.trim().length) {
throw new Error('\'tag\' parameter is mandatory');
}
const journalctlCommand = `journalctl -t ${tag}`;
const { stdout, stderr } = await exec(journalctlCommand);
console.log(typeof stdout);
console.log(typeof stderr);
const { stdout } = await exec(journalctlCommand);
return stdout;
}

51 changes: 3 additions & 48 deletions tests/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ test('should throws an error', async(t) => {
});

test.serial('should create an entry at systemd journal with a tag', async(t) => {
await jlogger(MESSAGE, TAG);
await jlogger(MESSAGE, TAG);
t.pass();
});

test('should throw an error since there is no message', async(t) => {
await t.throwsAsync(async() => {
await jlogger(' ');
await jlogger(undefined);
}, { instanceOf: Error, message: '\'message\' parameter is mandatory' });
});

test('should throw an error since message is empty', async(t) => {
await t.throwsAsync(async() => {
await jlogger(' ');
await jlogger('');
}, { instanceOf: Error, message: '\'message\' parameter is mandatory' });
});

Expand Down Expand Up @@ -69,48 +69,3 @@ test('should not retrieve a log since tag consists of spaces', async(t) => {
}, { instanceOf: Error, message: '\'tag\' parameter is mandatory' });
});


// test('should retrieve a random face', (t) => {
// console.log(face);

// t.true(arrayOfFaces.indexOf(face) >= 0, 'face not found at faces array');
// });

// test('should retrieve a random face with the name or descrition', (t) => {
// console.dir(faceObj);

// t.true(Object.prototype.hasOwnProperty.call(faceObj, 'face'));
// t.true(Object.prototype.hasOwnProperty.call(faceObj, 'description'));
// t.true(prettyStringFaces.indexOf(faceObj.description) >= 0);
// t.true(arrayOfFaces.indexOf(faceObj.face) >= 0, 'face not found at faces array');
// });

// test('should retrieve string with all faces fo pretty print', (t) => {
// console.log(prettyStringFaces);

// t.assert(typeof prettyStringFaces === 'string');
// });

// test('should retrieve a random face by name', (t) => {
// const faceLike = facetxt.like('embarrassed');

// t.true(WHOLE_EMBARRASSED_FACES.indexOf(faceLike) >= 0);
// });

// test('should not retrieve a random face by name because does not exists', (t) => {
// const faceLike = facetxt.like('foz');

// t.is(typeof faceLike, 'undefined');
// });

// test('should retrieve the array related with name', (t) => {
// const faces = facetxt.likes('embarrassed');

// t.like(faces, WHOLE_EMBARRASSED_FACES);
// });

// test('should not retrieve the array related with name, because does not exists', (t) => {
// const faces = facetxt.likes('foz');

// t.true(faces.length === 0);
// });

0 comments on commit 7d2ff13

Please sign in to comment.