new Logger( loggerName )

Description

Fancy-ish log messages (likely over engineered).

Console nested message groups can be started and ended using the special intro/outro method pairs, entered/leaving and starting/finished. By default, the former are opened and the latter collapsed (documented here as closed).

Individual Loggers can be enabled/disabled by setting the enabled boolean property.

Each Logger will have also have a collection of Groups associated with it. These groups can have one of three modes: opened, closed, silenced. The first two correspond to the browser console nested message groups. The intro and outro type of methods will handle the nesting. If a group is set as silenced, no messages will be sent to the console.

All Logger instances register a configuration with a singleton Map keyed by the instance name. If more than one instance is created with the same name, they all share the same configuration.

Configurations can be exported as a plain object and reimported using the configs property. The object could be saved via the userscript manager. Depending on which manager, it may have to be processed with JSON functions. Once exported, the object may be modified. This could be used to provide a UI to edit the object, though no schema is provided.

Some values may be of interest to users for help in debugging a script.

The callCount value is how many times a logger would have been used for messages, even if the logger is disabled. Similarly, each group associated with a logger also has a callCount. These values can be used to determine which loggers and groups generate a lot of messages and could be disabled or silenced.

The sequence value is a rough indicator of how recently a logger or group was actually used. It is purposely not a timestamp, but rather, more closely associated with how often configurations are restored, e.g. during web page reloads. A low sequence number, relative to the others, may indicate a logger was renamed, groups removed, or simply parts of an application that have not been visited recently. Depending on the situation, one could clean up old configs, or explore other parts of the script.

Handlers may be attached to listen for changes to the configuration singleton using the onConfig and offConfig static methods. Arrival of messages may controlled using configDispatcherEnabled (useful for disabling during testing).

Parameters
Name Type Description
loggerName string

Name for this logger.

Examples
const log = new Logger('Bob');
			foo(x) {
			 const me = foo.name;
			 log.entered(me, x);
			 ... do stuff ...
			 log.starting('loop');
			 for (const item of items) {
			   log.log(`Processing ${item}`);
			   ...
			 }
			 log.finished('loop');
			 log.leaving(me, y);
			 return y;
			}
			
			Logger.config(log.name).enabled = true;
			Logger.config(log.name).group('foo').mode = 'silenced';
			
			GM.setValue('Logger', Logger.configs);
			... restart browser ...
			Logger.configs = GM.getValue('Logger');
Details

Classes


new Config( loggerName )


new Group( mode, logger, group )


new GroupMode( modeName [, greeting [, farewell [, func ] ] ] )

Members


<static> configDispatcherEnabled :boolean

Details
boolean

<static> configs :object

Details
object

<static> loggers :Array.<string>

Details
Array.<string>

includeStackTrace :boolean

Details
boolean

mq :NexusHoratio.base.MessageQueue


name :string

Details
string

silenced :boolean

Details
boolean

Methods


<static> onConfig( callback )

Description

Attach a function for all config change events.

Parameters
Name Type Description
callback NexusHoratio.base.Logger~ConfigMutationHandler

Function that receives events.

Details

<static> offConfig( callback )

Description

Remove all instances of a function attached for config change events.

Parameters
Name Type Description
callback NexusHoratio.base.Logger~ConfigMutationHandler

Function that receives events.

Details

<static> config( loggerName ) → {NexusHoratio.base.Logger~Config}

Description

Get configuration of a specific Logger.

Parameters
Name Type Description
loggerName string

Logger configuration to get.

Returns

Current config for that Logger.

Details

<static> resetConfigs()

Description

Reset all configs to an empty state.

Details

<static> clear()

Description

Clear the console.

Details

log( msg, ...rest )

Description

Log a specific message.

Parameters
Name Type Attributes Description
msg string

Message to send to console.debug.

rest object <repeatable>

Arbitrary items to pass to console.debug.

Details

entered( group, ...rest )

Description

Indicate entered a specific group.

Parameters
Name Type Attributes Description
group string

Group that was entered.

rest object <repeatable>

Arbitrary items to pass to console.debug.

Details

leaving( group, ...rest )

Description

Indicate leaving a specific group.

Parameters
Name Type Attributes Description
group string

Group leaving.

rest object <repeatable>

Arbitrary items to pass to console.debug.

Details

starting( group, ...rest )

Description

Indicate starting a specific collapsed group.

Parameters
Name Type Attributes Description
group string

Group that is being started.

rest object <repeatable>

Arbitrary items to pass to console.debug.

Details

finished( group, ...rest )

Description

Indicate finished with a specific collapsed group.

Parameters
Name Type Attributes Description
group string

Group that was entered.

rest object <repeatable>

Arbitrary items to pass to console.debug.

Details

Type Definitions


ConfigMutationRecord

Properties
Name Type Attributes Description
logger string

Name of the affected Logger instance.

group string <nullable>

Name of a possibly affected group.

Details
object

ConfigMutationHandler( evt, record )

Parameters
Name Type Description
evt string

Type of mutation.

record NexusHoratio.base.Logger~ConfigMutationRecord

Details about the mutation.

Details
function