From 7af93bbe01d6afc24cc39896d0b32e096a4e7159 Mon Sep 17 00:00:00 2001 From: Dave Raffensperger Date: Thu, 10 Jan 2019 17:31:55 -0500 Subject: [PATCH] Simplify Logger interface, remove silly, make level optional (#271) * Simplify Logger interface, remove silly, make level optional * Add changelog line * Added line to note that there is a specific breaking change for trace --- CHANGELOG.md | 4 ++++ .../src/common/console-logger.ts | 12 +---------- packages/opencensus-core/src/common/types.ts | 5 +++-- .../test/test-console-logger.ts | 20 +------------------ .../test/test-stackdriver-monitoring.ts | 2 -- 5 files changed, 9 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f5d6c756..399d47161 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ All notable changes to this project will be documented in this file. - Add support for supplying instrumentation configuration via tracing option. Option argument added to instrumentation interface. - Add ignoreIncomingPaths and ignoreOutgoingUrls support to the http and https tracing instrumentations. + **Contains API breaking changes for trace implementations** + +- Modify `Logger` interface: `level` made optional, `silly` removed. + ## 0.0.8 - 2018-12-14 **Contains API breaking changes for stats/metrics implementations** diff --git a/packages/opencensus-core/src/common/console-logger.ts b/packages/opencensus-core/src/common/console-logger.ts index 0033f664c..ed35f961d 100644 --- a/packages/opencensus-core/src/common/console-logger.ts +++ b/packages/opencensus-core/src/common/console-logger.ts @@ -24,7 +24,7 @@ const logDriver = require('log-driver'); */ export class ConsoleLogger implements types.Logger { private logger: typeof logDriver; - static LEVELS = ['silent', 'error', 'warn', 'info', 'debug', 'silly']; + static LEVELS = ['silent', 'error', 'warn', 'info', 'debug']; level: string; /** @@ -89,16 +89,6 @@ export class ConsoleLogger implements types.Logger { debug(message: any, ...args: any[]): void { this.logger.debug(util.format(message, ...args)); } - - /** - * Logger silly function. - * @param message menssage silly to log in console - * @param args arguments to log in console - */ - // tslint:disable-next-line:no-any - silly(message: any, ...args: any[]): void { - this.logger.silly(util.format(message, ...args)); - } } /** diff --git a/packages/opencensus-core/src/common/types.ts b/packages/opencensus-core/src/common/types.ts index 71005cb05..152b9053c 100644 --- a/packages/opencensus-core/src/common/types.ts +++ b/packages/opencensus-core/src/common/types.ts @@ -19,12 +19,13 @@ export type LogFunction = (message: any, ...args: any[]) => void; /** Defines an logger interface. */ export interface Logger { - level: string; + /** Logger verbosity level. If omitted, `debug` level is assumed. */ + level?: string; + error: LogFunction; warn: LogFunction; info: LogFunction; debug: LogFunction; - silly: LogFunction; } /** Defines an logger options interface. */ diff --git a/packages/opencensus-core/test/test-console-logger.ts b/packages/opencensus-core/test/test-console-logger.ts index 32d1960a0..f274a2c78 100644 --- a/packages/opencensus-core/test/test-console-logger.ts +++ b/packages/opencensus-core/test/test-console-logger.ts @@ -19,7 +19,7 @@ import * as logger from '../src/common/console-logger'; import {ConsoleLogger} from '../src/common/console-logger'; -const LEVELS = ['silent', 'error', 'warn', 'info', 'debug', 'silly']; +const LEVELS = ['silent', 'error', 'warn', 'info', 'debug']; let consoleTxt = ''; // TODO: Review test cases: Maybe testing the info log level is sufficient @@ -86,15 +86,6 @@ describe('ConsoleLogger', () => { assert.equal(validateString, -1); }); - - it('should not log silly', () => { - consoleTxt = ''; - consoleLogger.silly('silly test logger'); - unhookIntercept(); - const validateString = consoleTxt.indexOf('silly'); - - assert.equal(validateString, -1); - }); }); /** Should disable logger */ @@ -138,14 +129,5 @@ describe('ConsoleLogger', () => { assert.equal(validateString, -1); }); - - it('should not log silly', () => { - consoleTxt = ''; - consoleLogger.silly('silly test logger'); - unhookIntercept(); - const validateString = consoleTxt.indexOf('silly'); - - assert.equal(validateString, -1); - }); }); }); diff --git a/packages/opencensus-exporter-stackdriver/test/test-stackdriver-monitoring.ts b/packages/opencensus-exporter-stackdriver/test/test-stackdriver-monitoring.ts index 2cbdf6a27..82b8a2630 100644 --- a/packages/opencensus-exporter-stackdriver/test/test-stackdriver-monitoring.ts +++ b/packages/opencensus-exporter-stackdriver/test/test-stackdriver-monitoring.ts @@ -44,8 +44,6 @@ class ExporterTestLogger implements Logger { warn(...args: any[]) {} // tslint:disable-next-line:no-any info(...args: any[]) {} - // tslint:disable-next-line:no-any - silly(...args: any[]) {} } describe('Stackdriver Stats Exporter', function() {