Skip to content

Commit

Permalink
Greatly improved logging
Browse files Browse the repository at this point in the history
- using a singleton class
- all log messages are now in one file
  • Loading branch information
ryklin committed Feb 25, 2016
1 parent f0a5f3c commit 6b7ee6a
Show file tree
Hide file tree
Showing 9 changed files with 430 additions and 184 deletions.
38 changes: 21 additions & 17 deletions MonkeyLogic/initio.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
% Last modified 8/11/08 -WA (to make certain analog-input objects use DMA)
% Last modified 11/17/15 -ER (Added DigitalInputStream for touchscreens and other future devices)

disp('<<< MonkeyLogic >>> Initializing I/O')
logger = log4m.getLogger('log.txt');
logger.setCommandWindowLevel(logger.ALL);
logger.setLogLevel(logger.ALL);

logger.info('initio.m', '<<< MonkeyLogic >>> Initializing I/O');

%for manual editing:
configIO.AI.BufferingConfig = [16 1024]; %[1 2000];
Expand Down Expand Up @@ -56,7 +60,7 @@
elseif strcmp(fnfrag, 'TTL'),
REQSYS.(fn) = {'DigitalIO'};
else
fprintf('Warning: Unable to test IO type %s for subsystem validity using "initio.m"', fn);
logger.info('initio.m', sprintf('Warning: Unable to test IO type %s for subsystem validity using "initio.m"', fn));
end
end

Expand All @@ -72,7 +76,7 @@
DaqError = cell(2, 1);
DaqError{1} = '*** Error: Non-permitted I/O mapping ***';
DaqError{2} = sprintf('Allowed Type for %s: %s %s ', fn, reqsys{:});
fprintf('*** Error: Non-permitted I/O mapping for %s ***', fn);
logger.info('initio.m', sprintf('*** Error: Non-permitted I/O mapping for %s ***', fn));
return
end
end
Expand All @@ -90,7 +94,7 @@
end
if length(unique(aicstr)) > 1,
DaqError{1} = '*** Error: All analog inputs must be on the same board ***';
disp(DaqError{1})
logger.info('initio.m', DaqError{1});
return
end

Expand All @@ -108,7 +112,7 @@
end
if count > 1 && length(unique(butsys)) > 1,
DaqError{1} = '*** Error: Button inputs must be either all analog or all digital ***';
disp(DaqError{1})
logger.info('initio.m', DaqError{1});
end

DAQ.AnalogInput = [];
Expand All @@ -131,7 +135,7 @@
if EyeXpresent || EyeYpresent,
if numfieldsEyeX ~= numfieldsEyeY,
DaqError{1} = 'I/O Error: Must define 0 or 2 eye signal inputs';
disp('I/O Error: Must define 0 or 2 eye signal inputs')
logger.info('initio.m', 'I/O Error: Must define 0 or 2 eye signal inputs');
return
end
end
Expand All @@ -145,7 +149,7 @@
if JoyXpresent || JoyYpresent,
if numfieldsJoyX ~= numfieldsJoyY,
DaqError{1} = 'I/O Error: Must define 0 or 2 joystick inputs';
disp('I/O Error: Must define 0 or 2 joystick inputs')
logger.info('initio.m', 'I/O Error: Must define 0 or 2 joystick inputs');
return
end
end
Expand All @@ -159,7 +163,7 @@
if TouchXpresent || TouchYpresent,
if numfieldsTouchX ~= numfieldsTouchY,
DaqError{1} = 'I/O Error: Must define 0 or 2 touchscreen inputs';
disp('I/O Error: Must define 0 or 2 touchscreen inputs')
logger.info('initio.m', 'I/O Error: Must define 0 or 2 touchscreen inputs');
return
end
end
Expand All @@ -173,7 +177,7 @@
if MouseXpresent || MouseYpresent,
if numfieldsMouseX ~= numfieldsMouseY,
DaqError{1} = 'I/O Error: Must define 0 or 2 mouse inputs';
disp('I/O Error: Must define 0 or 2 mouse inputs')
logger.info('initio.m', 'I/O Error: Must define 0 or 2 mouse inputs');
return
end
end
Expand Down Expand Up @@ -204,7 +208,7 @@
[DAQ.AnalogInput DaqError] = init_ai(IO.(signame).Constructor, configIO);
if ~isempty(DaqError),
DaqError{1} = sprintf('%s: %s', signame, DaqError{1});
disp(DaqError{1})
logger.info('initio.m', DaqError{1});
daqreset;
return
end
Expand Down Expand Up @@ -277,8 +281,8 @@
elseif ~any(board2) && configIO.AI.AnalogInputDuplication,
h = findobj('tag', 'monkeylogicmainmenu');
if ~isempty(h) && strcmpi(get(findobj(h, 'tag', 'aiduplication'), 'enable'), 'on'),
fprintf('Warning: No duplicate boards found to assign %s...', signame);
disp('... must sample and store data from the same DAQ board (suboptimal performance will result)');
logger.info('initio.m', sprintf('Warning: No duplicate boards found to assign %s...', signame));
logger.info('initio.m', '... must sample and store data from the same DAQ board (suboptimal performance will result)');
end
end

Expand Down Expand Up @@ -329,19 +333,19 @@

