forked from M-Labs/artiq
language: add basic logging initializer for experiments
This commit is contained in:
parent
04a049b93d
commit
797bf9830c
|
@ -1,10 +1,11 @@
|
|||
# Copyright (C) 2014, 2015 Robert Jordens <jordens@gmail.com>
|
||||
|
||||
from artiq.language import core, environment, units, scan
|
||||
from artiq.language import core, environment, units, scan, logging
|
||||
from artiq.language.core import *
|
||||
from artiq.language.environment import *
|
||||
from artiq.language.units import *
|
||||
from artiq.language.scan import *
|
||||
from artiq.language.logging import *
|
||||
|
||||
|
||||
__all__ = []
|
||||
|
@ -12,3 +13,4 @@ __all__.extend(core.__all__)
|
|||
__all__.extend(environment.__all__)
|
||||
__all__.extend(units.__all__)
|
||||
__all__.extend(scan.__all__)
|
||||
__all__.extend(logging.__all__)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
from artiq.language.environment import *
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
__all__ = ["LogExperiment"]
|
||||
|
||||
|
||||
class LogExperiment:
|
||||
def init_logger(self):
|
||||
"""Call this from build() to add a logging level enumeration
|
||||
widget, initialize logging globally, and create a logger.
|
||||
|
||||
Your class must also derive from ``HasEnvironment`` (or
|
||||
``EnvExperiment``).
|
||||
|
||||
The created logger is called ``self.logger``."""
|
||||
level = self.get_argument("log_level", EnumerationValue(
|
||||
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]))
|
||||
|
||||
if level is not None:
|
||||
logging.basicConfig(level=getattr(logging, level))
|
||||
self.logger = logging.getLogger(self.__class__.__name__)
|
|
@ -1,5 +1,3 @@
|
|||
import logging
|
||||
|
||||
from artiq import *
|
||||
|
||||
|
||||
|
@ -35,8 +33,10 @@ class SubComponent2(HasEnvironment):
|
|||
print(self.sc2_enum)
|
||||
|
||||
|
||||
class ArgumentsDemo(EnvExperiment):
|
||||
class ArgumentsDemo(EnvExperiment, LogExperiment):
|
||||
def build(self):
|
||||
self.init_logger()
|
||||
|
||||
self.setattr_argument("free_value", FreeValue(None))
|
||||
self.setattr_argument("number", NumberValue(42e-6,
|
||||
unit="s", scale=1e-6,
|
||||
|
@ -53,11 +53,10 @@ class ArgumentsDemo(EnvExperiment):
|
|||
self.sc2 = SubComponent2(parent=self)
|
||||
|
||||
def run(self):
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logging.error("logging test: error")
|
||||
logging.warning("logging test: warning")
|
||||
logging.info("logging test: info")
|
||||
logging.debug("logging test: debug")
|
||||
self.logger.error("logging test: error")
|
||||
self.logger.warning("logging test: warning")
|
||||
self.logger.info("logging test: info")
|
||||
self.logger.debug("logging test: debug")
|
||||
|
||||
print(self.free_value)
|
||||
print(self.boolean)
|
||||
|
|
Loading…
Reference in New Issue