Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Need Refactoring #11

@mpyw

Description

@mpyw

Current Implementation

  1. Create an instance with mandatory log configuration: accessKeyId, secretAccessKey, region and logGroupName.
  2. Configure some options: setLevels() and setInterval().
  3. install() with more options: logStreamNameResolver and messageFormatter.
  4. Switch some options on demand after installation: enable(), disable(), mute() and unmute().

It's too stateful and has so complex interface.

Future Plan

import { CloudWatchLogsClient } from '@aws-sdk/client-cloudwatch-logs';
import { LoggerFactory, Channel } from 'cloudwatch-front-logger';

const client = new CloudwatchLogsClient({
  credentials: {
    accessKeyId: ...,
    secretAccessKey: ...,
  }
  region: ...,
});
const factory = new LoggerFactory({
  client,
  logGroupName: ...,
  logStreamNameResolver: ...,
  messageFormatter: ...,
  interval: ...,
  muted: ...,
});
factory.addChannel(new Channel('error'));
factory.addChannel(new Channel('warn', {
  // All parameters can be overridden here
  client,
  logGroupName: ...,
  logStreamNameResolver: ...,
  messageFormatter: ...,
  interval: ...,
  muted: ...,
)); 

const logger = factory.createLogger();

const channels = logger.channels();  // Return channel collection
channels.mute(); // Mute all channels
channels.get('error').mute(); // Mute all error channels
channels.get('error')[0].mute(); // Mute only single error channel

Or you can create using default channels.

const logger = new LoggerFactory({
  client,
  logGroupName: ...,
  logStreamNameResolver: ...,
  messageFormatter: ...,
  interval: ...,
  muted: ...,
}).setDefaultChannels();

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions