Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 22.x
- run: npm install && cd example/browser && npm install
- run: docker run --name seq -d -p 5341:80 -e ACCEPT_EULA=Y datalust/seq:latest
- run: cd example/browser && npm run test:html
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [18.x, 20.x, 22.x]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
node-version: 18
- run: npm ci
- run: npm test

Expand All @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
### Requiring for Node

```js
const seq = require('seq-logging');
import { Logger } from 'seq-logging';
```

### Requiring for a browser

Using `seq-logging` in a browser context is the same, except the module to import is `seq-logging/browser`.

```js
const seq = require('seq-logging/browser');
import { Logger } from 'seq-logging/browser';
```

### Usage
Expand All @@ -22,10 +22,10 @@ A `Logger` is configured with `serverUrl`, and optionally `apiKey` as well as ev
`requestTimeout` can be used to adjust timeout for stalled connections, default: 30s.

```js
const process = require('process');
const seq = require('seq-logging');
import process from 'process';
import { Logger } from 'seq-logging';

const logger = new seq.Logger({ serverUrl: 'http://localhost:5341' });
const logger = new Logger({ serverUrl: 'http://localhost:5341' });

logger.emit({
timestamp: new Date(),
Expand Down
12 changes: 10 additions & 2 deletions browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
"use strict";

let Logger = require('./seq_logger')(Blob, fetch, typeof AbortController !== 'undefined' ? AbortController : require('abort-controller'));
// Variable used to force testing fallback modules
// This should remain false, but can be changed in testing
const fallback = false;

module.exports = {Logger};
const Logger = (await import('./seq_logger.js')).DefineLogger(
Blob,
fetch,
!fallback && typeof AbortController !== 'undefined' ? AbortController : (await import('abort-controller')).AbortController
);

export { Logger };
10 changes: 10 additions & 0 deletions example/browser/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
video: false,
e2e: {
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
},
})
3 changes: 0 additions & 3 deletions example/browser/cypress.json

This file was deleted.

14 changes: 7 additions & 7 deletions example/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"seq-logging": "file:../../"
},
"devDependencies": {
"@cypress/webpack-dev-server": "^1.3",
"cypress": "^7.5",
"html-loader": "^2.1",
"html-webpack-plugin": "^5.3",
"webpack": "^5.38",
"webpack-cli": "^4.7",
"webpack-dev-server": "^3.11"
"@cypress/webpack-dev-server": "^4.0.2",
"cypress": "^14.3.2",
"html-loader": "^5.1.0",
"html-webpack-plugin": "^5.6.3",
"webpack": "^5.99.7",
"webpack-cli": "^6.0.1",
"webpack-dev-server": "^5.2.1"
}
}
4 changes: 2 additions & 2 deletions example/browser/src/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
Create a logger that can write events to Seq.
*/

import seq from 'seq-logging/browser';
import { Logger as SeqLogger } from 'seq-logging/browser';
import status from './status';

export default (messageTemplate) => {
// Connect to the Seq server
const logger = new seq.Logger({ serverUrl: 'http://localhost:5341' });
const logger = new SeqLogger({ serverUrl: 'http://localhost:5341' });

// When the button is hit, send an event to Seq
document.getElementById('log-event').addEventListener('click', () => {
Expand Down
9 changes: 4 additions & 5 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use strict";

let process = require('process');
let SeqLogger = require('../index').Logger;
import process from 'process';
import { Logger as SeqLogger } from '../index.js';

let seq = new SeqLogger({ serverUrl: 'http://localhost:5341' });
const seq = new SeqLogger({ serverUrl: 'http://localhost:5341' });
var n = 0;

let interval = setInterval(sayHello, 100);
const interval = setInterval(sayHello, 100);

function sayHello() {
n = n + 1;
Expand All @@ -31,4 +31,3 @@ function sayHello() {
seq.close();
}
}

7 changes: 3 additions & 4 deletions example/example_async.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

let process = require('process');
let SeqLogger = require('../index').Logger;
import process from 'process';
import { Logger as SeqLogger } from '../index.js';

let seq = new SeqLogger({ serverUrl: 'http://localhost:5341', onRemoteConfigChange: (config) => {
const seq = new SeqLogger({ serverUrl: 'http://localhost:5341', onRemoteConfigChange: (config) => {
console.log(config);
}});

Expand All @@ -30,4 +30,3 @@ async function sayHello(times) {
}
}
}

14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"use strict";

let Logger = require('./seq_logger')(
typeof Blob !== 'undefined' ? Blob : require('buffer').Blob,
typeof fetch !== 'undefined' ? fetch : require('node-fetch'),
typeof AbortController !== 'undefined' ? AbortController : require('abort-controller')
// Variable used to force testing fallback modules
// This should remain false, but can be changed in testing
const fallback = false;

const Logger = (await import('./seq_logger.js')).DefineLogger(
!fallback && typeof Blob !== 'undefined' ? Blob : (await import('buffer')).Blob,
!fallback && typeof fetch !== 'undefined' ? fetch : (await import('node-fetch')).default,
!fallback && typeof AbortController !== 'undefined' ? AbortController : (await import('abort-controller')).AbortController
);

module.exports = {Logger};
export { Logger };
Loading