Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup_logger(log_path):
'''
Changer the GillesPy2 logger to record only error level logs and higher
to the console and to log warning level logs and higher to a log file in
the workflow directory.
Attributes
----------
workflow_path : str
Path to the workflow directory
'''
formatter = log.handlers[0].formatter # gillespy2 log formatter
fh_is_needed = True
for handler in log.handlers:
if type(handler) is logging.StreamHandler:
handler.stream = sys.stderr # Reset the stream to stderr
handler.setLevel(logging.ERROR) # Only log error and critical logs to console
elif type(handler) is logging.FileHandler:
fh_is_needed = False # File Handler was already added to the log
# Add the file handler if it not in the log already
if fh_is_needed:
fh = logging.FileHandler(log_path) # initialize file handler
fh.setLevel(logging.WARNING) # log warning, error, and critical logs to file
fh.setFormatter(formatter) # add gillespy2 log formatter
log.addHandler(fh) # add file handler to log
#!/usr/bin/env python3
import os
import sys
import json
import argparse
import logging
import pickle
import plotly
from io import StringIO
from gillespy2.core import log
log_stream = StringIO()
for handler in log.handlers:
if type(handler) is logging.StreamHandler:
handler.stream = log_stream
from gillespy2 import Species, Parameter, Reaction, RateRule, Model, AssignmentRule, FunctionDefinition
import numpy
import gillespy2.core.gillespySolver
from gillespy2.core.events import EventAssignment, EventTrigger, Event
from gillespy2.core.gillespyError import ModelError, SolverError, DirectoryError, BuildError, ExecutionError
from gillespy2.solvers.numpy.basic_tau_leaping_solver import BasicTauLeapingSolver
from gillespy2.solvers.numpy.basic_tau_hybrid_solver import BasicTauHybridSolver
from gillespy2.solvers.cpp.variable_ssa_c_solver import VariableSSACSolver
import warnings
warnings.simplefilter("ignore")