@boost/log
Version:
Lightweight level based logging system.
72 lines • 2.56 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import fs from 'node:fs';
import zlib from 'node:zlib';
import { Path, type PortablePath } from '@boost/common';
import { type Blueprint, type Schemas } from '@boost/common/optimal';
import { Transport } from '../Transport';
import type { TransportOptions } from '../types';
export interface FileTransportOptions extends TransportOptions {
/** Apply gzip compression to the write stream. */
gzip?: boolean;
/**
* Maximum file size before rotating file.
* Will create a backup and truncate the current file. Defaults to 10mb.
*/
maxSize?: number;
/** Absolute file system path for the intended log file. */
path: PortablePath;
}
export declare class FileTransport<Options extends FileTransportOptions = FileTransportOptions> extends Transport<Options> {
readonly path: Path;
stream?: NodeJS.WritableStream;
protected buffer: string;
protected draining: boolean;
protected lastSize: number;
protected rotating: boolean;
constructor(options: Options);
blueprint(schemas: Schemas): Blueprint<FileTransportOptions>;
/**
* Close the file stream and trigger the callback when finished.
*/
close(commit?: () => void): void;
/**
* Open the file stream for writing.
*/
open(): NodeJS.WritableStream;
/**
* Write a message to the file stream, and rotate files once written if necessary.
*/
write(message: string): void;
/**
* Check that the parent folder exists and has the correct permissions.
*/
protected checkFolderRequirements(): void;
/**
* Check if we should change and rotate files because of max size.
*/
protected checkIfNeedsRotation(): void;
/**
* Open and create a file stream for the defined path.
* Apply file size and gzip checks.
*/
protected createStream(): zlib.Gzip | fs.WriteStream;
/**
* Return the file name with extension, of the newly rotated file.
*/
protected getRotatedFileName(): string;
/**
* Count the number of files within path directory that matches the given file name.
*/
protected getNextIncrementCount(name: string): number;
/**
* Close the open stream and attempt to rotate the file.
*/
protected closeStreamAndRotateFile(): void;
/**
* Rotate the current file into a new file with an incremented name.
*/
protected rotateFile(): void;
}
//# sourceMappingURL=FileTransport.d.ts.map