This commit is contained in:
root
2025-11-25 09:56:15 +03:00
commit 68c8f0e80d
23717 changed files with 3200521 additions and 0 deletions

22
mc_test/node_modules/winston-daily-rotate-file/LICENSE generated vendored Executable file
View File

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015-2024 winstonjs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

206
mc_test/node_modules/winston-daily-rotate-file/README.md generated vendored Executable file
View File

@ -0,0 +1,206 @@
# winston-daily-rotate-file
[![NPM version][npm-image]][npm-url]
[![NPM](https://nodei.co/npm/winston-daily-rotate-file.png)](https://nodei.co/npm/winston-daily-rotate-file/)
A transport for [winston](https://github.com/winstonjs/winston) which logs to a rotating file. Logs can be rotated based on a date, size limit, and old logs can be removed based on count or elapsed days.
Starting with version 2.0.0, the transport has been refactored to leverage the [file-stream-rotator](https://github.com/rogerc/file-stream-rotator/) module. _Some of the options in the 1.x versions of the transport have changed._ Please review the options below to identify any changes needed.
## Compatibility
Please note that if you are using `winston@2`, you will need to use `winston-daily-rotate-file@3`. `winston-daily-rotate-file@4` removed support for `winston@2`.
Starting with version 5.0.0 this module also emits an "error" event for all low level filesystem error cases. Make sure to listen for this event to prevent crashes in your application.
This library should work starting with Node.js 8.x, but tests are only executed for Node.js 14+. Use on your own risk in lower Node.js versions.
## Install
```
npm install winston-daily-rotate-file
```
## Options
The DailyRotateFile transport can rotate files by minute, hour, day, month, year or weekday. In addition to the options accepted by the logger, `winston-daily-rotate-file` also accepts the following options:
* **frequency:** A string representing the frequency of rotation. This is useful if you want to have timed rotations, as opposed to rotations that happen at specific moments in time. Valid values are '#m' or '#h' (e.g., '5m' or '3h'). Leaving this null relies on `datePattern` for the rotation times. (default: null)
* **datePattern:** A string representing the [moment.js date format](http://momentjs.com/docs/#/displaying/format/) to be used for rotating. The meta characters used in this string will dictate the frequency of the file rotation. For example, if your datePattern is simply 'HH' you will end up with 24 log files that are picked up and appended to every day. (default: 'YYYY-MM-DD')
* **zippedArchive:** A boolean to define whether or not to gzip archived log files. (default: 'false')
* **filename:** Filename to be used to log to. This filename can include the `%DATE%` placeholder which will include the formatted datePattern at that point in the filename. (default: 'winston.log.%DATE%')
* **dirname:** The directory name to save log files to. (default: '.')
* **stream:** Write directly to a custom stream and bypass the rotation capabilities. (default: null)
* **maxSize:** Maximum size of the file after which it will rotate. This can be a number of bytes, or units of kb, mb, and gb. If using the units, add 'k', 'm', or 'g' as the suffix. The units need to directly follow the number. (default: null)
* **maxFiles:** Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. It uses auditFile to keep track of the log files in a json format. It won't delete any file not contained in it. It can be a number of files or number of days (default: null)
* **options:** An object resembling https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options indicating additional options that should be passed to the file stream. (default: `{ flags: 'a' }`)
* **auditFile**: A string representing the path of the audit file, passed directly to [file-stream-rotator](https://github.com/rogerc/file-stream-rotator/) as `audit_file`. If not specified, a file name is generated that includes a hash computed from the options object, and uses the `dirname` option value as the directory. (default: `<dirname>/.<optionsHash>-audit.json`)
* **utc**: Use UTC time for date in filename. (default: false)
* **extension**: File extension to be appended to the filename. (default: '')
* **createSymlink**: Create a tailable symlink to the current active log file. (default: false)
* **symlinkName**: The name of the tailable symlink. (default: 'current.log')
* **auditHashType**: Use specified hashing algorithm for audit. (default: 'sha256')
* **level**: Name of the logging level that will be used for the transport, if not specified option from `createLogger` method will be used
## Usage
``` js
var winston = require('winston');
require('winston-daily-rotate-file');
var transport = new winston.transports.DailyRotateFile({
level: 'info',
filename: 'application-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});
transport.on('error', error => {
// log or handle errors here
});
transport.on('rotate', (oldFilename, newFilename) => {
// do something fun
});
var logger = winston.createLogger({
transports: [
transport
]
});
logger.info('Hello World!');
```
using multiple transports
``` js
var winston = require('winston');
require('winston-daily-rotate-file');
var transport1 = new winston.transports.DailyRotateFile({
filename: 'application-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});
var transport2 = new winston.transports.DailyRotateFile({
level: 'error',
filename: 'application-error-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});
transport1.on('error', error => {
// log or handle errors here
});
transport2.on('error', error => {
// log or handle errors here
});
transport1.on('rotate', function(oldFilename, newFilename) {
// do something fun
});
transport2.on('rotate', function(oldFilename, newFilename) {
// do something fun
});
var logger = winston.createLogger({
level: 'info'
transports: [
transport1, // will be used on info level
transport2 // will be used on error level
]
});
logger.info('Hello World!');
logger.error('Hello Error!');
```
### ES6
``` js
import * as winston from 'winston';
import 'winston-daily-rotate-file';
const transport = new winston.transports.DailyRotateFile({
filename: 'application-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});
transport.on('error', error => {
// log or handle errors here
});
transport.on('rotate', (oldFilename, newFilename) => {
// do something fun
});
const logger = winston.createLogger({
transports: [
transport
]
});
logger.info('Hello World!');
```
### Typescript
``` typescript
import * as winston from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';
const transport: DailyRotateFile = new DailyRotateFile({
filename: 'application-%DATE%.log',
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});
transport.on('error', error => {
// log or handle errors here
});
transport.on('rotate', (oldFilename, newFilename) => {
// do something fun
});
const logger = winston.createLogger({
transports: [
transport
]
});
logger.info('Hello World!');
```
This transport emits the following custom events:
* **new**: fired when a new log file is created. This event will pass one parameter to the callback (*newFilename*).
* **rotate**: fired when the log file is rotated. This event will pass two parameters to the callback (*oldFilename*, *newFilename*).
* **archive**: fired when the log file is archived. This event will pass one parameter to the callback (*zipFilename*).
* **logRemoved**: fired when a log file is removed from the file system. This event will pass one parameter to the callback (*removedFilename*).
* * **error**: fired when a low level filesystem error happens (e.g. EACCESS)
## LICENSE
MIT
##### AUTHOR: [Charlie Robbins](https://github.com/indexzero)
##### MAINTAINER: [Matt Berther](https://github.com/mattberther)
[npm-image]: https://badge.fury.io/js/winston-daily-rotate-file.svg
[npm-url]: https://npmjs.org/package/winston-daily-rotate-file

View File

@ -0,0 +1,368 @@
const fs = require("fs");
const os = require("os");
const path = require("path");
const util = require("util");
const zlib = require("zlib");
const hash = require("object-hash");
const MESSAGE = require("triple-beam").MESSAGE;
const PassThrough = require("stream").PassThrough;
const Transport = require("winston-transport");
const loggerDefaults = {
json: false,
colorize: false,
eol: os.EOL,
logstash: null,
prettyPrint: false,
label: null,
stringify: false,
depth: null,
showLevel: true,
timestamp: () => {
return new Date().toISOString();
}
};
const DailyRotateFile = function(options) {
options = options || {};
Transport.call(this, options);
function throwIf(target /* , illegal... */) {
Array.prototype.slice.call(arguments, 1).forEach((name) => {
if (options[name]) {
throw new Error("Cannot set " + name + " and " + target + " together");
}
});
}
function getMaxSize(size) {
if (size && typeof size === "string") {
if (size.toLowerCase().match(/^((?:0\.)?\d+)([kmg])$/)) {
return size;
}
} else if (size && Number.isInteger(size)) {
const sizeK = Math.round(size / 1024);
return sizeK === 0 ? "1k" : sizeK + "k";
}
return null;
}
function isValidFileName(filename) {
// eslint-disable-next-line no-control-regex
return !/["<>|:*?\\/\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]/g.test(
filename
);
}
function isValidDirName(dirname) {
// eslint-disable-next-line no-control-regex
return !/["<>|\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]/g.test(
dirname
);
}
this.options = Object.assign({}, loggerDefaults, options);
if (options.stream) {
throwIf("stream", "filename", "maxsize");
this.logStream = new PassThrough();
this.logStream.pipe(options.stream);
} else {
this.filename = options.filename
? path.basename(options.filename)
: "winston.log";
this.dirname = options.dirname || path.dirname(options.filename);
if (!isValidFileName(this.filename) || !isValidDirName(this.dirname)) {
throw new Error("Your path or filename contain an invalid character.");
}
this.logStream = require("file-stream-rotator").getStream({
filename: path.join(this.dirname, this.filename),
frequency: options.frequency ? options.frequency : "custom",
date_format: options.datePattern ? options.datePattern : "YYYY-MM-DD",
verbose: false,
size: getMaxSize(options.maxSize),
max_logs: options.maxFiles,
end_stream: true,
audit_file: options.auditFile
? options.auditFile
: path.join(this.dirname, "." + hash(options) + "-audit.json"),
file_options: options.options ? options.options : { flags: "a" },
utc: options.utc ? options.utc : false,
extension: options.extension ? options.extension : "",
create_symlink: options.createSymlink ? options.createSymlink : false,
symlink_name: options.symlinkName ? options.symlinkName : "current.log",
watch_log: options.watchLog ? options.watchLog : false,
audit_hash_type: options.auditHashType ? options.auditHashType : "sha256"
});
this.logStream.on("new", (newFile) => {
this.emit("new", newFile);
});
this.logStream.on("rotate", (oldFile, newFile) => {
this.emit("rotate", oldFile, newFile);
});
this.logStream.on("logRemoved", (params) => {
if (options.zippedArchive) {
const gzName = params.name + ".gz";
try {
fs.unlinkSync(gzName);
} catch (err) {
// ENOENT is okay, means file doesn't exist, other errors prevent deletion, so report it
if (err.code !== "ENOENT") {
err.message = `Error occurred while removing ${gzName}: ${err.message}`;
this.emit("error", err);
return;
}
}
this.emit("logRemoved", gzName);
return;
}
this.emit("logRemoved", params.name);
});
if (options.zippedArchive) {
this.logStream.on("rotate", (oldFile) => {
try {
if (!fs.existsSync(oldFile)) {
return;
}
} catch (err) {
err.message = `Error occurred while checking existence of ${oldFile}: ${err.message}`;
this.emit("error", err);
return;
}
try {
if (fs.existsSync(`${oldFile}.gz`)) {
return;
}
} catch (err) {
err.message = `Error occurred while checking existence of ${oldFile}.gz: ${err.message}`;
this.emit("error", err);
return;
}
const gzip = zlib.createGzip();
const inp = fs.createReadStream(oldFile);
inp.on("error", (err) => {
err.message = `Error occurred while reading ${oldFile}: ${err.message}`;
this.emit("error", err);
});
const out = fs.createWriteStream(oldFile + ".gz");
out.on("error", (err) => {
err.message = `Error occurred while writing ${oldFile}.gz: ${err.message}`;
this.emit("error", err);
});
inp
.pipe(gzip)
.pipe(out)
.on("finish", () => {
try {
fs.unlinkSync(oldFile);
} catch (err) {
if (err.code !== "ENOENT") {
err.message = `Error occurred while removing ${oldFile}: ${err.message}`;
this.emit("error", err);
return;
}
}
this.emit("archive", oldFile + ".gz");
});
});
}
if (options.watchLog) {
this.logStream.on("addWatcher", (newFile) => {
this.emit("addWatcher", newFile);
});
}
}
};
module.exports = DailyRotateFile;
util.inherits(DailyRotateFile, Transport);
DailyRotateFile.prototype.name = "dailyRotateFile";
const noop = function() {};
DailyRotateFile.prototype.log = function (info, callback) {
callback = callback || noop;
this.logStream.write(info[MESSAGE] + this.options.eol);
this.emit("logged", info);
callback(null, true);
};
DailyRotateFile.prototype.close = function () {
if (this.logStream) {
this.logStream.end(() => {
this.emit("finish");
});
}
};
DailyRotateFile.prototype.query = function (options, callback) {
if (typeof options === "function") {
callback = options;
options = {};
}
if (!this.options.json) {
throw new Error(
"query() may not be used without the json option being set to true"
);
}
if (!this.filename) {
throw new Error("query() may not be used when initializing with a stream");
}
let results = [];
options = options || {};
// limit
options.rows = options.rows || options.limit || 10;
// starting row offset
options.start = options.start || 0;
// now
options.until = options.until || new Date();
if (typeof options.until !== "object") {
options.until = new Date(options.until);
}
// now - 24
options.from = options.from || options.until - 24 * 60 * 60 * 1000;
if (typeof options.from !== "object") {
options.from = new Date(options.from);
}
// 'asc' or 'desc'
options.order = options.order || "desc";
const logFiles = (() => {
const fileRegex = new RegExp(this.filename.replace("%DATE%", ".*"), "i");
return fs.readdirSync(this.dirname).filter((file) => path.basename(file).match(fileRegex));
})();
if (logFiles.length === 0 && callback) {
callback(null, results);
}
const processLogFile = (file) => {
if (!file) {
return;
}
const logFile = path.join(this.dirname, file);
let buff = "";
let stream;
if (file.endsWith(".gz")) {
stream = new PassThrough();
const inp = fs.createReadStream(logFile);
inp.on("error", (err) => {
err.message = `Error occurred while reading ${logFile}: ${err.message}`;
stream.emit("error", err);
});
inp.pipe(zlib.createGunzip()).pipe(stream);
} else {
stream = fs.createReadStream(logFile, {
encoding: "utf8",
});
}
stream.on("error", (err) => {
if (stream.readable) {
stream.destroy();
}
if (!callback) {
return;
}
return err.code === "ENOENT" ? callback(null, results) : callback(err);
});
stream.on("data", (data) => {
data = (buff + data).split(/\n+/);
const l = data.length - 1;
for (let i = 0; i < l; i++) {
add(data[i]);
}
buff = data[l];
});
stream.on("end", () => {
if (buff) {
add(buff, true);
}
if (logFiles.length) {
processLogFile(logFiles.shift());
} else if (callback) {
results.sort( (a, b) => {
const d1 = new Date(a.timestamp).getTime();
const d2 = new Date(b.timestamp).getTime();
return d1 > d2 ? 1 : d1 < d2 ? -1 : 0;
});
if (options.order === "desc") {
results = results.reverse();
}
const start = options.start || 0;
const limit = options.limit || results.length;
results = results.slice(start, start + limit);
if (options.fields) {
results = results.map( (log) => {
const obj = {};
options.fields.forEach( (key) => {
obj[key] = log[key];
});
return obj;
});
}
callback(null, results);
}
});
function add(buff, attempt) {
try {
const log = JSON.parse(buff);
if (!log || typeof log !== "object") {
return;
}
const time = new Date(log.timestamp);
if (
(options.from && time < options.from) ||
(options.until && time > options.until) ||
(options.level && options.level !== log.level)
) {
return;
}
results.push(log);
} catch (e) {
if (!attempt) {
stream.emit("error", e);
}
}
}
};
processLogFile(logFiles.shift());
};

120
mc_test/node_modules/winston-daily-rotate-file/index.d.ts generated vendored Executable file
View File

@ -0,0 +1,120 @@
import TransportStream = require("winston-transport");
// referenced from https://stackoverflow.com/questions/40510611/typescript-interface-require-one-of-two-properties-to-exist
type RequireOnlyOne<T, Keys extends keyof T = keyof T> =
Pick<T, Exclude<keyof T, Keys>>
& {
[K in Keys]-?:
Pick<T, K>
& Partial<Record<Exclude<Keys, K>, undefined>>
}[Keys];
// merging into winston.transports
declare module 'winston/lib/winston/transports' {
interface Transports {
DailyRotateFile: typeof DailyRotateFile;
DailyRotateFileTransportOptions: DailyRotateFile.DailyRotateFileTransportOptions;
}
}
declare namespace DailyRotateFile {
type DailyRotateFileTransportOptions = RequireOnlyOne<GeneralDailyRotateFileTransportOptions, 'filename' | 'stream'>;
interface GeneralDailyRotateFileTransportOptions extends TransportStream.TransportStreamOptions {
json?: boolean;
eol?: string;
/**
* A string representing the moment.js date format to be used for rotating. The meta characters used in this string will dictate the frequency of the file rotation. For example, if your datePattern is simply 'HH' you will end up with 24 log files that are picked up and appended to every day. (default 'YYYY-MM-DD')
*/
datePattern?: string;
/**
* A boolean to define whether or not to gzip archived log files. (default 'false')
*/
zippedArchive?: boolean;
/**
* Filename to be used to log to. This filename can include the %DATE% placeholder which will include the formatted datePattern at that point in the filename. (default: 'winston.log.%DATE%)
*/
filename?: string;
/**
* The directory name to save log files to. (default: '.')
*/
dirname?: string;
/**
* Write directly to a custom stream and bypass the rotation capabilities. (default: null)
*/
stream?: NodeJS.WritableStream;
/**
* Maximum size of the file after which it will rotate. This can be a number of bytes, or units of kb, mb, and gb. If using the units, add 'k', 'm', or 'g' as the suffix. The units need to directly follow the number. (default: null)
*/
maxSize?: string | number;
/**
* Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. (default: null)
*/
maxFiles?: string | number;
/**
* An object resembling https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options indicating additional options that should be passed to the file stream. (default: `{ flags: 'a' }`)
*/
options?: string | object;
/**
* A string representing the name of the audit file. (default: './hash-audit.json')
*/
auditFile?: string;
/**
* A string representing the frequency of rotation. (default: 'custom')
*/
frequency?: string;
/**
* A boolean whether or not to generate file name from "datePattern" in UTC format. (default: false)
*/
utc?: boolean;
/**
* A string representing an extension to be added to the filename, if not included in the filename property. (default: '')
*/
extension?: string;
/**
* Create a tailable symlink to the current active log file. (default: false)
*/
createSymlink?: boolean;
/**
* The name of the tailable symlink. (default: 'current.log')
*/
symlinkName?: string;
/**
* Watch the current file being written to and recreate it in case of accidental deletion. (default: FALSE)
*/
watchLog?: boolean;
handleRejections?: boolean;
/**
* Use specified hashing algorithm for audit. (default: 'sha256')
*/
auditHashType?: string;
}
}
declare class DailyRotateFile extends TransportStream {
filename: string;
dirname: string;
logStream: NodeJS.WritableStream;
options: DailyRotateFile.DailyRotateFileTransportOptions;
constructor(options?: DailyRotateFile.DailyRotateFileTransportOptions);
}
export = DailyRotateFile;

5
mc_test/node_modules/winston-daily-rotate-file/index.js generated vendored Executable file
View File

@ -0,0 +1,5 @@
const winston = require("winston");
const DailyRotateFile = require("./daily-rotate-file");
winston.transports.DailyRotateFile = DailyRotateFile;
module.exports = DailyRotateFile;

54
mc_test/node_modules/winston-daily-rotate-file/package.json generated vendored Executable file
View File

@ -0,0 +1,54 @@
{
"name": "winston-daily-rotate-file",
"version": "5.0.0",
"description": "A transport for winston which logs to a rotating file each day.",
"main": "index.js",
"types": "index.d.ts",
"engines": {
"node": ">=8"
},
"scripts": {
"test": "mocha --ignore **/*.worker.js && eslint .",
"release": "release-script"
},
"repository": {
"type": "git",
"url": "git@github.com:winstonjs/winston-daily-rotate-file.git"
},
"keywords": [
"winston",
"daily-rotate-file",
"log-rotate",
"logrotate"
],
"author": "Charlie Robbins <charlie.robbins@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/winstonjs/winston-daily-rotate-file/issues"
},
"files": [
"daily-rotate-file.js",
"index.js",
"index.d.ts"
],
"homepage": "https://github.com/winstonjs/winston-daily-rotate-file#readme",
"peerDependencies": {
"winston": "^3"
},
"devDependencies": {
"@alcalzone/release-script": "^3.7.0",
"@alcalzone/release-script-plugin-license": "^3.7.0",
"chai": "^4.4.1",
"eslint": "^8.56.0",
"eslint-plugin-node": "^11.1.0",
"mocha": "^10.2.0",
"rimraf": "^5.0.5",
"threads": "^1.7.0"
},
"dependencies": {
"file-stream-rotator": "^0.6.1",
"object-hash": "^3.0.0",
"triple-beam": "^1.4.1",
"winston-transport": "^4.7.0"
}
}