How about using the console on the main service, so we can configure and apply console.log conditionally:
myComponent.ts
export class myComponent implements OnInit { constructor( private config: GlobalService ) {} ngOnInit() { this.config.log('func name',{a:'aval'},'three'); } }
global.service.ts
@Injectable() export class GlobalService { constructor() { } this.prod = true; public log(one: any, two?: any, three?: any, four?: any) { if (!this.prod) { console.log('%c'+one, 'background:red;color:#fff', two, three, four); } } }
(Note: the first parameter should be a string in this example);
source share