Skip to content

Commit

Permalink
Update project to work with angular 4 and angular-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Newman authored and Tgure committed Jun 29, 2020
1 parent 201b7a1 commit f65047f
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 68 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ Desktop.ini
# Mac
.DS_Store
**/.DS_Store

# Ngc generated files
**/*.ngfactory.ts
7 changes: 7 additions & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"generator-angular2-library": {
"promptValues": {
"gitRepositoryUrl": "https://github.com/Tgure/ngx-loggly-logger"
}
}
}
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Simple library to log to loggly in Angular

## Installation

Version 4.0 has only been tested with angular cli and angular 4, if it does not work for you try version 0.0.21

To install follow this procedure:

1. __npm install ngx-loggly-logger --save__
Expand All @@ -13,19 +15,20 @@ To install follow this procedure:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MyTestApp } from './my-test-app';
import { LogglyService } from 'ngx-loggly-logger';
import { NgxLogglyModule } from 'ngx-loggly-logger';

@NgModule({
providers: [ LogglyService ],
imports: [ BrowserModule ],
providers: [ ],
imports: [ BrowserModule, NgxLogglyModule ],
declarations: [ MyTestApp ],
bootstrap: [ MyTestApp ]
})
export class MyTestAppModule {}
```
3. Use the following in your components, etc.
```js
import {LogglyService} from 'ngx-loggly-logger';
import { LogglyService } from 'ngx-loggly-logger/dist/src/loggly.service';
constructor(private _logglyService:LogglyService) {
}
Expand Down
28 changes: 14 additions & 14 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {NgModule, ModuleWithProviders} from '@angular/core';
import {ModuleWithProviders, NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {HttpModule} from '@angular/http';
import {LogglyService} from './src/loggly.service';

export * from './src/loggly.service';

@NgModule({
imports: [
CommonModule
],
declarations: [],
exports: []
imports: [
CommonModule,
HttpModule
],
declarations: [],
exports: []
})
export class NgxLogglyModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: NgxLogglyModule,
providers: [LogglyService]
};
}
static forRoot(): ModuleWithProviders{
return {
ngModule: NgxLogglyModule,
providers: [LogglyService]
};
}
}
48 changes: 30 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "ngx-loggly-logger",
"version": "0.0.21",
"version": "4.0.0",
"scripts": {
"build": "ngc -p tsconfig.json",
"lint": "tslint src/**/*.ts",
"lint": "tslint --type-check --project tsconfig.json src/**/*.ts",
"test": "tsc && karma start",
"prepublish": "tsc",
"tsc": "tsc"
Expand All @@ -25,26 +25,38 @@
},
"main": "./dist/index.js",
"dependencies": {
"@angular/core": "~2.4.8",
"@angular/common": "~2.4.8",
"@angular/http": "~2.4.8",
"@angular/platform-browser": "~2.4.8",
"rxjs": "~5.1.1",
"zone.js": "~0.7.7",
"ng2-cookies": "~1.0.4"
"@angular/common": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/http": "^4.0.0",
"ng2-cookies": "^1.0.10"
},
"devDependencies": {
"@angular/compiler": "~2.4.8",
"@angular/compiler-cli": "~2.4.8",
"@angular/platform-server": "~2.4.8",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/compiler-cli": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"tslint": "~4.4.2",
"typescript": "~2.1.6",
"@types/es6-shim": "~0.31.32",
"@types/jasmine": "~2.5.43",
"@types/selenium-webdriver": "~2.53.39"
"core-js": "^2.4.1",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~5.1.0",
"rxjs": "^5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0",
"zone.js": "^0.8.4"
},
"engines": {
"node": ">=0.8.0"
"node": ">=6.0.0"
}
}
34 changes: 17 additions & 17 deletions src/loggly.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Injectable} from '@angular/core';
import {Http, Headers, RequestOptions, Response} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import {Http, Headers, RequestOptions, Response} from '@angular/http';
import {Cookie} from 'ng2-cookies';