if ~isfield(IO.CodesDigOut, 'Constructor'),
DaqError{1} = '*** No digital lines assigned for event marker output ***';
disp(DaqError{1});
logger.info('initio.m', DaqError{1});
daqreset;
return
end
if ~isfield(IO.DigCodesStrobeBit, 'Constructor'),
DaqError{1} = '*** Must assign a strobe bit for behavioral code digital output ***';
disp(DaqError{1});
logger.info('initio.m', DaqError{1});
daqreset;
return
end
if ~strcmp(IO.DigCodesStrobeBit.Constructor, IO.CodesDigOut.Constructor),
DaqError{1} = '*** Strobe bit line must be on the same board & subsystem as the behavioral code data lines ***';
disp(DaqError{1});
logger.info('initio.m', DaqError{1});
daqreset;
return
end
Expand All @@ -360,7 +364,7 @@
DAQ.BehavioralCodes.DataBits = addline(DAQ.BehavioralCodes.DIO, hwlines, 'out', 'BehaviorCodes');
catch
DaqError{1} = '*** Unable to assign output digital lines for Behavioral Codes ***';
disp(DaqError{1});
logger.info('initio.m', DaqError{1});
rethrow(lasterror);
daqreset;
return
Expand All @@ -372,7 +376,7 @@
DAQ.BehavioralCodes.StrobeBit = addline(DAQ.BehavioralCodes.DIO, hwline, portnumber, 'out', 'StrobeBit');
catch
DaqError{1} = sprintf('*** Unable to assign line %i on port %i as a digital strobe output bit ***', hwline, portnumber);
disp(DaqError{1});
logger.info('initio.m', DaqError{1});
daqreset;
return
end
Expand Down
5 changes: 4 additions & 1 deletion MonkeyLogic/initstim.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
function C = initstim(fname, ScreenInfo)
% Created 8/23/08 -WA
logger = log4m.getLogger('log.txt');
logger.setCommandWindowLevel(logger.ALL);
logger.setLogLevel(logger.ALL);

P = getpref('MonkeyLogic');
sourcefile = [P.Directories.BaseDirectory fname];
fprintf('<<< MonkeyLogic >>> Initstim.m is looking for %s\r\n', sourcefile);
logger.info('initstim.m', sprintf('<<< MonkeyLogic >>> Looking for %s', sourcefile));
[pname fname ext] = fileparts(sourcefile);
processedfile = [pname filesep fname '_preprocessed.mat'];
if strcmpi(ext, '.avi'),
Expand Down
14 changes: 9 additions & 5 deletions MonkeyLogic/ioscan.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
% Modified 2/1/07 (bug in digitalio assignments fixed) --WA
% Modified 1/4/08 (improved error handling) --WA

disp('<<< MonkeyLogic >>> Gathering I/O board info (running ioscan.m)...')
logger = log4m.getLogger('log.txt');
logger.setCommandWindowLevel(logger.ALL);
logger.setLogLevel(logger.ALL);

logger.info('ioscan.m', '<<< MonkeyLogic >>> Gathering I/O board info (running ioscan.m)...');
hwinfo = daqhwinfo;
fprintf('<<< MonkeyLogic >>> DAQ Driver Version: %s %s\n', daq.getVendors().FullName, daq.getVendors().DriverVersion);
fprintf('<<< MonkeyLogic >>> DAQ Toolbox Version: %s %s\n', hwinfo.ToolboxName, hwinfo.ToolboxVersion);
logger.info('ioscan.m', sprintf('<<< MonkeyLogic >>> DAQ Driver Version: %s %s', daq.getVendors().FullName, daq.getVendors().DriverVersion));
logger.info('ioscan.m', sprintf('<<< MonkeyLogic >>> DAQ Toolbox Version: %s %s', hwinfo.ToolboxName, hwinfo.ToolboxVersion));

%insert an additional adapter
numFound = length(hwinfo.InstalledAdaptors);
Expand Down Expand Up @@ -116,9 +120,9 @@
end
end

fprintf('<<< MonkeyLogic >>> Found %i I/O adaptors:\n', length(adaptors));
logger.info('ioscan.m', sprintf('<<< MonkeyLogic >>> Found %i I/O adaptors:', length(adaptors)));
for i = 1:length(adaptors),
fprintf('... %i) %s\n', i, adaptors{i});
logger.info('ioscan.m', sprintf('... %i) %s', i, adaptors{i}));
end
AdaptorInfo = AdaptorInfo(1:totalboards);

8 changes: 6 additions & 2 deletions MonkeyLogic/load_conditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
% Modified 8/19/08 -WA (to handle non-integer RelativeFrequency values)
%

logger = log4m.getLogger('log.txt');
logger.setCommandWindowLevel(logger.ALL);
logger.setLogLevel(logger.ALL);

cerror = '';
Conditions = struct;

Expand Down Expand Up @@ -50,7 +54,7 @@
end

fid = fopen(txtfile);
disp(sprintf('<<< MonkeyLogic >>> Loading conditions file', txtfile));
logger.info('loadconditions.m', sprintf('<<< MonkeyLogic >>> Loading conditions file %s', txtfile));
if fid < 1,
cerror = 'Unable to open Conditions file';
return
Expand Down Expand Up @@ -91,7 +95,7 @@
i=i+1;
if i > length(h)+5,
cerror = 'Unable to parse conditions file header.';
fprintf('Valid columns are "Condition", "Frequency", "Block", "Timing File", "Info", and "TaskObject#1" through TaskObject#N".\n');
logger.info('loadconditions.m', sprintf('Valid columns are "Condition", "Frequency", "Block", "Timing File", "Info", and "TaskObject#1" through TaskObject#N".'));
return
end
end
Expand Down
Loading

0 comments on commit 6b7ee6a

Please sign in to comment.