app-tracker 1.4.5 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +10 -1
- package/index.js +1 -1
- package/os-node.d.ts +4 -0
- package/os-node.js +9 -0
- package/package.json +4 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LogType } from './log';
|
|
2
2
|
export declare class AppLogger {
|
|
3
3
|
static sendLogsOnLocal: boolean;
|
|
4
|
+
private static consoleLogsOnLocal;
|
|
4
5
|
private static endpointUrl;
|
|
5
6
|
private static apiKey;
|
|
6
7
|
private static logs;
|
|
@@ -13,25 +14,33 @@ export declare class AppLogger {
|
|
|
13
14
|
private static sendLogsByTypesImmediately;
|
|
14
15
|
private static isNode;
|
|
15
16
|
private static os;
|
|
17
|
+
private static isRunningLocal;
|
|
16
18
|
static init(apiKey: string, config?: AppLoggerConfig): void;
|
|
17
19
|
static debug(message?: string, ...optionalParams: any[]): void;
|
|
18
20
|
static info(message?: string, ...optionalParams: any[]): void;
|
|
19
21
|
static log(message?: string, ...optionalParams: any[]): void;
|
|
20
22
|
static warn(message?: string, ...optionalParams: any[]): void;
|
|
21
23
|
static error(message?: string, ...optionalParams: any[]): void;
|
|
24
|
+
static critical(message?: string, ...optionalParams: any[]): void;
|
|
22
25
|
private static addLog;
|
|
23
26
|
private static logToConsole;
|
|
24
|
-
private static isRunningLocal;
|
|
25
27
|
private static sendLogsToServer;
|
|
26
28
|
private static checkLogType;
|
|
27
29
|
private static sendLogsToServerCore;
|
|
28
30
|
}
|
|
29
31
|
export declare class AppLoggerConfig {
|
|
30
32
|
sendLogsOnLocal?: boolean | undefined;
|
|
33
|
+
consoleLogsOnLocal?: boolean | undefined;
|
|
31
34
|
endpointUrl?: string | undefined;
|
|
32
35
|
maxSendTries?: number | undefined;
|
|
33
36
|
maxLogsCount?: number | undefined;
|
|
34
37
|
/** Defines which log types should be sent to the server */
|
|
35
38
|
logLevel?: LogType[] | undefined;
|
|
36
39
|
sendLogsByTypesImmediately?: LogType[] | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Please pass:
|
|
42
|
+
* Web -> navigator.userAgent,
|
|
43
|
+
* Node -> os (from require('os'))
|
|
44
|
+
*/
|
|
45
|
+
userAgentOrOs: any;
|
|
37
46
|
}
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))((function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){var value;result.done?resolve(result.value):(value=result.value,value instanceof P?value:new P((function(resolve){resolve(value)}))).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0});const log_1=require("./log");class AppLogger{static init(apiKey,config){this.apiKey=apiKey,config&&(config.endpointUrl&&(this.endpointUrl=config.endpointUrl),config.maxLogsCount&&(this.maxLogsCount=config.maxLogsCount),config.maxSendTries&&(this.maxSendTries=config.maxSendTries),config.sendLogsOnLocal&&(this.sendLogsOnLocal=config.sendLogsOnLocal),config.logLevel&&(this.logLevel=config.logLevel),config.sendLogsByTypesImmediately&&(this.sendLogsByTypesImmediately=config.sendLogsByTypesImmediately)),this.isNode="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),this.isNode?(this.os=
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))((function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){var value;result.done?resolve(result.value):(value=result.value,value instanceof P?value:new P((function(resolve){resolve(value)}))).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0});const log_1=require("./log"),cross_fetch_1=require("cross-fetch");class AppLogger{static init(apiKey,config){var _a,_b;this.apiKey=apiKey,config&&(config.endpointUrl&&(this.endpointUrl=config.endpointUrl),config.maxLogsCount&&(this.maxLogsCount=config.maxLogsCount),config.maxSendTries&&(this.maxSendTries=config.maxSendTries),config.sendLogsOnLocal&&(this.sendLogsOnLocal=config.sendLogsOnLocal),config.consoleLogsOnLocal&&(this.consoleLogsOnLocal=config.consoleLogsOnLocal),config.logLevel&&(this.logLevel=config.logLevel),config.sendLogsByTypesImmediately&&(this.sendLogsByTypesImmediately=config.sendLogsByTypesImmediately)),this.isNode="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),this.isNode?(this.os=null===(_b=config)||void 0===_b?void 0:_b.userAgentOrOs,this.userAgent=JSON.stringify(this.os)):this.userAgent=null===(_a=config)||void 0===_a?void 0:_a.userAgentOrOs,this.isRunningLocal=this.isNode?this.os.hostname().indexOf("local")>-1:window.location.href.indexOf("localhost")>-1,""==apiKey||this.isNode||window.addEventListener("beforeunload",(e=>{if(e.preventDefault(),e.returnValue="",!this.isSending){const logsToSend=this.logs;this.isSending=!0,this.logs=[],AppLogger.sendLogsToServerCore(logsToSend)}}))}static debug(message,...optionalParams){AppLogger.addLog(log_1.LogType.debug,message,optionalParams)}static info(message,...optionalParams){AppLogger.addLog(log_1.LogType.info,message,optionalParams)}static log(message,...optionalParams){AppLogger.addLog(log_1.LogType.log,message,optionalParams)}static warn(message,...optionalParams){AppLogger.addLog(log_1.LogType.warn,message,optionalParams)}static error(message,...optionalParams){AppLogger.addLog(log_1.LogType.error,message,optionalParams)}static critical(message,...optionalParams){AppLogger.addLog(log_1.LogType.critical,message,optionalParams)}static addLog(type,message,optionalParams){this.checkLogType(type)?this.isRunningLocal&&!this.sendLogsOnLocal?AppLogger.logToConsole(type,message,optionalParams):AppLogger.sendLogsToServer(type,message,optionalParams):AppLogger.logToConsole(type,message,optionalParams)}static logToConsole(type,message,optionalParams){if(this.consoleLogsOnLocal)switch(type){case log_1.LogType.debug:console.debug(message,optionalParams);break;case log_1.LogType.critical:case log_1.LogType.error:console.error(message,optionalParams);break;case log_1.LogType.info:console.info(message,optionalParams);break;case log_1.LogType.log:console.log(message,optionalParams);break;case log_1.LogType.warn:console.warn(message,optionalParams);break;default:console.warn("Unkown LogType: ",type)}}static sendLogsToServer(type,message,...optionalParams){var _a;const log={logType:type,message:message,optionalParams:[],createdAt:new Date};if(optionalParams.forEach((op=>op.forEach((o=>log.optionalParams.push(o))))),this.logs.push(log),this.logs.length>=this.maxLogsCount&&!this.isSending||null!=((null===(_a=this.sendLogsByTypesImmediately)||void 0===_a?void 0:_a.find((l=>l==type)))||type==log_1.LogType.critical)&&!this.isSending){const logsToSend=this.logs;this.logs=[],this.isSending=!0,AppLogger.sendLogsToServerCore(logsToSend)}}static checkLogType(type){return null!=this.logLevel.find((l=>l===type))||type===log_1.LogType.critical}static sendLogsToServerCore(logsToSend){return __awaiter(this,void 0,void 0,(function*(){if(this.sendTries<this.maxSendTries)try{const last=this.endpointUrl.charAt(this.endpointUrl.length-1);yield cross_fetch_1.default(`${this.endpointUrl}${"/"===last?"logs/createLog":"/logs/createLog"}`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-Auth-Key":this.apiKey},body:JSON.stringify({logs:logsToSend,userAgent:this.userAgent},((key,value)=>{if(value instanceof Error){let error={};return Object.getOwnPropertyNames(value).forEach((function(key){error[key]=value[key]})),error}return value}))});logsToSend=[],this.isSending=!1}catch(error){console.error(`AppLogger: Could not send Logs to Server try ${this.sendTries}`,error),this.sendTries++,setTimeout((()=>{AppLogger.sendLogsToServerCore(logsToSend)}),1e4)}else this.sendTries=0,this.isSending=!1,console.error("AppLogger: Could not send Logs to Server finally")}))}}exports.AppLogger=AppLogger,AppLogger.sendLogsOnLocal=!1,AppLogger.consoleLogsOnLocal=!1,AppLogger.endpointUrl="https://api-app-tracker.azurewebsites.net/",AppLogger.apiKey="",AppLogger.logs=[],AppLogger.sendTries=0,AppLogger.maxSendTries=5,AppLogger.isSending=!1,AppLogger.maxLogsCount=10,AppLogger.logLevel=[log_1.LogType.error],AppLogger.sendLogsByTypesImmediately=[log_1.LogType.error],AppLogger.isNode=!1;class AppLoggerConfig{constructor(){this.maxLogsCount=5,this.sendLogsByTypesImmediately=[log_1.LogType.error]}}exports.AppLoggerConfig=AppLoggerConfig;
|
package/os-node.d.ts
ADDED
package/os-node.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "app-tracker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "App Tracker for Web-Applications",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,5 +19,8 @@
|
|
|
19
19
|
"tslint": "^5.20.1",
|
|
20
20
|
"tslint-config-prettier": "^1.18.0",
|
|
21
21
|
"typescript": "^3.7.3"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"cross-fetch": "^3.1.5"
|
|
22
25
|
}
|
|
23
26
|
}
|