Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not configure root logger #208

Merged
merged 15 commits into from
Nov 26, 2020
1 change: 0 additions & 1 deletion ecl2df/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
)


logging.basicConfig()
logger = logging.getLogger(__name__)


Expand Down
3 changes: 1 addition & 2 deletions ecl2df/compdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion ecl2df/eclfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions ecl2df/equil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions ecl2df/faults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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-"]
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions ecl2df/fipreports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions ecl2df/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from ecl2df import common, __version__
from .eclfiles import EclFiles

logging.basicConfig()
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions ecl2df/gruptree.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
write_dframe_stdout_file,
)

logging.basicConfig()
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion ecl2df/inferdims.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions ecl2df/nnc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from ecl2df import common, EclFiles, grid, __version__

logging.basicConfig()
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion ecl2df/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from ecl2df.eclfiles import EclFiles

logging.basicConfig()
logger = logging.getLogger(__name__)


Expand Down
3 changes: 1 addition & 2 deletions ecl2df/pillars.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import ecl2df

logging.basicConfig()
logger = logging.getLogger(__name__)

AGGREGATORS = {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions ecl2df/pvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions ecl2df/rft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 2 additions & 3 deletions ecl2df/satfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions ecl2df/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions ecl2df/trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
except ImportError:
HAVE_NETWORKX = False

logging.basicConfig()
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions ecl2df/wcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
20 changes: 20 additions & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -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