Skip to content

Log Format Standards — Defining Consistent Log Schemas Across Teams

DodaTech Updated 2026-06-28 1 min read

In this tutorial, you'll learn about Log Format Standards. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

Log format standards ensure consistent, machine-parseable log output across all services and teams in an organization.

// Standard log schema definition
const logSchemaDefinition = {
  $schema: 'https://json-schema.org/draft/2020-12/schema',
  type: 'object',
  required: ['timestamp', 'level', 'message', 'service'],
  properties: {
    timestamp: { type: 'string', format: 'date-time' },
    level: { type: 'string', enum: ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'] },
    message: { type: 'string', maxLength: 1000 },
    service: {
      type: 'object',
      properties: {
        name: { type: 'string' },
        version: { type: 'string' },
        environment: { type: 'string', enum: ['dev', 'staging', 'prod'] },
        host: { type: 'string' },
        instance: { type: 'string' }
      }
    },
    correlation: {
      type: 'object',
      properties: {
        id: { type: 'string', format: 'uuid' },
        traceId: { type: 'string' },
        spanId: { type: 'string' }
      }
    },
    user: {
      type: 'object',
      properties: {
        id: { type: 'string' },
        type: { type: 'string', enum: ['user', 'service', 'anonymous'] }
      }
    },
    request: {
      type: 'object',
      properties: {
        method: { type: 'string' },
        path: { type: 'string' },
        statusCode: { type: 'integer', minimum: 100, maximum: 599 },
        duration: { type: 'integer', minimum: 0 }
      }
    },
    error: {
      type: 'object',
      properties: {
        code: { type: 'string' },
        message: { type: 'string' },
        stack: { type: 'string' },
        fingerprint: { type: 'string' }
      }
    },
    context: { type: 'object' }
  }
};

// Schema validation middleware
function validateLogEntry(entry) {
  const ajv = new Ajv();
  const validate = ajv.compile(logSchemaDefinition);
  const valid = validate(entry);

  if (!valid) {
    console.error('Log entry failed schema validation:', validate.errors);
    return false;
  }
  return true;
}

Standardized log formats ensure that all tools in the Observability pipeline can parse and Process log data reliably.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro