import BlobWriter , { readBlob } from "./azure-container" ; export default class RollingLogs { static async create ( name , maxLines ) { return new RollingLogs ( name , maxLines , await BlobWriter . create ( ) ) ; } private allLogs : string [ ] | undefined ; constructor ( readonly name , readonly maxLines , private readonly container ) { } async write ( lines ) { const logs = this . allLogs || ( this . allLogs = await this . readAllLogs ( ) ) ; const totalLines = logs . length + lines . length ; logs . splice ( 0 , totalLines - this . maxLines ) ; logs . push ( ... lines ) ; await this . container . createBlobFromText ( this . name , logs . join ( "\n" ) ) ; } private async readAllLogs ( ) { try { return ( await readBlob ( this . name ) ) . split ( "\n" ) ; } catch ( err ) { return [ ] ; } } }