//Include module
var base = require("../lib/index.js");

/**
 * NOTE:
 * All resource: Logger, Redis, Cassandra, Elastic, Mailer, Metrics has same logic
 */

/**
 * To use logger in your project is pretty simple just call base.logger()
 * Module will ensure a stable logger with configuration established
 * in default config "./options.json (logger)" or specified by you using base.setDefaultOptions()
 * in any point before this (see: templates/express)
 */
base.logger();

/**
 * Also you can specify setting just for global logger (base.logger()), without afecting base.logger.newInstance(),
 * using base.logger.configurate().
 * 
 * !!! Atention !!!
 * It is recomended to specify all configuration at begin of project using base.setDefaultOptions().
 * If you have need to specify different setting for general(global) logger use base.logger.configurate() BEFORE any used base.logger()
 * If you use after base.logger() it will proper distroy previous logger and create a new one with the new configuration
 * 
 * Default setting are:
 */

base.logger.configurate({
    "logLevel": 0,
    "debugLogging": true,
    "logFolder": "../logs",
    "rotatingSize": "10M",
    "errorFile": "errors.log",
    "outputFile": "output.log"
});

/**
 * For a well configuration module put at your dispozition a list with posible logLevel
 */
enum LOG_LEVEL {
    INFO,
    WARNING,
    ERROR,
    DEBUG,
    DEBUG_VERBOSE,
    QUERIES,
    EXTERNAL_API,
    INTERNAL_API
}
/**
 * To access an item from this list you need base.LOG_LEVEL.
 * Can also concatenate multiple elements from list and then set like "logLevel"
 */
base.LOG_LEVEL.INFO;

/**
 * Simple use case
 */
base.logger().log("message", base.LOG_LEVEL.WARNING);

/**
 * !!! ATENTION !!!
 * In base.logger().log() CAN'T use concatenated logLevel just simple like in exemple
 */


/**
 * You alo can create how many loggers you want asociating with an unique tag
 * To do that use base.logger.newInstance(config, tag);
 * Also in this function you can specify any diferent config from the default one
 * 
 * For exemple: if new conection is identical with configuration from default (setted by you with base.setDefaultOptions())
 * but with different logLevel can do like this:
 */
base.elastic.newInstance({
    "logLevel": (base.LOG_LEVEL.INFO | base.LOG_LEVEL.WARNING | base.LOG_LEVEL.ERROR | base.LOG_LEVEL.DEBUG),
}, "unique_tag");


/**
 * If the tag is not unique the old one associated with that tag will be closed and replaced with new one
 * Tags are very important for identify a specific logger, if tag is invalid, do not exist anymore any logger associated
 * with that tag, "null" will be returned by function base.logger(tag).
 * 
 * To get an logger by tag use base.logger(tag);
 */
base.logger("unique_tag");

/**
 * !!! ATENTION !!!
 * Tag "global" is reserved for the global logger
 * So base.logger("global") are equivalent with  base.logger(), both use same logger
 */

 /**
 * Simple use case
 */
base.logger("unique_tag").execute("query", {}, {}, function(error, response){});

/**
 * If you do not have any more need by a logger, you can delete it using base.logger.deleteInstance("tag");
 * This function will proper distroy and delete logger, if you try to use it after deletion using base.logger("tag"),
 * function will return "null"
 */
base.logger.deleteInstance("unique_tag");


/**
 * You can also delete global logger using base.logger.deleteInstance("global") or better base.logger.deleteInstance()
 * Deleting the global logger is allowed
 */
base.logger.deleteInstance();


/**
 * !!! ATENTION !!!
 * Deleting the global logger is temporar, until you start using again
 * So if you use base.logger() after deletion will be created a new logger based on your configuration
 * Behavior is same as your first call of base.logger()
 * 
 * It will keep remaind also base.logger.configurate(config);
 * So you dont need to recall base.logger.configurate(config) if you want an identical logger
 * Otherwise you will need to call base.logger.configurate(config) to change "global" logger configuration
 * or base.setDefaultOptions() if you want to affect all future loggers not just the "global" one also 
 * any future base.logger.newInstance(config, "tag")
 */

 /**
  * !!! Keep in mind !!!
  * If you want to change "global" you dont need to delete "global" logger use base.logger.deleteInstance();
  * Then change config using base.logger.configurate(config) and then start using new logger
  *
  * Any time you call base.logger.configurate(config) will delete old logger and when start using it will create a new one
  * using the new configuration.
  *
  * Changing "global" logger is enough calling base.logger.configurate(config)
  * Also if you want to change a specific conection is enought to overwrite it base.logger.newInstance(config, "old_tag")
  * using same tag. base.logger.newInstance(config, "old_tag"), will ensure will close old logger after this will create a new one
  */