Skip to main content
Module

std/log/handlers.ts>FileHandler

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
class FileHandler
extends WriterHandler
Deprecated
Deprecated

(will be removed in 0.214.0) Import from https://deno.land/std/log/file_handler.ts instead.

import { FileHandler } from "https://deno.land/std@0.212.0/log/handlers.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)