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

Fix/enhance configuration #630

Merged
merged 5 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 44 additions & 11 deletions ocrd_utils/ocrd_logging.conf
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
# This is a template configuration file which allows customizing
# format and destination of log messages with OCR-D.
# It is meant as an example, and should be customized.
# This is a template configuration file to demonstrate
# formats and destinations of log messages with OCR-D.
# It's meant as an example, and should be customized.
# To get into effect, you must put a copy (under the same name)
# into your CWD, HOME or /etc. These directories are searched
# in said order, and the first find wins. When no config file
# is found, the default logging configuration applies (cf. ocrd_logging.py).
#
# mandatory loggers section
# configure loggers with correspnding keys "root", ""
# configure loggers with corresponding keys "root",""
# each logger requires a corresponding configuration section below
#
[loggers]
#keys=root,ocrd_workspace
keys=root
keys=root,ocrd_tensorflow,ocrd_shapely_geos,ocrd_PIL

#
# mandatory handlers section
# handle output for each logging "channel"
# handle output for logging "channel"
# i.e. console, file, smtp, syslog, http, ...
# each handler requires a corresponding configuration section below
# each handler requires a corresponding handler configuration section below
#
[handlers]
keys=consoleHandler,fileHandler

#
# optional custom formatters section
# format message fields, to be used differently by logging handlers
# optional formatters section
# format message records, to be used differently by logging handlers
# each formatter requires a corresponding formatter section below
#
[formatters]
keys=defaultFormatter,detailedFormatter

#
# default logger "root" using consoleHandler
# default logger "root" configured to use only consoleHandler
#
[logger_root]
level=INFO
handlers=consoleHandler


#
# additional logger configurations can be added
# as separate configuration sections like below
Expand All @@ -47,11 +48,43 @@ handlers=consoleHandler
# ocrd modul
# see in the modul-of-interrest (moi)
#
# example configuration entry
#
# logger ocrd.workspace
#
#[logger_ocrd_workspace]
#level=DEBUG
#handlers=fileHandler
#qualname=ocrd.workspace


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PIL restriction from the builtin config omitted because it is INFO anyway, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, since it is the default level. But If you mind, I can add this as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall ocrd be integrated, too?
Be aware, this might have side-effects, because it is the far most top ocrd logging channel.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall ocrd be integrated, too?
Be aware, this might have side-effects, because it is the far most top ocrd logging channel.

Since we don't specify logging behavior for ocrd* in the builtin config, we should not in the config file.

I also would leave the [logger_ocrd_workspace] commented out as an example - setting this to DEBUG by default will be very verbose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, I adopt your suggestions asap

#
# logger tensorflow
#
[logger_ocrd_tensorflow]
level=ERROR
handlers=consoleHandler
qualname=tensorflow


#
# logger shapely.geos
#
[logger_ocrd_shapely_geos]
level=ERROR
handlers=consoleHandler
qualname=shapely.geos


#
# logger PIL
#
[logger_ocrd_PIL]
level=INFO
handlers=consoleHandler
qualname=PIL


#
# handle stdout output
#
Expand Down
40 changes: 39 additions & 1 deletion tests/test_logging_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _fixture_loggin_conf(tmpdir):
return str(tmpdir)


def test_cli_log_level_set(logging_conf, capsys):
def test_configured_dateformat(logging_conf, capsys):
"""Ensure example ocrd_logging.conf is valid and produces desired record format"""

# arrange
Expand All @@ -44,3 +44,41 @@ def test_cli_log_level_set(logging_conf, capsys):
assert not re.match(must_not_match, log_info_output)
match_pattern = r"^\d{2}:\d{2}:\d{2}.*"
assert re.match(match_pattern, log_info_output)


def test_configured_tensorflow_logger_present(logging_conf, capsys):
"""Ensure example ocrd_logging.conf is valid and contains logger tensorflow"""

# arrange
os.chdir(logging_conf)
initLogging()
logger_under_test = getLogger('tensorflow')

# act info
logger_under_test.info("tensorflow logger initialized")
log_info_output = capsys.readouterr().out
assert not log_info_output

# act error
logger_under_test.error("tensorflow has error")
log_error_output = capsys.readouterr().out
assert log_error_output


def test_configured_shapely_logger_present(logging_conf, capsys):
"""Ensure example ocrd_logging.conf is valid and contains logger shapely.geos"""

# arrange
os.chdir(logging_conf)
initLogging()
logger_under_test = getLogger('shapely.geos')

# act info
logger_under_test.info("shapely.geos logger initialized")
log_info_output = capsys.readouterr().out
assert not log_info_output

# act error
logger_under_test.error("shapely alert")
log_error_output = capsys.readouterr().out
assert log_error_output