Skip to content

Instantly share code, notes, and snippets.

@hawkerboy7
Last active January 4, 2018 16:00
Show Gist options
  • Save hawkerboy7/507aacc7a19ecd7f54b9f241793e1cdf to your computer and use it in GitHub Desktop.
Save hawkerboy7/507aacc7a19ecd7f54b9f241793e1cdf to your computer and use it in GitHub Desktop.

Global logger

The global logger makes it easier to log messages using GSLog.

Usage

// Initialize the logger
var log = new [Prefix]_LOG(name);

// Supported: All log methods
log.debug("debug");
log.info("info");
log.notice("notice");
log.warn("warn");
log.error("error");

// Supported: Multiple arguments
log.info("arg1", "arg2", "arg3", "arg4");

// Supported: All variables are logged as clear strings
log.info(0);
log.info(1.1);
log.info("string");
log.info([1, "23", ["a", "b", "c"]]);
log.info({a: 1,b: 2,c: "abc"});

name [string] The name of the script you are working in. This name will be added to the log message.
name [string] The name of the sys_propery you need to create to enable/disable logging at a specific level.

note: You can pass an array and an object to the logger and it will log them correctly. (an object not like [object Object] and array not like a comma seperated string)

Sys Property

You need to create a true|false sys_property with name log.#{name} and value true to be able to see the debug, info and notice messages. Debug, info and notice messages will not be logged if the sys_property value is set to false or if the sys_proprty is not defined.

Example

var log = new [Prefix]_LOG("testScriptInclude");

The code above would require a sys_property with name log.testScriptInclude to be able to show debug, info and notice messages.

Log levels

Check the GSLog for more info about log levels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment