背景
我们在开发时都很喜欢使用console.*来打印出日志信息以方便我们调试代码,但是在上线时肯定是需要去除所有的console;但是大多数情况下开发者都会忘记移除console输出,这会带来生产日志风险。
编写
- 新增一个日志组件:logger
ionic g provier logger
- 修改logger.ts的内容如下:
import {Injectable} from '@angular/core';
import {Constants} from "../Constants";
@Injectable()
export class Logger {
constructor() {
}
/**
* Logs messages or objects with the debug level.
* Works the same as console.log().
*/
public log(...objects: any[]) {
this.log_real(console.log, LogLevel.Debug, objects);
}
/**
* Logs messages or objects with the debug level.
* Works the same as console.debug().
*/
public debug(...objects: any[]) {
this.log_real(console.log, LogLevel.Debug, objects);
}
/**
* Logs messages or objects with the i