Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
remove splunk transport so that apps only use the splunkHEC transport (
Browse files Browse the repository at this point in the history
…#75)

* remove splunk transport so that apps only use the splunkHEC transport
 🐿 v2.10.3

* Update README to remove Splunk forwarder references
 🐿 v2.10.3
  • Loading branch information
kitkat119 authored Sep 21, 2018
1 parent 2492163 commit 5b972ad
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 240 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Next Logger [![Circle CI](https://circleci.com/gh/Financial-Times/n-logger.svg?style=svg)](https://circleci.com/gh/Financial-Times/n-logger)

Logging utility
N-logger is a Winston wrapper which sends logs to Splunk's Http Event Collector (HEC).

## Installation

npm install @financial-times/n-logger

Ensure `SPLUNK_HEC_TOKEN` is in the app's shared folder in Vault.

## Usage

Expand All @@ -15,6 +16,7 @@ Logging utility
logger.info('Saying hello');
logger.warn('Everything’s mostly cool');
logger.error('Uh-oh', { field: 'some value' });
logger.info({ event: 'UPDATE_NOTIFICATION', data: data });

const err = new Error('Whoops!');
logger.error('Uh-oh', err, { extra_field: 'boo' });
Expand All @@ -25,14 +27,14 @@ If using CommonJS modules

### Loggers

By default
By default, the following loggers are added:

* the `console` logger is added
* logger level can be set by `CONSOLE_LOG_LEVEL` env variable; defaults to `silly`
* the `splunk` logger is added if `NODE_ENV === production`
* logger level can be set by `SPLUNK_LOG_LEVEL` env variable; defaults to `warn`
* the `splunkHEC` logger is added if `NODE_ENV === production && SPLUNK_HEC_TOKEN`
* logger level can be set by `SPLUNK_LOG_LEVEL` env variable; defaults to `warn`
* The `console` logger
* logger level can be set by `CONSOLE_LOG_LEVEL` env var (defaults to `silly`).


* The `splunkHEC` logger, if `NODE_ENV === production && SPLUNK_HEC_TOKEN`
* logger level can be set by `SPLUNK_LOG_LEVEL` env var (defaults to `warn`).

### API

Expand All @@ -48,10 +50,6 @@ By default

#### removeConsole()

#### addSplunk(splunkUrl, level = 'info', opts = {})

#### removeSplunk()

#### addSplunkHEC(level = 'info', opts = {})

#### removeSplunkHEC()
Expand Down
19 changes: 0 additions & 19 deletions src/lib/agent.js

This file was deleted.

24 changes: 1 addition & 23 deletions src/lib/app-logger.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import winston from 'winston';

import Logger from './logger';
import Splunk from './transports/splunk';
import SplunkHEC from './transports/splunkHEC';

class AppLogger extends Logger {

constructor (deps = {}) {
super(deps);
Object.assign(this.deps, { winston, Splunk, SplunkHEC }, deps);
Object.assign(this.deps, { winston, SplunkHEC }, deps);
this.logger = new (this.deps.winston.Logger)({
transports: [
new (this.deps.winston.transports.Console)({
Expand Down Expand Up @@ -40,27 +39,6 @@ class AppLogger extends Logger {
this.logger.remove('console');
}

addSplunk (splunkUrl, level = 'info', opts = {}) {
if (this.logger.transports.splunk) {
return;
}
if (!splunkUrl) {
this.warn('No `splunkUrl` supplied');
return false;
}
this.logger.add(
this.deps.Splunk,
Object.assign({ level, splunkUrl }, opts)
);
}

removeSplunk () {
if (!this.logger.transports.splunk) {
return;
}
this.logger.remove('splunk');
}

addSplunkHEC (level = 'info', opts = {}) {
if (this.logger.transports.splunkHEC) {
return;
Expand Down
35 changes: 0 additions & 35 deletions src/lib/transports/splunk.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ const getLogger = () => {
logger.addSplunkHEC(process.env.SPLUNK_LOG_LEVEL || 'warn');
}

// log to splunk only in production
if (process.env.NODE_ENV === 'production' && process.env.SPLUNK_URL) {
logger.addSplunk(process.env.SPLUNK_URL, process.env.SPLUNK_LOG_LEVEL || 'warn');
}
return logger;
}
};
Expand Down
48 changes: 0 additions & 48 deletions test/lib/agent.test.js

This file was deleted.

60 changes: 0 additions & 60 deletions test/lib/app-logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,66 +183,6 @@ describe('Logger', () => {

});

describe('#addSplunk', () => {

it('should be able to add a splunk logger', () => {
const addSpy = sinon.spy();
const SplunkSpy = sinon.spy();
const winston = winstonStub({ add: addSpy });
const logger = new Logger({ winston, Splunk: SplunkSpy });
logger.addSplunk('http://splunk.ft.com');
addSpy.should.always.have.been.calledWithExactly(SplunkSpy, { level: 'info', splunkUrl: 'http://splunk.ft.com' });
});

it('should be able to set the console logger\'s level', () => {
const addSpy = sinon.spy();
const SplunkSpy = sinon.spy();
const winston = winstonStub({ add: addSpy });
const logger = new Logger({ winston, Splunk: SplunkSpy });
logger.addSplunk('http://splunk.ft.com', 'warn');
addSpy.should.always.have.been.calledWithExactly(SplunkSpy, { level: 'warn', splunkUrl: 'http://splunk.ft.com' });
});

it('should return false if no `splunkUrl` supplied', () => {
const addSpy = sinon.spy();
const SplunkSpy = sinon.spy();
const winston = winstonStub({ add: addSpy });
const logger = new Logger({ winston, Splunk: SplunkSpy });
logger.addSplunk().should.be.false;
addSpy.should.not.have.been.called;
});

it('should not be able to add if already added', () => {
const addSpy = sinon.spy(function () { this.transports.splunk = true; });
const winston = winstonStub({ add: addSpy });
const logger = new Logger({ winston });
logger.addSplunk('http://splunk.ft.com');
logger.addSplunk('http://splunk.ft.com');
addSpy.should.have.been.calledOnce;
});

});

describe('#removeSplunk', () => {

it('should be able to remove', () => {
const removeSpy = sinon.spy();
const winston = winstonStub({ remove: removeSpy, transports: { splunk: true } });
const logger = new Logger({ winston });
logger.removeSplunk();
removeSpy.should.always.have.been.calledWithExactly('splunk');
});

it('should not be able to remove if not added', () => {
const removeSpy = sinon.spy();
const winston = winstonStub({ remove: removeSpy });
const logger = new Logger({ winston });
logger.removeSplunk();
removeSpy.should.not.have.been.called;
});

});

describe('#addSplunkHEC', () => {

it('should be able to add a splunkHEC logger', () => {
Expand Down
39 changes: 0 additions & 39 deletions test/lib/transports/splunk.test.js

This file was deleted.

0 comments on commit 5b972ad

Please sign in to comment.