/**
 * Copyright 2019 Twitter, Inc.
 * Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 */ import { AbstractLogger } from "../util/Logger" ; import { LogProperties } from "../api/log" ; import * as util from "util" ; export class TestLogger extends AbstractLogger { readonly messages : { msg : string ; level : string ; } [ ] = [ ] ; countErrors ( ) { let errorCount = 0 ; for ( const { level } of this . messages ) { if ( level === "trace" || level === "debug" || level === "info" ) { continue ; } errorCount += 1 ; } return errorCount ; } popLatest ( props ) { const { level } = props ; for ( let idx = this . messages . length - 1 ; idx >= 0 ; idx -- ) { if ( this . messages [ idx ] . level === level ) { return this . messages . splice ( idx , 1 ) [ 0 ] ; } } throw new Error ( "No log line found" ) ; } log ( level , props , format , ... param ) { const message = util . format ( format , ... param ) ; this . messages . push ( { msg : message , level , } ) ; console . error ( message ) ; } }