Changeset 416

Show
Ignore:
Timestamp:
07/16/08 10:40:43 (1 month ago)
Author:
apdavison
Message:

Harmonization of logging setup across simulators (see #66). Also fixes bug #105.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/nest1/__init__.py

    r414 r416  
    77 
    88import pynest 
    9 from pyNN import common, recording 
     9from pyNN import common, recording, utility 
    1010from pyNN.random import * 
    1111import numpy, types, sys, shutil, os, logging, copy, tempfile 
     
    8888    global tempdir 
    8989     
     90    # Initialisation of the log module. To write in the logfile, simply enter 
     91    # logging.critical(), logging.debug(), logging.info(), logging.warning()  
     92    log_file = "nest1.log" 
     93    if debug: 
     94        if isinstance(debug, basestring): 
     95            log_file = debug 
     96    utility.init_logging(log_file, debug, num_processes(), rank()) 
     97    logging.info("Initialization of Nest") 
     98     
    9099    tempdir = tempfile.mkdtemp() 
    91100    tempdirs.append(tempdir) # append tempdir to tempdirs list 
     
    111120                        'rng_seeds'   : rng_seeds[0:num_threads], 
    112121                        'buffsize'    : batchsize}) 
    113      
    114     # Initialisation of the log module. To write in the logfile, simply enter 
    115     # logging.critical(), logging.debug(), logging.info(), logging.warning()  
    116     if debug: 
    117         logging.basicConfig(level=logging.DEBUG, 
    118                     format='%(asctime)s %(levelname)s %(message)s', 
    119                     filename='nest.log', 
    120                     filemode='w') 
    121     else: 
    122         logging.basicConfig(level=logging.INFO, 
    123                     format='%(asctime)s %(levelname)s %(message)s', 
    124                     filename='nest.log', 
    125                     filemode='w') 
    126  
    127     logging.info("Initialization of Nest")     
     122        
    128123    return 0 
    129124 
  • trunk/src/nest2/__init__.py

    r414 r416  
    77 
    88import nest 
    9 from pyNN import common 
     9from pyNN import common, utility 
    1010from pyNN.random import * 
    1111from pyNN import recording 
     
    290290    simulator but not by others. 
    291291    """ 
     292    global tempdir 
     293    log_file = "nest2.log" 
     294    if debug: 
     295        if isinstance(debug, basestring): 
     296            log_file = debug 
     297    utility.init_logging(log_file, debug, num_processes(), rank()) 
     298    logging.info("Initialization of Nest") 
    292299    common.setup(timestep, min_delay, max_delay, debug, **extra_params) 
    293     global tempdir 
    294300    assert min_delay >= timestep, "min_delay (%g) must be greater than timestep (%g)" % (min_delay, timestep) 
    295301 
     
    327333                                                'max_delay': max_delay}) 
    328334 
    329     # Initialisation of the log module. To write in the logfile, simply enter 
    330     # logging.critical(), logging.debug(), logging.info(), logging.warning() 
    331     if debug: 
    332         if isinstance(debug, basestring): 
    333             filename = debug 
    334         else: 
    335             filename = "nest.log" 
    336         logging.basicConfig(level=logging.DEBUG, 
    337                     format='%(asctime)s %(levelname)s %(message)s', 
    338                     filename=filename, 
    339                     filemode='w') 
    340     else: 
    341         logging.basicConfig(level=logging.INFO, 
    342                     format='%(asctime)s %(levelname)s %(message)s', 
    343                     filename='nest.log', 
    344                     filemode='w') 
    345  
    346     logging.info("Initialization of Nest") 
    347335    return nest.Rank() 
    348336 
  • trunk/src/neuron/__init__.py

    r414 r416  
    1313from pyNN.random import * 
    1414from math import * 
    15 from pyNN import common 
     15from pyNN import common, utility 
    1616from pyNN.neuron.cells import * 
    1717from pyNN.neuron.connectors import * 
     
    414414    simulator but not by others. 
    415415    """ 
    416     global nhost, myid, logger, initialised, quit_on_end, running 
     416    global nhost, myid, initialised, quit_on_end, running 
    417417    load_mechanisms() 
    418418    if 'quit_on_end' in extra_params: 
    419419        quit_on_end = extra_params['quit_on_end'] 
    420     # Initialisation of the log module. To write in the logfile, simply enter 
    421     # logging.critical(), logging.debug(), logging.info(), logging.warning()  
    422     if debug: 
    423         logging.basicConfig(level=logging.DEBUG, 
    424                     format='%(asctime)s %(levelname)s %(message)s', 
    425                     filename='neuron.log', 
    426                     filemode='w') 
    427     else: 
    428         logging.basicConfig(level=logging.INFO, 
    429                     format='%(asctime)s %(levelname)s %(message)s', 
    430                     filename='neuron.log', 
    431                     filemode='w') 
    432          
    433     logging.info("Initialization of NEURON (use setup(.., debug=True) to see a full logfile)") 
    434420     
    435421    # All the objects that will be used frequently in the hoc code are declared in the setup 
     
    462448            h('cvode = new CVode()') 
    463449            h.cvode.active(1) 
    464          
     450     
     451    # Initialisation of the log module. To write in the logfile, simply enter 
     452    # logging.critical(), logging.debug(), logging.info(), logging.warning() 
     453    log_file = "neuron.log" 
     454    if debug: 
     455        if isinstance(debug, basestring): 
     456            log_file = debug 
     457    utility.init_logging(log_file, debug, num_processes(), rank()) 
     458    logging.info("Initialization of NEURON (use setup(.., debug=True) to see a full logfile)") 
     459     
    465460    nhost = int(h.pc.nhost()) 
    466461    if nhost < 2: 
  • trunk/src/neuron2/__init__.py

    r414 r416  
    3737    global quit_on_end 
    3838    if not simulator.state.initialized: 
    39         utility.init_logging("neuron2.log.%d" % rank(), debug
     39        utility.init_logging("neuron2.log", debug, num_processes(), rank()
    4040        logging.info("Initialization of NEURON (use setup(.., debug=True) to see a full logfile)") 
    4141        simulator.state.initialized = True 
  • trunk/src/recording.py

    r405 r416  
    124124    saved by the simulators). 
    125125    """ 
    126     logging.debug(filename) 
    127126    myfile = open(filename, "r", DEFAULT_BUFFER_SIZE) 
    128127    contents = myfile.readlines() 
    129128    myfile.close() 
    130     logging.debug(contents) 
    131129    data = [] 
    132130    for line in contents: 
     
    139137    if a.size > 0: 
    140138        (Nrow, Ncol) = a.shape 
    141         logging.debug(str(a.shape)) 
     139        #logging.debug(str(a.shape)) 
    142140        #if ((Nrow == 1) or (Ncol == 1)): a = numpy.ravel(a) 
    143141    return a 
  • trunk/src/utility.py

    r366 r416  
    4444    return args 
    4545     
    46 def init_logging(logfile, debug=False): 
     46def init_logging(logfile, debug=False, num_processes=1, rank=0): 
     47    if num_processes > 1: 
     48        logfile += '.%d' % rank 
    4749    if debug: 
    4850        logging.basicConfig(level=logging.DEBUG,