Unverified Commit 1e4e48f6 authored by Hong Minhee's avatar Hong Minhee
Browse files

`FEDIFY_LOG_FILE` variable

parent 8b9ff610
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -8,6 +8,10 @@ Version 1.0.16

To be released.

 -  The `fedify` command became aware of `FEDIFY_LOG_FILE` environment variable
    to log messages to a file.  If the variable is set, the command logs
    messages to the file specified by the variable.


Version 1.0.15
--------------
+2 −2
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ import { basename, dirname, join, normalize } from "@std/path";
import { format, greaterThan, parse } from "@std/semver";
import metadata from "./deno.json" with { type: "json" };

const logger = getLogger(["fedify", "cli", "init"]);

type Runtime = "deno" | "bun" | "node";

interface RuntimeDescription {
@@ -542,8 +544,6 @@ const messageQueues: Record<MessageQueue, MessageQueueDescription> = {
  },
} as const;

const logger = getLogger(["fedify", "cli", "init"]);

export const command = new Command()
  .type(
    "runtime",
+14 −3
Original line number Diff line number Diff line
import {
  configure,
  getConsoleSink,
  getFileSink,
  type LogRecord,
  type Sink,
} from "@logtape/logtape";
import { dirname } from "@std/path";

export interface RecordingSink extends Sink {
  startRecording(): void;
@@ -30,19 +32,28 @@ export function getRecordingSink(): RecordingSink {

export const recordingSink = getRecordingSink();

export const logFile = Deno.env.get("FEDIFY_LOG_FILE");
if (logFile != null) {
  await Deno.mkdir(dirname(logFile), { recursive: true });
}

await configure({
  sinks: { console: getConsoleSink(), recording: recordingSink },
  sinks: {
    console: getConsoleSink(),
    recording: recordingSink,
    file: logFile == null ? () => undefined : getFileSink(logFile),
  },
  filters: {},
  loggers: [
    {
      category: "fedify",
      level: "debug",
      sinks: ["recording"],
      sinks: ["recording", "file"],
    },
    {
      category: ["logtape", "meta"],
      level: "warning",
      sinks: ["console"],
      sinks: ["console", "file"],
    },
  ],
  reset: true,
+17 −6
Original line number Diff line number Diff line
import { Command, CompletionsCommand, HelpCommand } from "@cliffy/command";
import { configure, getConsoleSink } from "@logtape/logtape";
import { configure, getConsoleSink, getFileSink } from "@logtape/logtape";
import { DEFAULT_CACHE_DIR, setCacheDir } from "./cache.ts";
import metadata from "./deno.json" with { type: "json" };
import { command as inbox } from "./inbox.tsx";
import { command as init } from "./init.ts";
import { recordingSink } from "./log.ts";
import { logFile, recordingSink } from "./log.ts";
import { command as lookup } from "./lookup.ts";
import { command as tunnel } from "./tunnel.ts";

const command = new Command()
  .name("fedify")
  .version(metadata.version)
  .globalEnv(
    "FEDIFY_LOG_FILE=<file:file>",
    "An optional file to write logs to.  " +
      "Regardless of -d/--debug option, " +
      "all levels of logs are written to this file.  " +
      "Note that this does not mute console logs.",
  )
  .globalOption("-d, --debug", "Enable debug mode.", {
    async action() {
      await configure({
        sinks: { console: getConsoleSink(), recording: recordingSink },
        sinks: {
          console: getConsoleSink(),
          recording: recordingSink,
          file: logFile == null ? () => undefined : getFileSink(logFile),
        },
        filters: {},
        loggers: [
          {
            category: "fedify",
            level: "debug",
            sinks: ["console", "recording"],
            sinks: ["console", "recording", "file"],
          },
          {
            category: "localtunnel",
            level: "debug",
            sinks: ["console"],
            sinks: ["console", "file"],
          },
          {
            category: ["logtape", "meta"],
            level: "warning",
            sinks: ["console"],
            sinks: ["console", "file"],
          },
        ],
        reset: true,