Index Reference

Constructor

This is the constructor interface:

constructor(app: string, options?: LoggerageOptions)

The first parameter is the app or logger name. The second parameter is optional, and is a LoggerageOptions object, which defines different options for logger (all properties of the options are optionals).

const { Loggerage, LoggerageLevel, LoggerageOptions } = require("loggerage");
const myStorage = require('./my-storage');

const options = new LoggerageOptions();
options.version = '1.0';
options.defaultLogLevel = LoggerageLevel.INFO;
options.storage = myStorage;
const logger = new Loggerage("MY-APP", options);

LoggerageOptions is really a plain object, then, out of 'typescript' scope, you can do this:

const logger = new Loggerage("MY-APP", {
    version: '1.0',
    defaultLogLevel: LoggerageLevel.INFO,
    storage: myStorage
});

.setStorage (Change storage)

Declaration:

.setStorage( storage: Storage ): Loggerage

We can indicate a different storage other than the default one. This new storage must implement the next interface:

// file: 'src/storage-interface.ts'

interface Storage {
  getItem(key:string, query?:Query): LoggerageObject[] | Promise<LoggerageObject[]>
  setItem(key:string, value:LoggerageObject): void | Promise<void>
  clear(): void | Promise<void>
}

// 'key' is the name of app or logger, indicated in constructor.
// 'query' is optional.

It's similar to localStorage, but not working with strings in the return of getItem and second parameter of setItem.

IMPORTANT: We recommend returning a promise when we are going to work with asynchronous methods of Loggerage, but not is required. The calls to storage methods, inside async methods of Loggerage, are wrapped by Promise.resolve always.

.getVersion

Declaration:

.getVersion( ): number|string

Returns actual version

.getApp

Declaration:

.getApp( ): string

Returns app or logger name given at the constructor

.setDefaultLogLevel

Declaration:

.setDefaultLogLevel( defaultLogLevel: LoggerageLevel ): Loggerage

Modifies log default level if we call .log() directly

.getDefaultLogLevel

Declaration:

.getDefaultLogLevel( ): string

Returns current default log level string, like INFO

.getDefaultLogLevelNumber

Declaration:

.getDefaultLogLevelNumber( ): number

Returns current default log level number, like 3 for INFO level

.setSilence

Declaration:

.setSilence( silence: boolean ): Loggerage

Set silence console logs.

.getSilence

Declaration:

.getSilence( ): boole

Get actual silence console logs.

.getLog

Declaration:

.getLog( ): LoggerageObject[]

Returns the actual log saved at storage in an LoggerageObject Array, like this:

// file: src/loggerage-object.ts

LoggerageObject[] = [{
    app: string,            // app or logger name
    version: number|string, // app or logger version
    timestamp: number,      // Created by Date.now()
    date : "string",        // Creation date in Date.toLocaleString() format
    level : "string",       // log level
    level_number : number,  // log level number
    message : "string"      // logged message
}]

.getLogAsync

Declaration:

.getLogAsync( callback: (error: Error, data?: LoggerageObject[]) => void ): void

Returns asynchronously the actual log saved at storage in an LoggerageObject Array, like the .getLog( ) method.

.clearLog

Declaration:

.clearLog( ): Loggerage

Delete all current log.

.clearLogAsync

Declaration:

.clearLogAsync( callback: (error: Error|void) => void ): void

Delete all current log asynchronously

.downloadFileLog

Declaration:

.downloadFileLog( type: string = "txt" ) : Loggerage

Download current log file. We can indicate filetype with "csv" or "txt" parameters for .csv or .txt files. CSV files are separated by ';' and TXT files are separated by tabs

Name file format is:

[ App name ]_[ Date.now() ]_log.[ type ]

Example: MY-APP_1462995577596_log.txt

INSERT LOG METHODS

.info

Declaration:

.info( message: string ): Loggerage

Logs a message with INFO level

.infoAsync

Declaration:

.infoAsync( message: string, callback: (error: Error|void) => void ): void

Logs a message with INFO level asynchronously

.debug

Declaration:

.debug( message: string ): Loggerage

Logs a message with DEBUG level

.debugAsync

Declaration:

.debugAsync( message: string, callback: (error: Error|void) => void ): void

Logs a message with DEBUG level asynchronously

.trace

Declaration:

.trace( message: string ): Loggerage

Logs a message with TRACE level

.traceAsync

Declaration:

.traceAsync( message: string, callback: (error: Error|void) => void ): void

Logs a message with TRACE level asynchronously

.success

Declaration:

.trace( message: string ): Loggerage

Logs a message with SUCCESS level

.successAsync

Declaration:

.successAsync( message: string, callback: (error: Error|void) => void ): void

Logs a message with SUCCESS level asynchronously

.warn

Declaration:

.warn( message: string ): Loggerage

Logs a message with WARN level

.warnAsync

Declaration:

.warnAsync( message: string, callback: (error: Error|void) => void ): void

Logs a message with WARN level asynchronously

.error

Declaration:

.error( message: string, stacktrace?:string ): Loggerage

Logs a message with ERROR level. Concats stacktrace to message if stacktrace exists

.errorAsync

Declaration:

.errorAsync( message: string, stacktrace:string, callback: (error: Error|void) => void ): void

Logs a message with ERROR level asynchronously. Concats stacktrace to message. stacktrace is required.

.failure

Declaration:

.failure( message: string, stacktrace?:string ): Loggerage

Logs a message with FAILURE level. Concats stacktrace to message if stacktrace exists

.failureAsync

Declaration:

.failureAsync( message: string, stacktrace:string, callback: (error: Error|void) => void ): void

Logs a message with FAILURE level. Concats stacktrace to message if stacktrace exists

.log

Declaration:

.log( logLevel: LoggerageLevel = defaultLogLevel, message: string, stacktrace?: string ): Loggerage

Logs a message with given level. Concats stacktrace to message if stacktrace exists

.logAsync

Declaration:

.logAsync( logLevel: LoggerageLevel = defaultLogLevel, message: string, stacktrace: string, callback: (error: Error|void) => void ): void

Logs a message with given level asynchronously. Concats stacktrace to message if stacktrace exists, which can be null.