@Injectable()
Expand All @@ -14,45 +14,45 @@ export class LogglyService {
private session_id: any;
private inputUrl: any;

constructor(private _http: Http) {
constructor(private _http: Http){
this.LOGGLY_INPUT_PREFIX = 'http' + ( ('https:' === document.location.protocol ? 's' : '') ) + '://';
this.LOGGLY_COLLECTOR_DOMAIN = 'logs-01.loggly.com';
this.LOGGLY_SESSION_KEY = 'logglytrackingsession';
this.LOGGLY_SESSION_KEY_LENGTH = this.LOGGLY_SESSION_KEY + 1;
this.LOGGLY_PROXY_DOMAIN = 'loggly';
}

uuid() {
uuid(){
// lifted from here -> http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c){
let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}

setKey(tracker: any, key: any) {
setKey(tracker: any, key: any){
tracker.key = key;
tracker.setSession();
this.setInputUrl(tracker);
}

setTag(tracker: any, tag: any) {
setTag(tracker: any, tag: any){
tracker.tag = tag;
}

setDomainProxy(tracker: any, useDomainProxy: any) {
setDomainProxy(tracker: any, useDomainProxy: any){
tracker.useDomainProxy = useDomainProxy;
// refresh inputUrl value
this.setInputUrl(tracker);
}

setSendConsoleError(tracker: any, sendConsoleErrors: any) {
setSendConsoleError(tracker: any, sendConsoleErrors: any){
tracker.sendConsoleErrors = sendConsoleErrors;

if (tracker.sendConsoleErrors === true) {
let _onerror = window.onerror;
// send console error messages to Loggly
window.onerror = function (msg, url, line, col) {
window.onerror = function (msg, url, line, col){
tracker.push({
category: 'BrowserJsException',
exception: {
Expand All @@ -70,7 +70,7 @@ export class LogglyService {
}
}

setInputUrl(tracker: any) {
setInputUrl(tracker: any){
if (tracker.useDomainProxy === true) {
tracker.inputUrl = this.LOGGLY_INPUT_PREFIX
+ window.location.host
Expand All @@ -90,7 +90,7 @@ export class LogglyService {
}
}

setSession(session_id: any) {
setSession(session_id: any){
if (session_id) {
this.session_id = session_id;
this.setCookie(this.session_id);
Expand All @@ -103,7 +103,7 @@ export class LogglyService {
}
}

push(data: any) {
push(data: any){
let type = typeof data;

if (!data || !(type === 'object' || type === 'string')) {
Expand Down Expand Up @@ -151,15 +151,15 @@ export class LogglyService {
}

self.track(data).subscribe(
(response: any) => {
(response: any) =>{
// Success
},
(error: any) => {
(error: any) =>{
console.error(error);
});
}

track(data: any) {
track(data: any){
// inject session id
data.sessionId = this.session_id;
let headers = new Headers({'Content-Type': 'text/plain'});
Expand All @@ -168,7 +168,7 @@ export class LogglyService {
.map(res => res);
}

readCookie(): any {
readCookie(): any{
let cookie = Cookie.get(this.LOGGLY_SESSION_KEY);
if (cookie) {
let i = cookie.indexOf(this.LOGGLY_SESSION_KEY);
Expand All @@ -184,7 +184,7 @@ export class LogglyService {
}
}

setCookie(value: any) {
setCookie(value: any){
Cookie.set(this.LOGGLY_SESSION_KEY, value);
}
}
11 changes: 7 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
"compilerOptions": {
"noImplicitAny": true,
"module": "commonjs",
"target": "ES5",
"target": "es5",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowUnusedLabels": false,
"noImplicitReturns": true,
"sourceMap": true,
"declaration": true,
"outDir": "./dist",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
},
"files": [
"index.ts"
],
"exclude": [
"node_modules",
"dist",
Expand Down
25 changes: 14 additions & 11 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"spaces"
],
"label-position": true,
"label-undefined": true,
"max-line-length": [
true,
140
Expand All @@ -28,7 +27,7 @@
"variables-before-functions"
],
"no-arg": true,
"no-bitwise": false,
"no-bitwise": true,
"no-console": [
true,
"debug",
Expand All @@ -39,7 +38,6 @@
],
"no-construct": true,
"no-debugger": true,
"no-duplicate-key": true,
"no-duplicate-variable": true,
"no-empty": false,
"no-eval": true,
Expand All @@ -49,9 +47,7 @@
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unused-expression": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"no-unreachable": true,
"no-unused-variable": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"object-literal-sort-keys": false,
Expand Down Expand Up @@ -93,11 +89,18 @@
"check-separator",
"check-type"
],

"directive-selector-name": [true, "camelCase"],
"component-selector-name": [true, "kebab-case"],
"directive-selector-type": [true, "attribute"],
"component-selector-type": [true, "element"],
"directive-selector": [
true,
"attribute",
"",
"camelCase"
],
"component-selector": [
true,
"element",
"",
"kebab-case"
],
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
Expand Down

0 comments on commit f65047f

Please sign in to comment.