Members
(constant) Level
Logging levels.
- Source
(constant) LogFmt
Logging formats which are suitable for general messages (usually strings) as 'log', arrays as 'tab' or 'dir' and objects as 'dir'.
- Source
Methods
ctxt(replacePattern, replaceStr, padLen) → {string}
Gets name of calling function name for logging purposes.
Name | Type | Description |
---|---|---|
replacePattern | RegExp | Pattern to replace from start of function name as it is returned from the stack trace. Default: /http.*/js// |
replaceStr | string | Replacement string for pattern from start of function name as it is returned from the stack trace. Default: '' |
padLen | number | Length for left-padding function name. Default: 52 |
- Source
The caller function name, filtered as specified.
- Type:
- string
// Example import:
import { Level, loggingAt, logging, ctxt, log } from './logging.js';
// Example usage:
LOGLEV = Level.Debug;
function someFunc() {
log(Level.Info, `The current log level is '${LOGLEV}'`, ctxt());
log(Level.Debug, `This is a debugging message`, ctxt());
}
// Specifying non-default args:
// Note: Set args to 'undefined' for default parameter values
const ctxt1 = ctxt(/.*[@].*\/js\//);
const ctxt2 = ctxt(undefined, ':');
const ctxt3 = ctxt(undefined, undefined, 60);
log(level, obj, logCtxt, logFmt)
Logs the given message at the current global logging level.
Name | Type | Description |
---|---|---|
level | object | A valid |
obj | object | The object to log at the specified logging level. this would typically be a string (message) but could also be, e.g., an array or class object, particularly if used in conjunction with a non-defualt value for |
logCtxt | string | The logging context. Can be any string but would usually contain information about the calling function. |
logFmt | object | A valid |
- Source
LOGLEV = Level.Info;
log(Level.Info, `The current log level is '${LOGLEV}'`, ctxt());
const value = { 1: 'one', 2: 'two', 3: 'three' };
log(Level.Debug, value, ctxt(), 'tab');
log(Level.Debug, value, ctxt(), 'dir');
class Fruit {
constructor(type, colour) {
this.type = type;
this.colour = colour;
}
}
log(Level.Vbose, new Fruit('avo', 'green'), ctxt(), 'dir');
logging() → {boolean}
Checks if the logging level is enabled, i.e. if it is above 'Level.None'.
- Source
true if logging is enabled, false if not.
- Type:
- boolean
if (logging()) { log(Level.Info, 'Logging is enabled.'); }
loggingAt(level) → {boolean}
Checks if the logging level is enabled at or above the specified level.
Name | Type | Description |
---|---|---|
level | object | The |
- Source
true if logging is enabled at or above the specified level, false if not.
- Type:
- boolean
if (loggingAt(Level.Info)) { log(Level.Info, 'Logging at info level.'); }
if (loggingAt(Level.Debug)) { log(Level.Info, 'Logging at debug level.'); }
Type Definitions
Config
Class to manage static configuration information for the number grid and associated classes.
- Object
Dims
A collection of static functions relating dimensions for NumberGrid
.
- Object
GridAnimator
Class to handle grid animation, i.e. the animated 'counting along'.
- Object
- Source
GridScroller
Class to handle scrolling of the grid if the animation goes vertically outside of the current viewport.
- Object
- Source
InputValidator
Class to handle input validation for the grid configuration.
- object
Name | Type | Description |
---|---|---|
configCols | Array.<object> | An array of HTML elements which are the containers for columns in the config form. |
keyOrder | Array.<string> | An array of strings which are the HTML id's of the fields to validate. |
fields | Array.<object> | An associative array of HTMLInputElement objects which are the input fields to validate. The keys must match those in |
valid | Array.<object> | An associative array of boolean values, one for each of the input fields to validate, named according to the keys in |
- Source
MediaHandler
Class to handle media queries.
- Object
- Source
NumberGrid
Class to manage the number grid.
- Object
- Source
State
Class to represent possible number grid states.
- Object
TitleAnimator
Class to manage animating the HTML title.
- Object
- Source