mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
add open telemetry
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Device } from '@capacitor/device';
|
||||
import { SocketLog } from './worker.worker';
|
||||
import { FCM } from '@capacitor-community/fcm';
|
||||
import { ActionPerformed, PushNotificationSchema, PushNotifications, Token, } from '@capacitor/push-notifications';
|
||||
import { AlertController, Platform } from '@ionic/angular';
|
||||
import { AngularFireMessaging } from '@angular/fire/messaging';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CaptureLogService {
|
||||
|
||||
deviceName = ''
|
||||
|
||||
constructor(
|
||||
public socket: SocketLog,
|
||||
private platform: Platform,
|
||||
private afMessaging: AngularFireMessaging,
|
||||
) {
|
||||
|
||||
// this.interceptLogs()
|
||||
|
||||
Device.getInfo().then(e => {
|
||||
this.deviceName = e.name
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
interceptLogs() {
|
||||
(() => {
|
||||
const originalConsoleLog = console.log;
|
||||
const originalConsoleError = console.error;
|
||||
const originalConsoleWarn = console.warn;
|
||||
const originalConsoleInfo = console.info;
|
||||
|
||||
console.log = function(...args) {
|
||||
//sendLogToServer(args.join(' '));
|
||||
this.socket.sendMessage({
|
||||
type:'sendLog',
|
||||
payload: {
|
||||
logType: 'log',
|
||||
args
|
||||
}
|
||||
})
|
||||
originalConsoleLog.apply(console, args);
|
||||
};
|
||||
|
||||
console.error = function(...args) {
|
||||
// sendLogToServer('ERROR: ' + args.join(' '));
|
||||
|
||||
this.socket.sendMessage({
|
||||
type:'sendLog',
|
||||
payload: {
|
||||
logType: 'error',
|
||||
args
|
||||
}
|
||||
})
|
||||
originalConsoleError.apply(console, args);
|
||||
};
|
||||
|
||||
console.warn = function(...args) {
|
||||
this.socket.sendMessage({
|
||||
type:'sendLog',
|
||||
payload: {
|
||||
logType: 'warn',
|
||||
args
|
||||
}
|
||||
})
|
||||
originalConsoleWarn.apply(console, args);
|
||||
};
|
||||
|
||||
console.info = function(...args) {
|
||||
this.socket.sendMessage({
|
||||
type:'sendLog',
|
||||
payload: {
|
||||
logType: 'info',
|
||||
args
|
||||
}
|
||||
})
|
||||
originalConsoleInfo.apply(console, args);
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
|
||||
async getDeviceToken() {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (this.platform.is('mobile')) {
|
||||
if (this.platform.is('ios')) {
|
||||
FCM.getToken()
|
||||
.then(r => {
|
||||
resolve(r.token)
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
} else {
|
||||
|
||||
PushNotifications.addListener('registration',
|
||||
(token: Token) => {
|
||||
resolve(token.value)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
this.afMessaging.requestToken.subscribe(
|
||||
(token) => {
|
||||
resolve(token)
|
||||
},
|
||||
(error) => {
|
||||
console.error('Permission denied:', error);
|
||||
}
|
||||
);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user