You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix broken https link and wrap at 80 columns (#28)
* Fix broken https link and wrap at 80 columns
* Apply suggestions from code review
Co-authored-by: Maxime Rey <[email protected]>
Co-authored-by: Alex Kaszynski <[email protected]>
Co-authored-by: Maxime Rey <[email protected]>
This enables logging to that file in addition of the standard output.
220
-
If you wish to change the characteristics of this global logger from
221
-
the beginning of the execution, you must edit the file ``__init__`` in
222
-
the directory of your library.
218
+
This enables logging to that file in addition of the standard output. If you
219
+
wish to change the characteristics of this global logger from the beginning of
220
+
the execution, you must edit the file ``__init__`` in the directory of your
221
+
library.
223
222
224
-
To log using this logger, simply call the desired method as a normal
225
-
logger.
223
+
To log using this logger, simply call the desired method as a normal logger.
226
224
227
225
.. code:: python
228
226
@@ -237,13 +235,13 @@ logger.
237
235
238
236
Instance logger
239
237
~~~~~~~~~~~~~~~
240
-
Every time that the class ``_MapdlCore`` is instantiated, a logger is
241
-
created. This logger is recommended when using the ``pool`` library
242
-
or when using multiple instances of ``Mapdl``. The main feature of
243
-
this logger is that it tracks each instance and it includes its name
244
-
when logging. The name of the instances are unique. For example in
245
-
case of using the ``gRPC`` ``Mapdl`` version, its name includes the IP
246
-
and port of the correspondent instance, making unique its logger.
238
+
Every time that the class ``_MapdlCore`` is instantiated, a logger is created.
239
+
This logger is recommended when using the ``pool`` library or when using
240
+
multiple instances of ``Mapdl``. The main feature of this logger is that it
241
+
tracks each instance and it includes its name when logging. The name of the
242
+
instances are unique. For example in case of using the ``gRPC`` ``Mapdl``
243
+
version, its name includes the IP and port of the correspondent instance, making
244
+
unique its logger.
247
245
248
246
249
247
The instance loggers can be accessed in two places:
@@ -252,11 +250,11 @@ The instance loggers can be accessed in two places:
252
250
* ``LOG._instances``. This field is a ``dict`` where the key is the
253
251
name of the created logger.
254
252
255
-
These instance loggers inherit from the ``pymapdl_global`` output
256
-
handlers and logging level unless otherwise specified. The way this
257
-
logger works is very similar to the global logger. You can add a file
258
-
handler if you wish using the method ``log_to_file`` or change the log
259
-
level using :meth:`logging.Logger.setLevel`.
253
+
These instance loggers inherit from the ``pymapdl_global`` output handlers and
254
+
logging level unless otherwise specified. The way this logger works is very
255
+
similar to the global logger. You can add a file handler if you wish using the
256
+
method ``log_to_file`` or change the log level using
257
+
:meth:`logging.Logger.setLevel`.
260
258
261
259
You can use this logger like this:
262
260
@@ -274,17 +272,22 @@ You can use this logger like this:
274
272
275
273
Wrapping Other Loggers
276
274
~~~~~~~~~~~~~~~~~~~~~~
277
-
A product, due to its architecture can be made of several loggers.
278
-
The ``logging`` library features allows to work with a finite number of loggers.
279
-
The factory function logging.getLogger() helps to access each logger by its name.
280
-
In addition of this naming-mappings, a hierachy can be established to structure the loggers
281
-
parenting and their connection.
282
-
283
-
284
-
For instance, if an ANSYS product is using a pre-exsiting custom logger encapsulated inside the product itself, the <PyProject> will benefit from exposing it through the standard python tools.
285
-
It is recommended to use the standard library as much as possible. It will facilitate every contribution -both external and internal- to the <PyProject> by exposing common tools that are widely spread.
286
-
Each developer will be able to operate quickly and autonomously.
287
-
The project will take advantage of the entire set of features exposed in the standard logger and all the upcoming improvements.
275
+
A product, due to its architecture can be made of several loggers. The
276
+
``logging`` library features allows to work with a finite number of loggers. The
277
+
factory function logging.getLogger() helps to access each logger by its name. In
278
+
addition of this naming-mappings, a hierachy can be established to structure the
279
+
loggers parenting and their connection.
280
+
281
+
282
+
For instance, if an ANSYS product is using a pre-exsiting custom logger
283
+
encapsulated inside the product itself, the <PyProject> will benefit from
284
+
exposing it through the standard python tools. It is recommended to use the
285
+
standard library as much as possible. It will facilitate every contribution
286
+
-both external and internal- to the <PyProject> by exposing common tools that
287
+
are widely spread. Each developer will be able to operate quickly and
288
+
autonomously.
289
+
The project will take advantage of the entire set of features exposed in the
290
+
standard logger and all the upcoming improvements.
288
291
289
292
Create a custom log handler to catch each product message and redirect them on another logger:
@@ -298,9 +301,12 @@ AEDT product has its own internal logger called the message manager made of 3 ma
298
301
* *Project*: related to the project
299
302
* *Design*: related to the design (most specific destination of each 3 loggers.)
300
303
301
-
The message manager is not using the standard python logging module and this might be a problem later when exporting messages and data from each ANSYS product to a common tool.
302
-
In most of the cases, it is easier to work with the standard python module to extract data.
303
-
In order to overcome this limitation, the existing message manager is wrapped into a logger based on the standard python `logging <https://docs.python.org/3/library/logging.html>`__ module.
304
+
The message manager is not using the standard python logging module and this
305
+
might be a problem later when exporting messages and data from each ANSYS
306
+
product to a common tool. In most of the cases, it is easier to work with the
307
+
standard python module to extract data.
308
+
In order to overcome this limitation, the existing message manager is wrapped
309
+
into a logger based on the standard python :mod:`logging` module.
304
310
305
311
306
312
.. figure:: images/log_flow.png
@@ -311,8 +317,10 @@ In order to overcome this limitation, the existing message manager is wrapped in
311
317
**Figure 1: Loggers message passing flow.**
312
318
313
319
314
-
This wrapper implementation boils down to a custom handler. It is based on a class inherited from logging.Handler.
315
-
The initializer of this class will require the message manager to be passed as an argument in order to link the standard logging service with the ANSYS internal message manager.
320
+
This wrapper implementation boils down to a custom handler. It is based on a
321
+
class inherited from logging.Handler. The initializer of this class will require
322
+
the message manager to be passed as an argument in order to link the standard
323
+
logging service with the ANSYS internal message manager.
316
324
317
325
.. code:: python
318
326
@@ -330,9 +338,17 @@ The initializer of this class will require the message manager to be passed as a
330
338
331
339
332
340
The purpose of this class is to send log messages in AEDT logging stream.
333
-
One of the mandatory actions is to overwrite the ``emit`` function. This method operates as a proxy. It will dispatch all the log message toward the message manager.
334
-
Based on the record level, the message is sent to the appropriate log level (debug, info, error...) into the message manager to fit the level provided by the ANSYS product.
335
-
As a reminder the record is an object containing all kind of information related to the event logged.
336
-
337
-
This custom handler is used into the new logger instance (the one based on the standard library).
338
-
A good practice before to add a handler on any logger is to verify if any appropriate handler is already available in order to avoid any conflict, message duplication...
341
+
One of the mandatory actions is to overwrite the ``emit`` function. This method
342
+
operates as a proxy. It will dispatch all the log message toward the message
343
+
manager.
344
+
Based on the record level, the message is sent to the appropriate log level
345
+
(debug, info, error...) into the message manager to fit the level provided by
346
+
the ANSYS product.
347
+
As a reminder the record is an object containing all kind of information related
348
+
to the event logged.
349
+
350
+
This custom handler is used into the new logger instance (the one based on the
351
+
standard library).
352
+
A good practice before to add a handler on any logger is to verify if any
353
+
appropriate handler is already available in order to avoid any conflict, message
0 commit comments