Skip to main content
Deno 2 is finally here 🎉️
Learn more
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
import { FileHandler } from "https://deno.land/std@0.201.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: BufWriterSync
protected
_encoder: TextEncoder
protected
_file: Deno.FsFile | undefined
protected
_filename: string
protected
_mode: LogMode
protected
_openOptions: Deno.OpenOptions

Methods

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