Skip to content

Latest commit

 

History

History
178 lines (124 loc) · 3.24 KB

File metadata and controls

178 lines (124 loc) · 3.24 KB

Log

console.log()



Use CSS

// ---- EXAMPLE #1 ----
console.log('%cHello..', 'font-weight: bold; color: red')

// ---- EXAMPLE #2 ----
console.log('%cHello..%cNew Color here..', 'font-weight: bold; color: red', 'font-weight: bold; color: green')



console.time()

console.time("Timer")
for (let i = 0; i < 100000000; i++){
  // ..
}
console.timeEnd("Timer")



console.error()

console.error("You made a mistake");



console.warn()

console.warn("You made a mistake");



console.assert()

let x = 3
console.assert(x === 2, 'x is not 2..')



console.table()

// ---- EXAMPLE #1 - Array ----
console.table(["apples", "oranges", "bananas"]);


// ---- EXAMPLE #2 - Object ----
function Person(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}

var me = new Person("John", "Smith");
console.table(me);



console.trace()

function foo() {
  function bar() {
    console.trace();
  }
  bar();
}

foo();



Log every method call

	import { LogClass, Log } from 'class-logger'

@LogClass()
class Test {
  @Log()
  method1() {
    return 123
  }

  @Log()
  async methodAsync1() {
    // do something asynchronous
    return Symbol()
  }

  @Log()
  methodError() {
    throw new Error()
  }

  @Log()
  property1 = () => null

  @Log()
  static methodStatic1(arg1) {
    return {
      prop1: 'test',
    }
  }
}

// Logs to the console before the method call:
// 'Test.methodStatic1. Args: [42].'
Test.methodStatic1(42)
// Logs to the console after the method call:
// 'Test.methodStatic1 -> done. Args: [42]. Res: {"prop1":"test"}.'

// Logs to the console before the class' construction:
// 'Test.construct. Args: [].'
const test = new Test()

// Logs to the console before the method call:
// 'Test.method1. Args: [].'
test.method1()
// Logs to the console after the method call:
// 'Test.method1 -> done. Args: []. Res: 123.'

// Logs to the console before the method call:
// 'Test.methodAsync1. Args: [].'
test.methodAsync1()
// Logs to the console after the method call (after the promise is resolved):
// 'Test.methodAsync1 -> done. Args: []. Res: Symbol().'

// Logs to the console before the method call:
// 'Test.methodError. Args: [].'
test.methodError()
// Logs to the console after the method call:
// 'Test.methodError -> error. Args: []. Res: Error {"name":"Error","message":"","stack":"some stack trace"}.'

// Logs to the console before the method call:
// 'Test.property1. Args: [].'
test.property1()
// Logs to the console after the method call:
// 'Test.property1 -> done. Args: []. Res: null.'