Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeRuntime log format options #4193

Open
StefanTheWiz opened this issue Dec 26, 2024 · 0 comments
Open

NodeRuntime log format options #4193

StefanTheWiz opened this issue Dec 26, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@StefanTheWiz
Copy link

StefanTheWiz commented Dec 26, 2024

What is the problem this feature would solve?

Trying to set the log format for the whole CLI.

At the moment, extra code is required to make the whole CLI output json logs

#!/usr/bin/env node
import { Effect, Logger, LogLevel, Option } from 'effect';
import { NodeContext, NodeRuntime } from '@effect/platform-node';
import { Command } from '@effect/cli';

const root = Command.make('my-app').pipe(
  Command.withSubcommands([...]),
);

const cli = Command.run(root, {
  name: 'my-app',
  version: '0.0.1',
});

cli(process.argv).pipe(
  Effect.provide(NodeContext.layer),
  Effect.tapErrorCause((cause) => Effect.logFatal('Failed', cause)),
  Effect.provide(Logger.json),
  NodeRuntime.runMain({
    disablePrettyLogger: true,
    disableErrorReporting: true,
  }),
);

The example above

  • disables the default logging behaviour of the node runtime (it seems to only support pretty/default logger)
  • sets the json logger
  • logs any uncaught errors (had to disable error reporting since those would be logged using the pretty or the default logger)

What is the feature you are proposing to solve the problem?

More flexibility around setting the log format for the node runtime. Could look like this, although something pipe-able would probably look nicer

cli(process.argv).pipe(
  Effect.provide(NodeContext.layer),
  NodeRuntime.runMain({ logger: Logger.json }),
);

Another potential solution would be to add a Log Format ([--log-format]) built-in option to the CLI package.

What alternatives have you considered?

No response

@StefanTheWiz StefanTheWiz added the enhancement New feature or request label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant