title: Nestjs: Retrieve the request / context from a Decorator
body: <p>I am working on a NestJS project,
  I'm trying to get the executionContext accessible in a logger to filter the logs by request.</p>
  <p>I have one logger instance per injectable, and I would like to keep this behavior (So the scope of the injectable is default).</p>
  <p>To do this, I'm trying to create a decorator that gets the context from the request and passes it to the child services (as in the logger), to finally get the context in the logger...</p>
  <p>I'm not sure to be clear... For now, here is my code:</p>
  <pre><code>export const Loggable = () =&gt; (constructor: Function) =&gt; {
    for (const propertyName of Reflect.ownKeys(constructor.prototype)) {
      let descriptor = Reflect.getOwnPropertyDescriptor(constructor.prototype, propertyName);
      const isMethod = descriptor.value instanceof Function;
      if (!isMethod)
        continue;
  
      const originalMethod = descriptor.value;
      const routeArgsMetada = Reflect.getMetadata(ROUTE_ARGS_METADATA, constructor, propertyName as string);
  
      descriptor.value = function (...args: any[]) {
        const result = originalMethod.apply(this, args);
          //TODO : retrieve the request / contextExecution
          //TODO : pass the request / contextExecution to children functions...
        return result;
      };
      Reflect.defineProperty(constructor.prototype, propertyName, descriptor);
  
      Reflect.defineMetadata(ROUTE_ARGS_METADATA, routeArgsMetada, constructor, propertyName as string);
    }
  };
  </code></pre>
  <p>This @Loggable() decorator would be attached to all injectable classes that need to log or throw execution context</p>
  <p>Is that possible ? If not why ?</p>
  <p>PS: I'm wondering, how could the @Guard annotation get the context? and how could the @Req annotations get the request?</p>
  <p><a href="https://github.com/nestjs/nest/tree/master/packages/common/decorators/http" rel="nofollow noreferrer">https://github.com/nestjs/nest/tree/master/packages/common/decorators/http</a></p>
  <p><a href="https://github.com/nestjs/nest/blob/master/packages/common/decorators/core/use-guards.decorator.ts" rel="nofollow noreferrer">https://github.com/nestjs/nest/blob/master/packages/common/decorators/core/use-guards.decorator.ts</a></p>