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.

Private logger property

See original GitHub issue

It would be nice if the logger property would be protected instead of private; that would allow its use in the init function.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dot-icommented, Aug 29, 2022

I just published 1.3.3 which makes the logger protected.

1reaction
marghidanucommented, Aug 12, 2022

I understand perfectly what you are saying, but I have an unwanted dependency that is not on my class; let me give you an example. I have in my operator.ts implementation of the Operator:

import Operator from '@dot-i/k8s-operator';

export default class MyOperator extends Operator {
    protected async init(): Promise<void> {
        this.logger.info("default logger"); // Property 'logger' is private and only accessible within class 'Operator'.
    }
}

In my index.ts file I have this:

import winston from 'winston';
import MyOperator from './components/operator';

const logger = winston.createLogger({
    level: 'info',
    transports: [new winston.transports.Console()],
});

const operator = new MyOperator(logger);
operator.start();

In my case, the logger is shared between other components (like a web component); I have only one definition for the logger. If the property would be protected, I wouldn’t need to export the logger from anywhere, and I wouldn’t need to override the constructor of my operator class. Also, if the attribute is already in the class, why not use it? Also, the default constructor works just fine; I don’t need to implement that either 😃

Does it make sense?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use custom log4j.properties file for private logging?
I came up with a workaround where I'm using the regular logger: private static final Logger myLog = LoggerFactory.getLogger(MyClass ...
Read more >
Logger in Java - Java Logging Example - DigitalOcean
LogManager is the class that reads the logging configuration, create and maintains the logger instances. We can use this class to set our...
Read more >
Logger (Java Platform SE 7 ) - Oracle Help Center
A Logger object is used to log messages for a specific system or application component. Loggers are normally named, using a hierarchical dot-separated ......
Read more >
Logger in Java | Java Logging Basics with Log4j and util
This article on Logger in Java is a comprehensive guide on the Java logging API used for logging solutions while creating projects.
Read more >
Java Logging Basics - The Ultimate Guide To Logging - Loggly
This lets you create and store logging.properties files with individual projects. ... private static final Logger logger = Logger.
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