import IStoreWriter from "./IStoreWriter" ; import IStoreReader from "./IStoreReader" ; export default class StoreLogger implements IStoreWriter , IStoreReader { writer : IStoreWriter ; reader : IStoreReader ; constructor ( _writer , _reader ) { this . writer = _writer ; this . reader = _reader ; } public read ( id ) { this . reading ( id ) ; var retValue = this . reader . read ( id ) ; if ( retValue === undefined ) { this . didNotFind ( id ) ; } else { this . returning ( id ) ; } return retValue ; } public save ( id , message ) { this . saving ( id ) ; try { this . writer . save ( id , message ) ; } catch ( err ) { console . log ( err ) ; this . errorSaving ( id ) ; } this . saved ( id ) ; } public saving ( id ) { console . log ( `Saving message ${ id }.` ) ; } public saved ( id ) { console . info ( `Saved message ${ id }.` ) ; } public reading ( id ) { console . debug ( `Reading message ${ id }.` ) ; } public didNotFind ( id ) { console . debug ( `No message ${ id } found.` ) ; } public missingFromCache ( id ) { console . debug ( `Message ${ id } missing from cache.` ) ; } public returning ( id ) { console . debug ( `Returning message ${ id }.` ) ; } public errorSaving ( id ) { console . error ( `Error saving message ${ id }.` ) ; } }