mirror of
				https://git.hibas.dev/OpenServer/NodeLogging.git
				synced 2025-11-03 22:40:45 +00:00 
			
		
		
		
	Changing filewrite behavior
This commit is contained in:
		@ -7,12 +7,7 @@ const MAX_FILE_SIZE = 500000000;
 | 
			
		||||
 | 
			
		||||
export class LoggingFiles implements Adapter {
 | 
			
		||||
   file: Files;
 | 
			
		||||
   constructor(
 | 
			
		||||
      private filename: string,
 | 
			
		||||
      private error = false,
 | 
			
		||||
      private maxFileSize = MAX_FILE_SIZE,
 | 
			
		||||
      private noPrefix = false
 | 
			
		||||
   ) {}
 | 
			
		||||
   constructor(private filename: string, private maxFileSize = MAX_FILE_SIZE) {}
 | 
			
		||||
 | 
			
		||||
   init() {
 | 
			
		||||
      if (!this.file) {
 | 
			
		||||
@ -58,20 +53,22 @@ export class Files {
 | 
			
		||||
   private stream: fs.WriteStream = undefined;
 | 
			
		||||
   private lock = new Lock();
 | 
			
		||||
 | 
			
		||||
   private $initialized = false;
 | 
			
		||||
   #initialized = false;
 | 
			
		||||
   #iv: any;
 | 
			
		||||
 | 
			
		||||
   public get initlialized() {
 | 
			
		||||
      return this.$initialized;
 | 
			
		||||
      return this.#initialized;
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   private constructor(private file: string) {}
 | 
			
		||||
 | 
			
		||||
   public async init(maxFileSize: number) {
 | 
			
		||||
      if (this.$initialized) return;
 | 
			
		||||
      if (this.#initialized) return;
 | 
			
		||||
      let lock = await this.lock.getLock();
 | 
			
		||||
      this.maxFileSize == maxFileSize;
 | 
			
		||||
      await this.initializeFile();
 | 
			
		||||
      this.$initialized = true;
 | 
			
		||||
      this.#initialized = true;
 | 
			
		||||
      this.#iv = setInterval(() => this.checkQueue(), 500);
 | 
			
		||||
      lock.release();
 | 
			
		||||
      this.checkQueue();
 | 
			
		||||
   }
 | 
			
		||||
@ -104,7 +101,7 @@ export class Files {
 | 
			
		||||
         this.size = size;
 | 
			
		||||
      } catch (e) {
 | 
			
		||||
         console.log(e);
 | 
			
		||||
         //ToDo is this the right behavior?
 | 
			
		||||
         //TODO: is this the right behavior?
 | 
			
		||||
         process.exit(1);
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
@ -125,10 +122,12 @@ export class Files {
 | 
			
		||||
      await this.flush(false);
 | 
			
		||||
      this.open--;
 | 
			
		||||
      if (this.open <= 0) {
 | 
			
		||||
         clearInterval(this.#iv);
 | 
			
		||||
         this.stream.close();
 | 
			
		||||
         Files.files.delete(this.file);
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   public flush(sync: boolean) {
 | 
			
		||||
      if (sync) {
 | 
			
		||||
         // if sync flush, the process most likely is in failstate, so checkQueue stopped its work.
 | 
			
		||||
@ -165,7 +164,6 @@ export class Files {
 | 
			
		||||
 | 
			
		||||
   public write(data: Buffer) {
 | 
			
		||||
      this.queue.push(data);
 | 
			
		||||
      this.checkQueue();
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   public dispose() {}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user