diff --git a/ecl2df/common.py b/ecl2df/common.py index 9f5f55f52..46513c5be 100644 --- a/ecl2df/common.py +++ b/ecl2df/common.py @@ -62,7 +62,6 @@ ) -logging.basicConfig() logger = logging.getLogger(__name__) diff --git a/ecl2df/compdat.py b/ecl2df/compdat.py index 614fa1b3f..1528ddb7e 100644 --- a/ecl2df/compdat.py +++ b/ecl2df/compdat.py @@ -17,7 +17,6 @@ ) from .grid import merge_initvectors -logging.basicConfig() logger = logging.getLogger(__name__) """OPM authors and Roxar RMS authors have interpreted the Eclipse @@ -434,7 +433,7 @@ def fill_parser(parser): def compdat_main(args): """Entry-point for module, for command line utility""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) eclfiles = EclFiles(args.DATAFILE) compdat_df = df(eclfiles, initvectors=args.initvectors) if compdat_df.empty: diff --git a/ecl2df/eclfiles.py b/ecl2df/eclfiles.py index a0f9a34a8..7f756aea0 100644 --- a/ecl2df/eclfiles.py +++ b/ecl2df/eclfiles.py @@ -14,7 +14,6 @@ from ecl.grid import EclGrid from ecl.summary import EclSum -logging.basicConfig() logger = logging.getLogger(__name__) # Default parse option to opm.io for a very permissive parsing diff --git a/ecl2df/equil.py b/ecl2df/equil.py index 0c9dc78c0..a2413851d 100644 --- a/ecl2df/equil.py +++ b/ecl2df/equil.py @@ -10,7 +10,6 @@ from ecl2df import inferdims, common from .eclfiles import EclFiles -logging.basicConfig() logger = logging.getLogger(__name__) SUPPORTED_KEYWORDS = ["EQUIL", "PBVD", "PDVD", "RSVD", "RVVD"] @@ -295,7 +294,7 @@ def fill_reverse_parser(parser): def equil_main(args): """Read from disk and write CSV back to disk""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) eclfiles = EclFiles(args.DATAFILE) if eclfiles: deck = eclfiles.get_ecldeck() @@ -327,7 +326,7 @@ def equil_main(args): def equil_reverse_main(args): """Entry-point for module, for command line utility for CSV to Eclipse""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) equil_df = pd.read_csv(args.csvfile) logger.info("Parsed %s", args.csvfile) inc_string = df2ecl(equil_df, keywords=args.keywords) diff --git a/ecl2df/faults.py b/ecl2df/faults.py index cfe0e25b9..5a928c967 100644 --- a/ecl2df/faults.py +++ b/ecl2df/faults.py @@ -10,10 +10,8 @@ from .eclfiles import EclFiles from .common import parse_opmio_deckrecord -logging.basicConfig() logger = logging.getLogger(__name__) - RECORD_COLUMNS = ["NAME", "IX1", "IX2", "IY1", "IY2", "IZ1", "IZ2", "FACE"] COLUMNS = ["NAME", "I", "J", "K", "FACE"] ALLOWED_FACES = ["X", "Y", "Z", "I", "J", "K", "X-", "Y-", "Z-", "I-", "J-", "K-"] @@ -71,7 +69,7 @@ def fill_parser(parser): def faults_main(args): """Read from disk and write CSV back to disk""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) eclfiles = EclFiles(args.DATAFILE) if eclfiles: deck = eclfiles.get_ecldeck() diff --git a/ecl2df/fipreports.py b/ecl2df/fipreports.py index eb6b6eb8e..61e167ca2 100644 --- a/ecl2df/fipreports.py +++ b/ecl2df/fipreports.py @@ -12,7 +12,6 @@ from .eclfiles import EclFiles from .common import parse_ecl_month, write_dframe_stdout_file -logging.basicConfig() logger = logging.getLogger(__name__) REGION_REPORT_COLUMNS = [ @@ -183,7 +182,7 @@ def fill_parser(parser): def fipreports_main(args): """Command line API""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) if args.PRTFILE.endswith(".PRT"): prtfile = args.PRTFILE else: diff --git a/ecl2df/grid.py b/ecl2df/grid.py index 3436a0c1d..66aa2534f 100644 --- a/ecl2df/grid.py +++ b/ecl2df/grid.py @@ -23,7 +23,6 @@ from ecl2df import common, __version__ from .eclfiles import EclFiles -logging.basicConfig() logger = logging.getLogger(__name__) @@ -652,7 +651,7 @@ def df2ecl( def grid_main(args): """This is the command line API""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) eclfiles = EclFiles(args.DATAFILE) grid_df = df( eclfiles, diff --git a/ecl2df/gruptree.py b/ecl2df/gruptree.py index 9f95b973f..960dcb384 100644 --- a/ecl2df/gruptree.py +++ b/ecl2df/gruptree.py @@ -20,7 +20,6 @@ write_dframe_stdout_file, ) -logging.basicConfig() logger = logging.getLogger(__name__) @@ -292,7 +291,7 @@ def fill_parser(parser): def gruptree_main(args): """Entry-point for module, for command line utility""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) if not args.output and not args.prettyprint: print("Nothing to do. Set --output or --prettyprint") sys.exit(0) diff --git a/ecl2df/inferdims.py b/ecl2df/inferdims.py index 1e1801e1d..bb0e36259 100644 --- a/ecl2df/inferdims.py +++ b/ecl2df/inferdims.py @@ -10,7 +10,6 @@ from ecl2df import EclFiles -logging.basicConfig() logger = logging.getLogger(__name__) # Constants to use for pointing to positions in the xxxDIMS keyword diff --git a/ecl2df/nnc.py b/ecl2df/nnc.py index 07c2440b1..3516414ce 100644 --- a/ecl2df/nnc.py +++ b/ecl2df/nnc.py @@ -9,7 +9,6 @@ from ecl2df import common, EclFiles, grid, __version__ -logging.basicConfig() logger = logging.getLogger(__name__) @@ -274,7 +273,7 @@ def df2ecl_editnnc(nnc_df, filename=None, nocomments=False): def nnc_main(args): """Command line access point from main() or from ecl2csv via subparser""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) eclfiles = EclFiles(args.DATAFILE) nncdf = df(eclfiles, coords=args.coords, pillars=args.pillars) if nncdf.empty: diff --git a/ecl2df/parameters.py b/ecl2df/parameters.py index 80aeb6ece..6eb4db310 100644 --- a/ecl2df/parameters.py +++ b/ecl2df/parameters.py @@ -10,7 +10,6 @@ from ecl2df.eclfiles import EclFiles -logging.basicConfig() logger = logging.getLogger(__name__) diff --git a/ecl2df/pillars.py b/ecl2df/pillars.py index 9fdf450fb..5f45c8f68 100644 --- a/ecl2df/pillars.py +++ b/ecl2df/pillars.py @@ -11,7 +11,6 @@ import ecl2df -logging.basicConfig() logger = logging.getLogger(__name__) AGGREGATORS = { @@ -407,7 +406,7 @@ def fill_parser(parser): def pillars_main(args): """This is the command line API""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) eclfiles = ecl2df.EclFiles(args.DATAFILE) dframe = df( eclfiles, diff --git a/ecl2df/pvt.py b/ecl2df/pvt.py index 8a2b2e637..0ce02cd8e 100644 --- a/ecl2df/pvt.py +++ b/ecl2df/pvt.py @@ -12,7 +12,6 @@ from ecl2df import inferdims, common from .eclfiles import EclFiles -logging.basicConfig() logger = logging.getLogger(__name__) SUPPORTED_KEYWORDS = ["PVTO", "PVDO", "PVTG", "PVDG", "DENSITY", "ROCK", "PVTW"] @@ -246,7 +245,7 @@ def fill_reverse_parser(parser): def pvt_main(args): """Entry-point for module, for command line utility for Eclipse to CSV""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) eclfiles = EclFiles(args.DATAFILE) logger.info("Parsed %s", args.DATAFILE) if eclfiles: @@ -280,7 +279,7 @@ def pvt_main(args): def pvt_reverse_main(args): """Entry-point for module, for command line utility for CSV to Eclipse""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) pvt_df = pd.read_csv(args.csvfile) logger.info("Parsed %s", args.csvfile) inc_string = df2ecl(pvt_df, keywords=args.keywords) diff --git a/ecl2df/rft.py b/ecl2df/rft.py index 6563c8fe1..4461406b1 100644 --- a/ecl2df/rft.py +++ b/ecl2df/rft.py @@ -25,7 +25,6 @@ from .common import merge_zones, write_dframe_stdout_file -logging.basicConfig() logger = logging.getLogger(__name__) # In debug mode, these columns will be exported to three csv files. @@ -675,9 +674,9 @@ def fill_parser(parser): def rft_main(args): """Entry-point for module, for command line utility""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) if args.debug: - logger.setLevel(logging.DEBUG) + logging.basicConfig(level=logging.DEBUG) if args.DATAFILE.endswith(".RFT"): # Support the RFT file as an argument also: eclfiles = EclFiles(args.DATAFILE.replace(".RFT", "") + ".DATA") diff --git a/ecl2df/satfunc.py b/ecl2df/satfunc.py index befe43632..e3d084e28 100644 --- a/ecl2df/satfunc.py +++ b/ecl2df/satfunc.py @@ -20,7 +20,6 @@ from .eclfiles import EclFiles from .common import write_dframe_stdout_file -logging.basicConfig() logger = logging.getLogger(__name__) SUPPORTED_KEYWORDS = ["SWOF", "SGOF", "SWFN", "SGWFN", "SOF2", "SGFN", "SOF3", "SLGOF"] @@ -276,7 +275,7 @@ def fill_reverse_parser(parser): def satfunc_main(args): """Entry-point for module, for command line utility""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) eclfiles = EclFiles(args.DATAFILE) if eclfiles: deck = eclfiles.get_ecldeck() @@ -308,7 +307,7 @@ def satfunc_main(args): def satfunc_reverse_main(args): """For command line utility for CSV to Eclipse""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) satfunc_df = pd.read_csv(args.csvfile) logger.info("Parsed %s", args.csvfile) inc_string = df2ecl(satfunc_df, keywords=args.keywords) diff --git a/ecl2df/summary.py b/ecl2df/summary.py index 13f0469eb..1ebbcc947 100644 --- a/ecl2df/summary.py +++ b/ecl2df/summary.py @@ -15,10 +15,8 @@ from . import parameters from .common import write_dframe_stdout_file -logging.basicConfig() logger = logging.getLogger(__name__) - PD_FREQ_MNEMONICS = { "monthly": "MS", "yearly": "YS", @@ -373,7 +371,7 @@ def fill_parser(parser): def summary_main(args): """Read summary data from disk and write CSV back to disk""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) eclfiles = EclFiles(args.DATAFILE) sum_df = df( eclfiles, diff --git a/ecl2df/trans.py b/ecl2df/trans.py index 2579bd0b6..ade7e58f5 100644 --- a/ecl2df/trans.py +++ b/ecl2df/trans.py @@ -17,7 +17,6 @@ except ImportError: HAVE_NETWORKX = False -logging.basicConfig() logger = logging.getLogger(__name__) @@ -298,7 +297,7 @@ def fill_parser(parser): def trans_main(args): """This is the command line API""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) eclfiles = EclFiles(args.DATAFILE) trans_df = df( eclfiles, diff --git a/ecl2df/wcon.py b/ecl2df/wcon.py index 611bc7784..48af162cb 100644 --- a/ecl2df/wcon.py +++ b/ecl2df/wcon.py @@ -14,7 +14,6 @@ from .eclfiles import EclFiles from .common import parse_opmio_date_rec, OPMKEYWORDS -logging.basicConfig() logger = logging.getLogger(__name__) # The keywords supported in this module. @@ -147,7 +146,7 @@ def fill_parser(parser): def wcon_main(args): """Read from disk and write CSV back to disk""" if args.verbose: - logger.setLevel(logging.INFO) + logging.basicConfig(level=logging.INFO) eclfiles = EclFiles(args.DATAFILE) if eclfiles: deck = eclfiles.get_ecldeck() diff --git a/tests/test_logging.py b/tests/test_logging.py new file mode 100644 index 000000000..4136336b1 --- /dev/null +++ b/tests/test_logging.py @@ -0,0 +1,20 @@ +import sys +import subprocess + +import pytest + +from test_grid import DATAFILE + + +@pytest.mark.skipif(sys.version_info < (3, 7), reason="Requires Python 3.7 or higher") +@pytest.mark.parametrize("verbose", [False, True]) +def test_grid_logging(tmp_path, verbose): + + commands = ["ecl2csv", "grid", DATAFILE, "--output", tmp_path / "eclgrid.csv"] + if verbose: + commands.append("-v") + + result = subprocess.run(commands, check=True, capture_output=True) + output = result.stdout.decode() + result.stderr.decode() + + assert "INFO:" in output if verbose else "INFO:" not in output