or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

caching-performance.mdcontext-types.mderror-handling.mdindex.mdlogging-system.mdplugin-system.mdrequest-processing.mdresult-processing.mdschema-management.mdserver-configuration.mdsubscription-system.md
tile.json

logging-system.mddocs/

Logging System

Comprehensive logging system with configurable log levels, structured output, and integration with GraphQL Yoga server lifecycle. Provides both default console logging and custom logger support.

Capabilities

Logger Creation

Creates logger instances with configurable output and log level filtering.

/**
 * Creates a logger instance with specified configuration
 * @param logLevel - Minimum log level to output
 * @param logger - Optional custom logger implementation
 * @returns Configured YogaLogger instance
 */
function createLogger(logLevel?: LogLevel, logger?: YogaLogger): YogaLogger;

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

interface YogaLogger {
  /** Log debug messages (lowest priority) */
  debug(...args: any[]): void;
  /** Log informational messages */
  info(...args: any[]): void;
  /** Log warning messages */
  warn(...args: any[]): void;
  /** Log error messages (highest priority) */
  error(...args: any[]): void;
}

Usage Examples:

import { createYoga, createLogger, LogLevel } from 'graphql-yoga';

// Create logger with specific log level
const logger = createLogger(LogLevel.Info);

const yoga = createYoga({
  schema,
  logging: logger, // Use custom logger
});

// Or use log level directly
const yoga2 = createYoga({
  schema,
  logging: LogLevel.Warn, // Only warnings and errors
});

// Disable logging completely
const yoga3 = createYoga({
  schema,
  logging: false,
});

Custom Logger Implementation

Interface for implementing custom loggers with external logging systems.

/**
 * Custom logger interface for integration with external logging systems
 */
interface CustomLogger {
  debug(...args: any[]): void;
  info(...args: any[]): void;
  warn(...args: any[]): void;
  error(...args: any[]): void;
}

Usage Example:

import { createYoga } from 'graphql-yoga';
import winston from 'winston';

// Winston logger integration
const winstonLogger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    new winston.transports.File({ filename: 'error.log', level: 'error' }),
    new winston.transports.File({ filename: 'combined.log' }),
  ],
});

const customLogger = {
  debug: (...args) => winstonLogger.debug(args.join(' ')),
  info: (...args) => winstonLogger.info(args.join(' ')),
  warn: (...args) => winstonLogger.warn(args.join(' ')),
  error: (...args) => winstonLogger.error(args.join(' ')),
};

const yoga = createYoga({
  schema,
  logging: customLogger,
});

Server Logger Access

Access to the server's logger instance for custom plugin and middleware logging.

/**
 * Server logger accessible from YogaServer instance
 */
interface YogaServerLogger {
  logger: YogaLogger;
}

Usage Example:

import { createYoga, Plugin } from 'graphql-yoga';

const loggingPlugin: Plugin = {
  onRequestParse({ context, logger }) {
    logger.info('Parsing GraphQL request', {
      method: context.request.method,
      url: context.request.url,
    });
  },
  
  onExecutionResult({ result, logger }) {
    if (result.errors) {
      logger.error('GraphQL execution errors', result.errors);
    } else {
      logger.debug('GraphQL execution successful');
    }
  },
};

const yoga = createYoga({
  schema,
  plugins: [loggingPlugin],
});

// Access server logger directly
yoga.logger.info('Server initialized');

Types

type LoggerConfiguration = 
  | boolean
  | YogaLogger
  | LogLevel
  | undefined;

interface LogContext {
  request?: Request;
  query?: string;
  variables?: Record<string, any>;
  operationName?: string;
}