How to use the @nestjs/common.Logger function in @nestjs/common

To help you get started, weโ€™ve selected a few @nestjs/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github juicycleff / ultimate-backend / apps / service-notification / src / email / queue / auth.queue.ts View on Github external
import {
  Processor,
  Process,
  OnQueueActive,
  OnQueueEvent,
  BullQueueEvents,
} from 'nest-bull';
import { Job } from 'bull';
import { Logger } from '@nestjs/common';
import { UserEntity } from '@graphqlcqrs/repository';
import { EmailService } from '../email.service';

@Processor({ name: 'auth_queue' })
export class AuthQueue {
  private readonly logger = new Logger(this.constructor.name);
  constructor(
    private readonly service: EmailService,
    // private readonly configService: ConfigService,
  ) {}

  @Process({ name: 'UserRegistered' })
  async processUserRegister(job: Job) {
    if (job.data) { return; }

    const user = job.data;
    const userEmail = user.emails.reduce(previousValue => previousValue.primary === true && previousValue);

    await this.service.sendEmail({
      to: userEmail.address,
      from: 'noreply@demo.com',
      subject: 'Thank for registering',
github nest-cloud / nestcloud / packages / config / consul-config.ts View on Github external
import * as Consul from 'consul';
import { get } from 'lodash';
import * as YAML from 'yamljs';
import { Logger } from '@nestjs/common';
import { IConfig, IKVResponse, sleep } from '@nestcloud/common';
import { Store } from './store';
import { ConfigSyncException } from './exceptions/config-sync.exception';

export class ConsulConfig implements IConfig {
    private readonly store = Store;
    private readonly consul: Consul;
    private readonly key: string;
    private readonly retryInterval: 5000;
    private watcher = null;
    private readonly logger = new Logger('ConfigModule');

    constructor(consul: Consul, key: string) {
        this.consul = consul;
        this.key = key;
    }

    async init() {
        while (true) {
            try {
                const result = await this.consul.kv.get(this.key);
                this.store.data = result ? YAML.parse(result.Value) : {};
                this.createWatcher();
                this.logger.log('ConfigModule initialized');
                break;
            } catch (e) {
                this.logger.error('Unable to initial ConfigModule, retrying...', e);
github golevelup / nestjs / packages / rabbitmq / src / rabbitmq.module.ts View on Github external
useFactory: async (): Promise => {
            const connection = new AmqpConnection(config);
            await connection.init();
            const logger = new Logger(RabbitMQModule.name);
            logger.log('Successfully connected to RabbitMQ');
            return connection;
          }
        }
github notadd / next / src / injection / loaders / injection.loader.ts View on Github external
import * as writeJsonToFile from "write-json-file";
import { dirname } from "path";
import { existsSync } from "fs";
import { Logger } from "@nestjs/common";
import { Json } from "@notadd/core/loaders";

import { importInjectionsFromDirectories } from "../utilities";
import { Injection as InjectionInterface } from "../interfaces";

export class InjectionLoader {
    protected cacheForInjections: Array = [];

    protected filePathForCache = "";

    protected logger = new Logger("Injection");

    protected patterns = [
        "**/*.injection.js",
        "**/*.module.js",
    ];

    public get injections(): Array {
        if (!this.cacheForInjections.length) {
            this.loadInjectionsFromCache();
        }

        return this.cacheForInjections;
    }

    constructor() {
        this.loadInjectionsFromCache();
github nestjs / nest / bundle / core / exceptions / exceptions-handler.js View on Github external
invokeCustomFilters(exception, response) {
        if (shared_utils_1.isEmpty(this.filters))
            return false;
        const filter = this.filters.find(({ exceptionMetatypes, func }) => {
            const hasMetatype = !exceptionMetatypes.length ||
                !!exceptionMetatypes.find(ExceptionMetatype => exception instanceof ExceptionMetatype);
            return hasMetatype;
        });
        filter && filter.func(exception, response);
        return !!filter;
    }
    isExceptionObject(err) {
        return shared_utils_1.isObject(err) && !!err.message;
    }
}
ExceptionsHandler.logger = new common_1.Logger(ExceptionsHandler.name);
exports.ExceptionsHandler = ExceptionsHandler;
github chanlito / nestjs-extensions / src / redis / redis.providers.ts View on Github external
import { Logger } from '@nestjs/common';
import * as optional from 'optional';

import { RedisClientToken } from './redis.constants';

const redis = optional('redis');

const logger = new Logger('RedisModule');

export function createRedisProviders(config: CreateRedisProvidersConfig) {
  const redisProvider = {
    provide: RedisClientToken,
    useFactory: () => {
      const redisClient = redis.createClient({
        host: config.host,
        port: config.port,
        auth_pass: config.auth_pass
      });
      redisClient.on('connect', () => logger.log('Connecting'));
      redisClient.on('ready', () => logger.log('Connected'));
      redisClient.on('reconnecting', () => logger.log('Reconnecting'));
      redisClient.on('end', () => logger.warn('Ended'));
      redisClient.on('error', e => logger.error(e.message, e.stack));
      return redisClient;
github scalio / bazel-nx-example / apps / api / src / cats / cats.resolvers.ts View on Github external
import { Logger, ParseIntPipe, UseGuards } from '@nestjs/common';
import { Args, Mutation, Query, Resolver, Subscription } from '@nestjs/graphql';
import { PubSub } from 'graphql-subscriptions';
import { GqlAuthGuard } from '../auth/graphql-auth.guard';
import { CatEntity } from './cat.entity';
import { CatsService } from './cats.service';
import { CreateCatDto } from './dto/create-cat.dto';

const pubSub = new PubSub();

@Resolver('Cat')
export class CatsResolvers {
  private logger = new Logger(CatsResolvers.name);
  constructor(private readonly catsService: CatsService) {}

  @Query()
  @UseGuards(GqlAuthGuard)
  async getCats() {
    this.logger.log('getCats called');
    return await this.catsService.findAll();
  }

  @Query('cat')
  @UseGuards(GqlAuthGuard)
  async findOneById(
    @Args('id', ParseIntPipe)
    id: number,
  ): Promise {
    this.logger.log('getCat called');
github chanlito / simple-todos / src / lib / redis / redis.providers.ts View on Github external
import { Logger } from '@nestjs/common';
import * as Promise from 'bluebird';
import * as redis from 'redis';

import { RedisClientToken } from './redis.constants';

Promise.promisifyAll(redis.RedisClient.prototype);
Promise.promisifyAll(redis.Multi.prototype);

const logger = new Logger('RedisModule');

export function createRedisProviders(options: CreateRedisProvidersOptions) {
  const redisProvider = {
    provide: RedisClientToken,
    useFactory: () => {
      const redisClient = redis.createClient({
        host: options.host,
        port: options.port,
        auth_pass: options.auth_pass
      });
      redisClient.on('connect', () => logger.log('Connecting'));
      redisClient.on('ready', () => logger.log('Connected'));
      redisClient.on('reconnecting', () => logger.log('Reconnecting'));
      redisClient.on('end', () => logger.warn('Ended'));
      redisClient.on('error', e => logger.error(e.message, e.stack));
      return redisClient;