Skip to content

Commit

Permalink
Set logger name, and include in examples and docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy-Grigg committed Jan 11, 2022
1 parent 8fac647 commit 6a7c57b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
19 changes: 16 additions & 3 deletions examples/0_Getting_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,23 @@

# ## Logging

# All query results also contain a list of messages that were returned by the server when running the query. These are
# sorted in order of decreasing severity. The same messages are logged in the Service Layer log file. These messages are
# also visible as logs if the standard Python `logging` module is used.
# All query results contain a list of messages that were returned by the server when running the query. These are
# sorted in order of decreasing severity. The same messages are also available in the Service Layer log file.

# + tags=[]
result.messages
# -

# These messages are also available via the standard `logging` module using the 'ansys.grantami.bomanalytics' logger.
# Alternatively, omit the logger name to get the root logger, which will include messages logged by all packages.
# The code below creates a log handler that outputs all bomanalytics messages with severity INFO and above to either the
# terminal or the notebook.

# + tags=[]
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("ansys.grantami.bomanalytics")

result = cxn.run(query)
# -
2 changes: 1 addition & 1 deletion src/ansys/grantami/bomanalytics/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
BomComplianceQueryResult,
)

logger = logging.getLogger(__name__)
logger = logging.getLogger("ansys.grantami.bomanalytics")


class Connection(common.ApiClientFactory):
Expand Down
7 changes: 4 additions & 3 deletions src/ansys/grantami/bomanalytics/_query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ def messages(self) -> List[LogMessage]:
"""[TECHDOCS] Messages generated by Granta MI when running the query. The presence of one or more messages means
something unexpected happened when running the query, but the query could still be completed.
Messages are sorted in order of decreasing severity. Messages are also logged in the Service Layer log on the
Granta MI server, and are logged using the Python `logging` module. By default, messages with a severity of
"warning" or higher are printed on stderr.
Messages are sorted in order of decreasing severity. Messages are also available in the Service Layer log file.
Messages are also logged using the Python `logging` module to the "ansys.grantami.bomanalytics" logger. By
default, messages with a severity of "warning" or higher are printed on stderr.
Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/grantami/bomanalytics/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
Query_Builder = TypeVar("Query_Builder", covariant=True, bound=Union["_BaseQueryBuilder", "_ApiMixin"])
Query_Result = TypeVar("Query_Result", covariant=True, bound=Union[ComplianceBaseClass, ImpactedSubstancesBaseClass])

logger = logging.getLogger(__name__)
logger = logging.getLogger("ansys.grantami.bomanalytics")
EXCEPTION_MAP = {
"critical": logger.critical,
"error": logger.error,
Expand Down

0 comments on commit 6a7c57b

Please sign in to comment.