Skip to content

Commit

Permalink
fix: changed logstash transport logic (#92)
Browse files Browse the repository at this point in the history
* fix: changed logstash transport logic

* docs: updated README

Co-authored-by: osher-sade <[email protected]>
  • Loading branch information
chenshoo and osher-sade authored Nov 25, 2020
1 parent 9face7f commit 22e5a84
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 123 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Ever wanted your logs to look pretty, to contain all the data you need in order

Through this interface you should set the following configuration to the `PolarisLogger`:

- **loggerLevel** (_LoggerLevel_) - The level the logger is listening on, can be one of the following levels: `fatal` /
- **loggerLevel** (_LoggerLevel | string_) - The level the logger is listening on, can be one of the following levels: `fatal` /
`error` / `warn` / `info` / `debug` / `trace`.
- **logstashConfigurations** (_LogstashConfiguration[] - optional_) - Through this property you can set multiple logstash
hosts, ports and protocols (**Notice that you can use `TCP`/`UDP` or `DYNAMIC` for each logstash config**).
Expand Down
59 changes: 7 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@
"dependencies": {
"@enigmatis/polaris-common": "^1.4.5",
"clean-deep": "^3.4.0",
"object-sizeof": "^1.6.1",
"serialize-error": "^7.0.1",
"uuid": "^8.3.1",
"winston": "^3.3.3",
"winston-logstash-ts": "^0.2.3",
"winston-dynamic-logstash-transport": "^0.0.2",
"winston-transport": "^4.4.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/configurations/logger-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LogstashConfiguration } from './logstash-configuration';
import { LoggerLevel } from './logger-level';

export interface LoggerConfiguration {
loggerLevel: LoggerLevel;
loggerLevel: LoggerLevel | string;
logstashConfigurations?: LogstashConfiguration[];
writeToConsole?: boolean;
writeFullMessageToConsole?: boolean;
Expand Down
22 changes: 0 additions & 22 deletions src/transports/dynamic-logstash-transport.ts

This file was deleted.

25 changes: 7 additions & 18 deletions src/winston-logger.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as winston from 'winston';
import { LoggerConfiguration } from './configurations/logger-configuration';
import { Logger } from './logger-with-custom-levels';
import { DynamicLogstashTransport } from './transports/dynamic-logstash-transport';
import { LogstashTransport } from 'winston-logstash-ts';
import { LogstashProtocol } from './configurations/logstash-protocol';
import { LogstashTransport } from 'winston-dynamic-logstash-transport';

const consoleTimestampFormat = 'DD-MM-YYYY HH:mm:ss';

Expand Down Expand Up @@ -65,22 +63,13 @@ export const createLogger = (loggerConfiguration: LoggerConfiguration): Logger =
logger.on('error', (error) => console.error('logger error!', error));

if (loggerConfiguration.logstashConfigurations) {
let logstashTransport: LogstashTransport | DynamicLogstashTransport;
loggerConfiguration.logstashConfigurations.forEach((logstashConfiguration) => {
if (logstashConfiguration.protocol === LogstashProtocol.DYNAMIC) {
logstashTransport = new DynamicLogstashTransport({
host: logstashConfiguration.host,
port: logstashConfiguration.port,
format: logstashFormat,
});
} else {
logstashTransport = new LogstashTransport({
host: logstashConfiguration.host,
port: logstashConfiguration.port,
protocol: logstashConfiguration.protocol,
format: logstashFormat,
});
}
const logstashTransport = new LogstashTransport({
host: logstashConfiguration.host,
port: logstashConfiguration.port,
protocol: logstashConfiguration.protocol,
format: logstashFormat,
});
logger.add(logstashTransport);
});
}
Expand Down
23 changes: 0 additions & 23 deletions test/dynamic-logstash-transport.test.ts

This file was deleted.

9 changes: 5 additions & 4 deletions test/winston-logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LoggerConfiguration } from '../src/configurations/logger-configuration'
import { LoggerLevel } from '../src/configurations/logger-level';
import { LogstashProtocol } from '../src/configurations/logstash-protocol';
import * as winstonLogger from '../src/winston-logger';
import { LogstashTransport } from 'winston-logstash-ts';
import { LogstashTransport } from 'winston-dynamic-logstash-transport';

jest.mock('winston', () => {
return {
Expand All @@ -27,7 +27,7 @@ jest.mock('winston', () => {
};
});

jest.mock('winston-logstash-ts');
jest.mock('winston-dynamic-logstash-transport');

describe('winston-logger tests', () => {
const loggerLevel = LoggerLevel.INFO;
Expand Down Expand Up @@ -115,14 +115,14 @@ describe('winston-logger tests', () => {
});

test('creating logger with configuration of dynamic logstash service', () => {
const anotherLogstashProtocol: LogstashProtocol = LogstashProtocol.DYNAMIC;
const dynamicLogstashProtocol: LogstashProtocol = LogstashProtocol.DYNAMIC;
const config: LoggerConfiguration = {
loggerLevel,
logstashConfigurations: [
{
host: logstashHost,
port: logstashPort,
protocol: anotherLogstashProtocol,
protocol: dynamicLogstashProtocol,
},
],
};
Expand All @@ -132,6 +132,7 @@ describe('winston-logger tests', () => {
expect(LogstashTransport).toHaveBeenCalledWith({
host: logstashHost,
port: logstashPort,
protocol: dynamicLogstashProtocol,
});
});

Expand Down

0 comments on commit 22e5a84

Please sign in to comment.