简体   繁体   English

离子2:ngx-loggly-logger

[英]Ionic 2: ngx-loggly-logger

I am using this to log in errors. 我正在使用它来登录错误。 In my app.components.ts : 在我的app.components.ts中:

this.logglyService.push({
          'logglyKey':'xxxxxx-xxxx-xxx-xxxx',
          'sendConsoleErrors' : true,
          'tag' : 'testing'
   });

And in the rest of my pages, I import the loggly service and call : 在其余页面中,我导入loggly服务并调用:

this.logglyService.push('Example of error ')

But the issue is, the only errors sent are the ones logged in app.components.ts, but not the other pages. 但是问题是,发送的唯一错误是在app.components.ts中记录的错误,而不是其他页面。

Am I supposed to include the key and tag on every page with my push? 我是否应该在每次推送时在每个页面上包含键和标签?

i made this by a service : 我通过服务做到了这一点:

in app.module.ts define your LogglyService as a provider then make new service provider and import your service to app.module.ts 在app.module.ts中,将LogglyService定义为提供程序,然后创建新的服务提供程序并将服务导入到app.module.ts

import { LogglyService } from 'ngx-loggly-logger';
import { MyNewService} from '../providers/MyNewService/MyNewService';
providers: [    
LogglyService,
MyNewService,
...]

then inside of your new service 然后在您的新服务中

import { LogglyService } from 'ngx-loggly-logger';
private loggyTracker = {
                        'logglyKey':'xxxxxx-xxxx-xxx-xxxx',
                        'sendConsoleErrors' : true,
                        'tag' : 'my-tag'
                       };

constructor(private _logglyService:LogglyService, public httpClient: HttpClient) {

}

loggyPush(){ //use this method every where you want in every page
    this._logglyService.push(this.loggyTracker);  //initiate  
    this._logglyService.push('Example of error ');
}
...

now you can import your service(MyNewService) in every where you want and call loggyPush() method. 现在,您可以在所需的任何位置导入服务(MyNewService)并调用loggyPush()方法。

you can also define logglyservice config (key/tag ...) inside of your app.component.ts 您还可以在app.component.ts内部定义logglyservice配置(键/标签...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM