/**
 * Copyright 2018, OpenCensus Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ import * as util from 'util' ; import * as types from './types' ; const logDriver = require ( 'log-driver' ) ; /**
 * This class implements a console logger.
 */ export class ConsoleLogger implements types . Logger { private logger : typeof logDriver ; static LEVELS = [ 'silent' , 'error' , 'warn' , 'info' , 'debug' ] ; level ? : string ; param options constructor ( options ? ) { let opt = { } ; if ( typeof options === 'number' ) { if ( options < 0 ) { options = 0 ; } else if ( options > ConsoleLogger . LEVELS . length ) { options = ConsoleLogger . LEVELS . length - 1 ; } opt = { level : ConsoleLogger . LEVELS [ options ] } ; } else if ( typeof options === 'string' ) { opt = { level : options } ; } else { opt = options || { } ; } if ( opt . level ) this . level = opt . level ; this . logger = logDriver ( { levels : ConsoleLogger . LEVELS , level : opt . level || 'silent' , } ) ; } param message param args error ( message , ... args ) { this . logger . error ( util . format ( message , ... args ) ) ; } param message param args warn ( message , ... args ) { this . logger . warn ( util . format ( message , ... args ) ) ; } param message param args info ( message , ... args ) { this . logger . info ( util . format ( message , ... args ) ) ; } param message param args debug ( message , ... args ) { this . logger . debug ( util . format ( message , ... args ) ) ; } } param options const logger = ( options ? ) : types . Logger => { return new ConsoleLogger ( options ) ; } ; export { logger } ;