Skip to main content
Module

std/log/file_handler.ts>FileHandler

The Deno Standard Library
Go to Latest
class FileHandler
extends BaseHandler
import { FileHandler } from "https://deno.land/std@0.223.0/log/file_handler.ts";

This handler will output to a file using an optional mode (default is a, e.g. append). The file will grow indefinitely. It uses a buffer for writing to file. Logs can be manually flushed with fileHandler.flush(). Log messages with a log level greater than error are immediately flushed. Logs are also flushed on process completion.

Behavior of the log modes is as follows:

  • 'a' - Default mode. Appends new log messages to the end of an existing log file, or create a new log file if none exists.
  • 'w' - Upon creation of the handler, any existing log file will be removed and a new one created.
  • 'x' - This will create a new log file and throw an error if one already exists.

This handler requires --allow-write permission on the log file.

Constructors

new
FileHandler(levelName: LevelName, options: FileHandlerOptions)

Properties

protected
_buf: Uint8Array
protected
_encoder: TextEncoder
protected
_file: Deno.FsFile | undefined
protected
_filename: string
protected
_mode: LogMode
protected
_openOptions: Deno.OpenOptions
protected
_pointer: number

Methods

handle(logRecord: LogRecord)
log(msg: string)