| 
 | 1 | +Logging  | 
 | 2 | +=======  | 
 | 3 | + | 
 | 4 | +Python’s standard `logging <https://docs.python.org/3/library/logging.html>`_ module is used to implement debug log output for ingredient-parser.  | 
 | 5 | +This allows ingredient-parser's logging to integrate in a standard way with other application and libraries.  | 
 | 6 | + | 
 | 7 | +All logging for ingredient-parser is within ``ingredient-parser`` namespace.  | 
 | 8 | + | 
 | 9 | +* The ``ingredient-parser`` namespace contains general logging for parsing of ingredient sentences.  | 
 | 10 | +* The ``ingredient-parser.foundation-foods`` namespace contains logging related to the :doc:`Foundation Foods </explanation/foundation>` functionality.  | 
 | 11 | + | 
 | 12 | +For example, to output debug logs to stdout:  | 
 | 13 | + | 
 | 14 | +.. code:: python  | 
 | 15 | +
  | 
 | 16 | +  >>> import logging, sys  | 
 | 17 | +  >>> from ingredient_parser import parse_ingredient  | 
 | 18 | +  >>>  | 
 | 19 | +  >>> logging.basicConfig(stream=sys.stdout)  | 
 | 20 | +  >>> logging.getLogger("ingredient-parser").setLevel(logging.DEBUG)  | 
 | 21 | +  >>>  | 
 | 22 | +  >>> parsed = parse_ingredient("24 fresh basil leaves or dried basil")  | 
 | 23 | +  DEBUG:ingredient-parser:Parsing sentence "24 fresh basil leaves or dried basil" using "en" parser.  | 
 | 24 | +  DEBUG:ingredient-parser:Normalised sentence: "24 fresh basil leaves or dried basil".  | 
 | 25 | +  DEBUG:ingredient-parser:Tokenized sentence: ['24', 'fresh', 'basil', 'leaf', 'or', 'dried', 'basil'].  | 
 | 26 | +  DEBUG:ingredient-parser:Singularised tokens at indices: [3].  | 
 | 27 | +  DEBUG:ingredient-parser:Generating features for tokens.  | 
 | 28 | +  DEBUG:ingredient-parser:Sentence token labels: ['QTY', 'B_NAME_TOK', 'I_NAME_TOK', 'I_NAME_TOK', 'NAME_SEP', 'B_NAME_TOK', 'I_NAME_TOK'].  | 
 | 29 | +
  | 
 | 30 | +Only enabling logging for foundation foods:  | 
 | 31 | +
  | 
 | 32 | +.. code:: python  | 
 | 33 | +
  | 
 | 34 | +  >>> import logging, sys  | 
 | 35 | +  >>> from ingredient_parser import parse_ingredient  | 
 | 36 | +  >>>  | 
 | 37 | +  >>> logging.basicConfig(stream=sys.stdout)  | 
 | 38 | +  >>> logging.getLogger("ingredient-parser.foundation-foods").setLevel(logging.DEBUG)  | 
 | 39 | +  >>>  | 
 | 40 | +  >>> parsed = parse_ingredient("24 fresh basil leaves or dried basil", foundation_foods=True)  | 
 | 41 | +  DEBUG:ingredient-parser.foundation-foods:Matching FDC ingredient for ingredient name tokens: ['fresh', 'basil', 'leaves']  | 
 | 42 | +  DEBUG:ingredient-parser.foundation-foods:Prepared tokens: ['fresh', 'basil', 'leav'].  | 
 | 43 | +  DEBUG:ingredient-parser.foundation-foods:Loaded 13318 FDC ingredients.  | 
 | 44 | +  DEBUG:ingredient-parser.foundation-foods:Selecting best match from 1 candidates based on preferred FDC datatype.  | 
 | 45 | +  DEBUG:ingredient-parser.foundation-foods:Matching FDC ingredient for ingredient name tokens: ['dried', 'basil']  | 
 | 46 | +  DEBUG:ingredient-parser.foundation-foods:Prepared tokens: ['dri', 'basil'].  | 
 | 47 | +  DEBUG:ingredient-parser.foundation-foods:Selecting best match from 1 candidates based on preferred FDC datatype.  | 
0 commit comments