Advanced Topics Configuration

Configuration

Prerequisites: Installation

Configure ng-forge dynamic forms behavior at the application level using provider features.

Overview

ng-forge uses a feature-based configuration pattern similar to Angular's provideRouter(). Features are optional add-ons that modify the library's behavior globally.

import { provideDynamicForm, withLogger, LogLevel } from '@ng-forge/dynamic-forms';
import { withMaterialFields } from '@ng-forge/dynamic-forms-material';

export const appConfig: ApplicationConfig = {
  providers: [
    provideDynamicForm(
      ...withMaterialFields(),
      withLogger({ level: LogLevel.Debug }), // Provider feature
    ),
  ],
};

Two Levels of Configuration:

LevelScopeWhereExamples
ProviderApp-wideprovideDynamicForm()withLogger(), future features
FormPer-formFormConfigoptions, customFnConfig, defaultValidationMessages

This page covers provider-level features. For form-level configuration, see Submission, Custom Validators, and i18n.

Logging

Control how ng-forge logs diagnostic information using withLogger().

Basic Usage

import { provideDynamicForm, withLogger, LogLevel } from '@ng-forge/dynamic-forms';

provideDynamicForm(...withMaterialFields(), withLogger({ level: LogLevel.Debug }));

Log Levels

LevelValueLogs
LogLevel.Off0Nothing
LogLevel.Error1Errors only
LogLevel.Warn2Errors + Warnings
LogLevel.Info3Errors + Warnings + Info
LogLevel.Debug4Everything

Each level includes all messages from more severe levels.

Default Behavior

Without withLogger(), ng-forge uses smart defaults:

  • Development mode (isDevMode() === true): LogLevel.Warn
  • Production mode: Logging disabled (silent)

Common Configurations

Verbose debugging during development:

Disable all logging:

Errors only in production:

Custom Logger

Integrate with external logging services (Sentry, DataDog, LogRocket, etc.) by providing a custom logger implementation:

import { DynamicFormLogger } from '@ng-forge/dynamic-forms';

const sentryLogger: DynamicFormLogger = {
  debug: (message, ...args) => {
    // Optionally send to Sentry breadcrumbs
  },
  info: (message, ...args) => {
    Sentry.addBreadcrumb({ message, level: 'info', data: args[0] });
  },
  warn: (message, ...args) => {
    Sentry.addBreadcrumb({ message, level: 'warning', data: args[0] });
  },
  error: (message, ...args) => {
    Sentry.captureMessage(message, { level: 'error', extra: { args } });
  },
};

provideDynamicForm(...withMaterialFields(), withLogger({ logger: sentryLogger }));

When providing a custom logger, the level option is ignored—your implementation controls filtering.

DynamicFormLogger Interface

interface DynamicFormLogger {
  debug(message: string, ...args: unknown[]): void;
  info(message: string, ...args: unknown[]): void;
  warn(message: string, ...args: unknown[]): void;
  error(message: string, ...args: unknown[]): void;
}

Injecting the Logger

For advanced use cases, inject the logger directly:

import { inject } from '@angular/core';
import { DYNAMIC_FORM_LOGGER } from '@ng-forge/dynamic-forms';

@Component({...})
export class MyComponent {
  private logger = inject(DYNAMIC_FORM_LOGGER);

  someMethod() {
    this.logger.debug('Custom debug message', { data: 'value' });
  }
}

What Gets Logged

ng-forge logs diagnostic information to help with debugging:

LevelExamples
ErrorMissing field components, schema errors, validator registration failures
WarnMissing validation messages, field type overwrites, deprecated usage
InfoForm lifecycle events (future)
DebugExpression evaluation, validator execution, field rendering (future)

API Reference

withLogger()

function withLogger(options?: LoggerFeatureOptions): DynamicFormFeature<'logger'>;

Options:

PropertyTypeDescription
levelLogLevelLog level threshold. Messages below this level are filtered.
loggerDynamicFormLoggerCustom logger implementation. If provided, level is ignored.

LogLevel

enum LogLevel {
  Off = 0,
  Error = 1,
  Warn = 2,
  Info = 3,
  Debug = 4,
}

DynamicFormLogger

interface DynamicFormLogger {
  debug(message: string, ...args: unknown[]): void;
  info(message: string, ...args: unknown[]): void;
  warn(message: string, ...args: unknown[]): void;
  error(message: string, ...args: unknown[]): void;
}

DYNAMIC_FORM_LOGGER

const DYNAMIC_FORM_LOGGER: InjectionToken<DynamicFormLogger>;

Injection token for accessing the configured logger directly.

Next Steps