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

[feat]暴露formatter时FILENAME_SEP参数进行配置传入 #67

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/RollingFileWriteStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ class RollingFileWriteStream extends Writable {
alwaysIncludeDate: this.options.alwaysIncludePattern,
needsIndex: this.options.maxSize < Number.MAX_SAFE_INTEGER,
compress: this.options.compress,
keepFileExt: this.options.keepFileExt
keepFileExt: this.options.keepFileExt,
fileNameSep: this.options.fileNameSep
});

this.fileNameParser = fileNameParser({
file: this.fileObject,
keepFileExt: this.options.keepFileExt,
pattern: this.options.pattern
pattern: this.options.pattern,
fileNameSep: this.options.fileNameSep
});

this.state = {
Expand Down Expand Up @@ -246,7 +248,7 @@ class RollingFileWriteStream extends Writable {
debug("_clean: existing files are: ", existingFileDetails);
if (this._tooManyFiles(existingFileDetails.length)) {
const fileNamesToRemove = existingFileDetails
.slice(0, existingFileDetails.length - this.options.numToKeep - 1)
.slice(0, existingFileDetails.length - this.options.numToKeep)
lamweili marked this conversation as resolved.
Show resolved Hide resolved
.map(f => path.format({ dir: this.fileObject.dir, base: f.filename }));
await deleteFiles(fileNamesToRemove);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/fileNameFormatter.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const debug = require("debug")("streamroller:fileNameFormatter");
const path = require("path");
const FILENAME_SEP = ".";
const ZIP_EXT = ".gz";
let FILENAME_SEP = ".";

module.exports = ({
file,
keepFileExt,
needsIndex,
alwaysIncludeDate,
compress
compress,
fileNameSep
}) => {
FILENAME_SEP = fileNameSep || FILENAME_SEP;
const dirAndName = path.join(file.dir, file.name);

const ext = f => f + file.ext;
Expand Down
6 changes: 3 additions & 3 deletions lib/fileNameParser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const debug = require("debug")("streamroller:fileNameParser");
const FILENAME_SEP = ".";
const ZIP_EXT = ".gz";
const format = require("date-format");

module.exports = ({ file, keepFileExt, pattern }) => {
let FILENAME_SEP = ".";
module.exports = ({ file, keepFileExt, pattern, fileNameSep }) => {
FILENAME_SEP = fileNameSep || FILENAME_SEP;
// All these functions take two arguments: f, the filename, and p, the result placeholder
// They return the filename with any matching parts removed.
// The "zip" function, for instance, removes the ".gz" part of the filename (if present)
Expand Down