Read about our upcoming Code of Conduct on this issue

Commit 4d2a2b54 authored by Pierre Augier's avatar Pierre Augier
Browse files

Better logging

parent eb10fb79a63a
......@@ -562,6 +562,7 @@ class FluidPythran:
class FluidPythranTemporaryMethod:
"""Internal temporary class for methods"""
def __init__(self, func):
self.func = func
......
......@@ -6,6 +6,7 @@ Defines the fluidpythran logger (variable :code:`logger`).
"""
import logging
from types import MethodType
logger = logging.getLogger("fluidpythran")
......@@ -33,15 +34,39 @@ except ImportError:
logger.info("Disabling color, you really want to install colorlog.")
def set_log_level(level):
"""Set logging level"""
def _get_level_number(level):
level = level.lower()
if level == "info":
level = logging.INFO
return logging.INFO
elif level == "debug":
level = logging.DEBUG
return logging.DEBUG
elif level == "warning":
return logging.WARNING
else:
raise ValueError
def set_level(self, level):
"""Set logging level"""
if not level:
self.setLevel(0)
return
level = _get_level_number(level)
self.setLevel(level)
def get_level(self):
return logging.getLevelName(self.getEffectiveLevel()).lower()
def is_enable_for(self, level):
return _get_level_number(level) >= self.getEffectiveLevel()
logger.setLevel(level)
logger.set_level = MethodType(set_level, logger)
logger.get_level = MethodType(get_level, logger)
logger.is_enable_for = MethodType(is_enable_for, logger)
set_log_level("info")
logger.set_level("info")
......@@ -34,7 +34,7 @@ import sys
from .compat import open, implementation
from . import mpi
from .mpi import Path, PathSeq
from .log import logger
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") or ".so"
......@@ -136,6 +136,9 @@ class SchedulerPopen:
if openmp:
update_flags("-fopenmp")
if logger.is_enable_for("info"):
update_flags("-v")
words_command = [
sys.executable,
"-m",
......
......@@ -13,10 +13,11 @@ Internal API
import argparse
from pathlib import Path
from glob import glob
import sys
from . import __version__
from .transpiler import make_pythran_files
from .log import logger, set_log_level
from .log import logger
from .pythranizer import compile_pythran_files, ext_suffix
from .util import has_to_build, clear_cached_extensions
......@@ -38,7 +39,6 @@ def run():
See :code:`fluidpythran -h`
"""
args = parse_args()
# print(args)
if args.version:
print(__version__)
......@@ -53,10 +53,12 @@ def run():
return
if args.verbose is None:
set_log_level("info")
elif args.verbose > 0:
set_log_level("debug")
logger.debug(args)
logger.set_level(None)
elif args.verbose == 1:
logger.set_level("info")
elif args.verbose > 1:
logger.set_level("debug")
logger.info(args)
path = args.path
......@@ -74,6 +76,10 @@ def run():
else:
paths = glob(str(path))
if not paths:
logger.error(f"No input file found (args.path = {args.path})")
sys.exit(1)
make_pythran_files(paths, force=args.force)
if not pythran or args.no_pythran:
......
......@@ -36,8 +36,6 @@ from tokenize import (
OP,
)
from logging import DEBUG
from token import tok_name
import inspect
from io import BytesIO
......@@ -54,7 +52,7 @@ try:
except ImportError:
black = False
from .log import logger, set_log_level
from .log import logger
from .annotation import compute_pythran_types_from_valued_types
from .util import (
has_to_build,
......@@ -465,7 +463,7 @@ def make_pythran_code(path_py: Path):
imports,
) = parse_py_code(code)
if logger.isEnabledFor(DEBUG):
if logger.is_enable_for("debug"):
logger.debug(
f"""
blocks: {blocks}\n
......@@ -644,10 +642,13 @@ def make_pythran_file(
):
"""Create a Python file from a Python file (if necessary)"""
if log_level is not None:
set_log_level(log_level)
logger.set_level(log_level)
path_py = Path(path_py)
if not path_py.exists():
raise FileNotFoundError(f"Input file {path_py} not found")
if path_py.absolute().parent.name == "__pythran__":
logger.debug(f"skip file {path_py}")
return
......@@ -698,7 +699,7 @@ def make_pythran_files(
"""Create Pythran files from a list of Python files"""
if log_level is not None:
set_log_level(log_level)
logger.set_level(log_level)
paths_out = []
for path in paths:
......
......@@ -7,7 +7,7 @@ import black
import numpy as np
from fluidpythran.log import logger, set_log_level
from fluidpythran.log import logger
from fluidpythran.util import get_source_without_decorator
from fluidpythran.annotation import compute_pythran_types_from_valued_types
......@@ -17,7 +17,7 @@ def pythran_def_method(func):
return func
# set_log_level("debug")
# logger.set_level("debug")
from fluidpythran import Array, Type, NDim
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment