question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to set the context?

I am using the logger in a library which outputs:

2021-02-05T12:58:01.192Z DEBUG [my-module-my-module.js:20803] Hello world

But my-module is actually the client that uses the library not the module from the library and not the service I used the logger within.

I would like what is set what stands in the brackets. E.g. in Nest.js you would do it like this:

import { Logger } from 'ngx-logger';

@Injectable()
class MyService {
  private logger = new Logger(MyService.name);
  
  doSomething() {
    this.logger.log('Doing something...');
  }
}

Or alternatively it could be done like this:

import { Logger } from 'ngx-logger';

@Injectable()
class MyService {
  constructor(private logger: Logger) {
     logger.setContext(MyService.name);
  }
  
  doSomething() {
    this.logger.log('Doing something...');
  }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
bmtheocommented, Nov 7, 2021

Hi @MickL, I just published v5 that allows you to customise any behavior of the logger and that would be enough for your feature The doc is here : https://github.com/dbfannin/ngx-logger/blob/master/docs/customising.md In your case you would need to customise the metadata.service.ts

Still your feature request is probably something I’ll look into

Read more comments on GitHub >

github_iconTop Results From Across the Web

kubectl config set-context - Kubernetes
Sets a context entry in kubeconfig Specifying a name that already exists will merge new fields on top of existing values for those...
Read more >
Kubectl Config Set-Context | Tutorial and Best Practices
Kubernetes comes with many tools to help you manage your clusters, including kubectl set-context. In this guide, you'll learn how to use this...
Read more >
setcontext(2): get/set user context - Linux man page - Die.net
The function setcontext() restores the user context pointed at by ucp. A successful call does not return. The context should have been obtained...
Read more >
kubectl Cheat Sheet | Kubernetes
Kubectl context and configuration. Set which Kubernetes cluster kubectl communicates with and modifies configuration information.
Read more >
Set context | Microsoft Learn
Sets the context for shadow copy creation. If used without parameters, set context displays help at the command prompt.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found