Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Storage Configuration #392

Open
chenyulun opened this issue Mar 20, 2024 · 4 comments
Open

Add Storage Configuration #392

chenyulun opened this issue Mar 20, 2024 · 4 comments

Comments

@chenyulun
Copy link

Can you realize that the current log is written to a file without a date, and the next day the file is dumped to a file with a date for backup, which is not the same as creating createSymlink?

Because our file-listening service (the log-collecting service) doesn't support createSymlink and can only listen to a single file

@Apollon77
Copy link
Collaborator

The current fikle which is there as symlink is not sufficient?

@chenyulun
Copy link
Author

我们的监听日志文件是用java写的,可能没有配置symlink的支持,我也fork了项目,添加了fixed_name,在创建文件的时候和备份日期的时候做了差异
file-stream-rotator/src/FileStreamRotator.ts

export default class FileStreamRotator extends EventEmitter {
  rotate(force: boolean = false) {
    let oldFile = this.currentFile;
    this.rotator.rotate(force);
    this.currentFile = this.rotator.getNewFilename();
    let _filename = this.currentFile;
    if (this.config.options?.fixed_name) {
      let logPath = path.dirname(this.currentFile);
      _filename = logPath + path.sep + this.config.options?.fixed_name;
    }

    // oldfile same as new file. do nothing
    if (this.currentFile == oldFile) {
      return;
    }

    // close old file and watcher if exists.
    if (this.fs) {
      // if (this.logWatcher) {
      //     this.logWatcher.close()
      // }
      if (this.config.options?.end_stream === true) {
        this.fs.end();
      } else {
        this.fs.destroy();
      }
      if (oldFile && this.config.options?.fixed_name) {
        this.saveOldLog(oldFile, _filename);
      }
    }

    // add old file to audit
    if (oldFile) {
      this.auditManager.addLog(oldFile);
    }

    this.createNewLog(_filename);
    this.emit('new', _filename);
    this.emit('rotate', oldFile, _filename, force);
  }

  private saveOldLog(saveFilename: string, filename: string) {
    makeDirectory(saveFilename);
    fs.copyFileSync(filename, saveFilename);
  }
}

@Apollon77
Copy link
Collaborator

@chenyulun Can you please write in english?

@chenyulun
Copy link
Author

Our listening log file is written in java, may not have configured symlink support, I also forked the project, added fixed_name, in the creation of the file and the backup date to do the differences

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants