Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change logging configuration #240

Closed
wants to merge 1 commit into from

Conversation

dmfigol
Copy link
Collaborator

@dmfigol dmfigol commented Aug 30, 2018

Fix #230

  • Logging is configured inside InitNornir
  • Remove logging_dictConfig, logging_loggers configuration parameters
  • Add logging_enabled configuration parameter
  • Logging is configured only if a user didn't configure nornir logger
  • Logging configuration is using only programmatic way
  • Remove all previous logging configuration

I would like to encourage you to check it out with different logging configuration in the app.
Here are a couple of examples:

logging.basicConfig(filename="app.log", format="MYAPP: [%(asctime)s] %(levelname)-8s {%(name)s:%(lineno)d} MY %(message)s", level='DEBUG')
logger = logging.getLogger(__name__)

def main() -> None:
    logger.info("before")
    logger.error("before")
    with InitNornir("config.yaml") as nr:
        logger.info("during")
        logger.error("during")
    logger.info("after")
    logger.error("after")

or

logging_dict = {
    "version": 1,
    "disable_existing_loggers": True,
    "formatters": {
        "standard": {
            "format": "APP [%(asctime)s] %(levelname)-8s {%(name)s:%(lineno)d} %(message)s"
        }
    },
    "handlers": {
        "default": {
            "level": "INFO",
            "class": "logging.handlers.RotatingFileHandler",
            "filename": "app.log",
            "maxBytes": 1024 * 1024 * 5,
            "backupCount": 5,
            "formatter": "standard",
        },
        "console": {
            "level": "INFO",
            "class": "logging.StreamHandler",
            "stream": sys.stdout,
            "formatter": "standard",
        },
    },
    "loggers": {
        "nornir": {
            "handlers": ["console", "default"],
            "level": "INFO",
            "propagate": False,
        }
        # "": {
        #     "handlers": ["console", "default"],
        #     "level": "INFO",
        #     "propagate": False
        # }
    },
    "root": {"handlers": ["console", "default"], "level": "INFO"},
}
logging.config.dictConfig(logging_dict)
logger = logging.getLogger(__name__)

@coveralls
Copy link

Pull Request Test Coverage Report for Build 926

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at ?%

Totals Coverage Status
Change from base Build 924: 0.0%
Covered Lines:
Relevant Lines: 0

💛 - Coveralls

1 similar comment
@coveralls
Copy link

Pull Request Test Coverage Report for Build 926

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at ?%

Totals Coverage Status
Change from base Build 924: 0.0%
Covered Lines:
Relevant Lines: 0

💛 - Coveralls

@coveralls
Copy link

coveralls commented Aug 30, 2018

Pull Request Test Coverage Report for Build 929

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-11.8%) to 70.0%

Totals Coverage Status
Change from base Build 924: -11.8%
Covered Lines: 1834
Relevant Lines: 2620

💛 - Coveralls

Fix nornir-automation#230

* Logging is configured inside InitNornir
* Remove logging_dictConfig, logging_loggers configuration parameters
* Add logging_enabled configuration parameter
* Logging is configured only if a user didn't configure nornir logger
* Logging configuration is using only programmatic way
* Remove all previous logging configuration
@dmfigol
Copy link
Collaborator Author

dmfigol commented Oct 17, 2018

During review of #254 I noticed that InitNornir has configure_logging argument, but we already have a schema for Logging config.
Should we get rid of this argument and have a default value in the LoggingConfig enabled=True?
@dbarrosop

@dbarrosop dbarrosop changed the base branch from 2.0 to 2.0.0-beta October 23, 2018 16:23
@dmfigol dmfigol closed this Jan 13, 2019
@dbarrosop
Copy link
Contributor

Are you still planning to work on this?

@dmfigol
Copy link
Collaborator Author

dmfigol commented Jan 20, 2019

yes, will submit new pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants