Skip to content

Commit

Permalink
Merge pull request #75 from jedwards4b/logging_facility_improvement
Browse files Browse the repository at this point in the history
improved logging facility
  • Loading branch information
jgfouca committed Mar 3, 2016
2 parents b220994 + 4fe90c5 commit 4fc8fe0
Show file tree
Hide file tree
Showing 24 changed files with 145 additions and 59 deletions.
2 changes: 1 addition & 1 deletion scripts/Tools/case.build
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ OR
"that we have a case.test_build script. If you are in a test that requires"
" multiple builds, provide this flag.")

parser.add_argument("-s", "--sharedlib-only", action="store_true",
parser.add_argument("--sharedlib-only", action="store_true",
help="Only build sharedlibs")

parser.add_argument("-m", "--model-only", action="store_true",
Expand Down
2 changes: 1 addition & 1 deletion scripts/Tools/case.test_build
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ OR
parser.add_argument("--caseroot", default=os.getcwd(),
help="Case directory to build")

parser.add_argument("-s", "--sharedlib-only", action="store_true",
parser.add_argument("--sharedlib-only", action="store_true",
help="Only build sharedlibs")

parser.add_argument("-m", "--model-only", action="store_true",
Expand Down
7 changes: 4 additions & 3 deletions scripts/Tools/standard_script_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
that every script should do.
"""

import sys, os, logging, doctest, argparse
import sys, os, logging, doctest, argparse, logging.config
import __main__ as main
_CIMEROOT = os.environ.get("CIMEROOT")
if(_CIMEROOT is None):
_CIMEROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..","..")
Expand All @@ -15,5 +16,5 @@
import CIME.utils
CIME.utils.check_minimum_python_version(2, 7)
CIME.utils.stop_buffering_output()

logging.basicConfig()
# set up logging to file
logging.basicConfig(level=logging.INFO)
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from entry_id import EntryID
from CIME.utils import expect, get_cime_root, get_model

logger = logging.getLogger(__name__)

class Component(EntryID):
def __init__(self,infile):
"""
Expand Down
6 changes: 4 additions & 2 deletions utils/python/CIME/XML/entry_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from CIME.utils import expect
from generic_xml import GenericXML

logger = logging.getLogger(__name__)

class EntryID(GenericXML):

def __init__(self, infile=None):
Expand Down Expand Up @@ -36,7 +38,7 @@ def set_default_value(self, vid, attributes=None):
if (att.key in attributes):
if (re.search(attributes[att.key],att.text)):
value = valnode.text
logging.info("id %s value %s" % (vid, valnode.text))
logger.info("id %s value %s" % (vid, valnode.text))

if (value is None):
value = self.get_node("default_value", root=node)
Expand Down Expand Up @@ -164,7 +166,7 @@ def add_elements_by_group(self, srcobj, attlist, infile):
self.set_default_value(node, attlist)
node = self.cleanupnode(node)
self.groups[gname].append(node)
logging.info ("Adding to group "+gname)
logger.debug ("Adding to group "+gname)
return nodelist

def cleanupnode(self,node):
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/env_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from env_base import EnvBase

logger = logging.getLogger(__name__)

class EnvArchive(EnvBase):
def __init__(self, case_root=os.getcwd(), infile="env_archive.xml"):
"""
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/env_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from entry_id import EntryID
from headers import Headers

logger = logging.getLogger(__name__)

class EnvBase(EntryID):
def __init__(self, case_root, infile):
if(os.path.isabs(infile)):
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/env_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from env_base import EnvBase

logger = logging.getLogger(__name__)

class EnvBatch(EnvBase):
def __init__(self, case_root=os.getcwd(), infile="env_batch.xml"):
"""
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/env_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from env_base import EnvBase

logger = logging.getLogger(__name__)

class EnvBuild(EnvBase):
def __init__(self, case_root=os.getcwd(), infile="env_build.xml"):
"""
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/env_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from env_base import EnvBase

logger = logging.getLogger(__name__)

class EnvCase(EnvBase):
def __init__(self, case_root=os.getcwd(), infile="env_case.xml"):
"""
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/env_mach_pes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from env_base import EnvBase

logger = logging.getLogger(__name__)

class EnvMachPes(EnvBase):
def __init__(self, case_root=os.getcwd(), infile="env_mach_pes.xml"):
"""
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/env_mach_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from generic_xml import GenericXML

logger = logging.getLogger(__name__)

class EnvMachSpecific(GenericXML):

def __init__(self, caseroot, infile="env_mach_specific.xml"):
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/env_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from env_base import EnvBase

logger = logging.getLogger(__name__)

class EnvRun(EnvBase):
def __init__(self, case_root=os.getcwd(), infile="env_run.xml"):
"""
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/env_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from env_base import EnvBase

logger = logging.getLogger(__name__)

class EnvTest(EnvBase):
def __init__(self, case_root=os.getcwd(), infile="env_test.xml"):
"""
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from entry_id import EntryID
from CIME.utils import expect, get_cime_root, get_model

logger = logging.getLogger(__name__)

class Files(EntryID):
def __init__(self):
"""
Expand Down
20 changes: 11 additions & 9 deletions utils/python/CIME/XML/generic_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from xml.dom import minidom
from CIME.utils import expect, get_cime_root

logger = logging.getLogger(__name__)

class GenericXML(object):

def __init__(self, infile=None):
Expand Down Expand Up @@ -37,14 +39,14 @@ def read(self, infile):
"""
Read and parse an xml file into the object
"""
logging.info("read: "+infile)
logger.debug("read: "+infile)
self.tree = ET.parse(infile)
self.root = self.tree.getroot()
if ("version" in self.root.attrib):
self.version = self.root.attrib["version"]
else:
self.version = "1.0"
logging.info("File version is "+self.version)
logger.debug("File version is "+self.version)


def write(self, outfile=None):
Expand All @@ -53,7 +55,7 @@ def write(self, outfile=None):
"""
if(outfile is None):
outfile = self.filename
logging.info("write: "+ outfile)
logger.debug("write: "+ outfile)
xmlstr = ET.tostring(self.root)
doc = minidom.parseString(xmlstr)
with open(outfile,'w') as xmlout:
Expand Down Expand Up @@ -101,15 +103,15 @@ def get_value(self, item,resolved=True):
"""
get_value is expected to be defined by the derived classes, if you get here it is an error.
"""
logging.debug("Get Value for "+item)
logger.debug("Get Value for "+item)
result = None
if item in self.lookups.keys():
result = self.lookups[item]
if item in os.environ:
result = os.environ.get(item)

if (result is None):
logging.info("No value available for item '%s'" % item)
logger.debug("No value available for item '%s'" % item)
elif(resolved):
result = self.get_resolved_value(result)

Expand All @@ -135,7 +137,7 @@ def get_resolved_value(self, raw_value):
>>> obj.get_resolved_value("one $ENV{FOO} two $ENV{BAZ} three")
'one BAR two BARF three'
"""
logging.debug("raw_value %s" % raw_value)
logger.debug("raw_value %s" % raw_value)
reference_re = re.compile(r'\$(\w+)')
env_ref_re = re.compile(r'\$ENV\{(\w+)\}')
item_data = raw_value
Expand All @@ -144,17 +146,17 @@ def get_resolved_value(self, raw_value):
return None

for m in env_ref_re.finditer(item_data):
logging.debug("look for "+item_data+ " in env")
logger.debug("look for "+item_data+ " in env")
env_var = m.groups()[0]
expect(env_var in os.environ, "Undefined env var '%s'" % env_var)
item_data = item_data.replace(m.group(), os.environ[env_var])

for m in reference_re.finditer(item_data):
var = m.groups()[0]
logging.debug("find: "+var)
logger.debug("find: "+var)
ref = self.get_value(var)
if(ref is not None):
logging.debug("resolve: "+ref)
logger.debug("resolve: "+ref)
item_data = item_data.replace(m.group(), self.get_resolved_value(ref))

return item_data
2 changes: 2 additions & 0 deletions utils/python/CIME/XML/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from files import Files
from CIME.utils import expect, get_cime_root, get_model

logger = logging.getLogger(__name__)

class Headers(EntryID):
def __init__(self,infile=None):
"""
Expand Down
13 changes: 7 additions & 6 deletions utils/python/CIME/XML/machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from files import Files
from CIME.utils import expect

logger = logging.getLogger(__name__)

class Machines(GenericXML):

def __init__(self, infile=None, files=None, machine=None):
Expand All @@ -24,7 +26,6 @@ def __init__(self, infile=None, files=None, machine=None):
files = Files()
infile = files.get_value("MACHINES_SPEC_FILE")

logging.info("Open file " + infile)
GenericXML.__init__(self, infile)

if (machine is None):
Expand Down Expand Up @@ -67,7 +68,7 @@ def probe_machine_name(self):

for node in nodes:
machtocheck = node.get("MACH")
logging.debug("machine is " + machtocheck)
logger.debug("machine is " + machtocheck)
self.set_machine(machtocheck)
regex_str_nodes = self.get_node("NODENAME_REGEX", root=self.machine)

Expand All @@ -77,15 +78,15 @@ def probe_machine_name(self):
regex_str = machtocheck

if (regex_str is not None):
logging.debug("machine regex string is " + regex_str)
logger.debug("machine regex string is " + regex_str)
regex = re.compile(regex_str)
if (regex.match(nametomatch)):
logging.info("Found machine: %s matches %s" % (machtocheck, nametomatch))
logger.info("Found machine: %s matches %s" % (machtocheck, nametomatch))
machine = machtocheck
break

if (machine is None):
logging.warning("Could not probe machine for hostname '%s'" % nametomatch)
logger.warning("Could not probe machine for hostname '%s'" % nametomatch)

return machine

Expand Down Expand Up @@ -217,7 +218,7 @@ def has_batch_system(self):
batch_system = self.get_node("batch_system")
if (batch_system):
result = (batch_system[0].get("type") != "none")
logging.debug("Machine %s has batch: %s" % (self.name, result))
logger.debug("Machine %s has batch: %s" % (self.name, result))
return result

def get_batch_system_type(self):
Expand Down
4 changes: 3 additions & 1 deletion utils/python/CIME/XML/testlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from generic_xml import GenericXML
from CIME.utils import expect, get_cime_root, get_model

logger = logging.getLogger(__name__)

class Testlist(GenericXML):
def __init__(self,infile):
"""
Expand Down Expand Up @@ -81,6 +83,6 @@ def get_tests(self, machine=None, category=None, compiler=None):
elif (self.version == "2.0"):
return self._get_testsv2(machine,category,compiler)
else:
logging.critical("Did not recognize testlist file version %s for file %s"
logger.critical("Did not recognize testlist file version %s for file %s"
% (self.version,self.filename))

2 changes: 2 additions & 0 deletions utils/python/CIME/XML/testspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

_VERSION = "1.0"

logger = logging.getLogger(__name__)

class TestSpec(GenericXML):
def __init__(self,infile):
"""
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from CIME.XML.env_archive import EnvArchive
from CIME.XML.env_batch import EnvBatch

logger = logging.getLogger(__name__)

class Case(object):

def __init__(self, case_root=os.getcwd()):
Expand Down
2 changes: 2 additions & 0 deletions utils/python/CIME/env_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from CIME.XML.machines import Machines
from CIME.XML.env_mach_specific import EnvMachSpecific

logger = logging.getLogger(__name__)

class EnvModule(object):

# TODO - write env_mach_specific files into case
Expand Down
Loading

0 comments on commit 4fc8fe0

Please sign in to comment.