import * as log4javascript from "log4javascript" ; import { LogLevelConverter } from "./log-level.converter" ; import { LogLevel } from "./log-level.model" ; import { LogMessage } from "./log-message.model" ; import { MemoryAppenderConfiguration } from "./memory-appender.configuration" ; /**
 * An appender which stores the log messages in the browser's memory.
 *
 * The MemoryAppender is enabled by default.
 * If you do not specify anything else, it is using this configuration:
 *
 * ```JSON
 * {
 *   "memoryAppender": [
 *     {
 *       "maxMessages": 250,
 *       "threshold": "ALL"
 *     }
 * }
 * ```
 */ export class MemoryAppender extends log4javascript . Appender { private static maxMessagesDefault = 250 ; private static thresholdDefault = "ALL" ; private maxMessages : number ; private logMessages : LogMessage [ ] ; private onLogMessagesChangedCallback : ( message : LogMessage ) => void ; param configuration constructor ( configuration ? ) { super ( ) ; this . logMessages = [ ] ; configuration = configuration || { } ; this . configure ( { maxMessages : configuration . maxMessages || MemoryAppender . maxMessagesDefault , threshold : configuration . threshold || MemoryAppender . thresholdDefault , } ) ; this . maxMessages = MemoryAppender . maxMessagesDefault ; } param configuration public configure ( configuration ) { if ( configuration ) { if ( configuration . maxMessages ) { this . setMaxMessages ( configuration . maxMessages ) ; } if ( configuration . threshold ) { const convertedThreshold = LogLevelConverter . levelToLog4Javascript ( LogLevelConverter . levelFromString ( configuration . threshold ) ) ; this . setThreshold ( convertedThreshold ) ; } } } param loggingEvent public append ( loggingEvent ) { while ( this . logMessages . length >= this . maxMessages ) { this . logMessages . shift ( ) ; } const message = { level : LogLevel [ LogLevelConverter . levelFromLog4Javascript ( loggingEvent . level ) ] , logger : typeof loggingEvent . logger === "object" ? loggingEvent . logger . name : undefined , message : loggingEvent . messages . slice ( 1 ) , methodName : loggingEvent . messages [ 0 ] , timeStamp : loggingEvent . timeStamp , } ; this . logMessages . push ( message ) ; if ( typeof this . onLogMessagesChangedCallback === "function" ) { this . onLogMessagesChangedCallback ( message ) ; } } return public toString ( ) { return "Ionic.Logging.MemoryAppender" ; } /**
     * Get the maximum number of messages which will be stored in memory.
     */ public getMaxMessages ( ) { return this . maxMessages ; } param value public setMaxMessages ( value ) { this . maxMessages = value ; if ( this . logMessages . length > this . maxMessages ) { this . logMessages . splice ( 0 , this . logMessages . length - this . maxMessages ) ; } } return public getLogMessages ( ) { return this . logMessages ; } /**
     * Remove all messages stored in memory.
     */ public removeLogMessages ( ) { this . logMessages . splice ( 0 ) ; } param callback public setOnLogMessagesChangedCallback ( callback ) { this . onLogMessagesChangedCallback = callback ; } }