首页 > 其他分享 >[Utils] Create a logger helper

[Utils] Create a logger helper

时间:2023-02-05 01:11:05浏览次数:40  
标签:console functionName text Utils params Create logger x1b 0m

function getTimeNow() {
  const now = new Date().toLocaleTimeString(
    'en-US',
    { hour12: false }
  );

  return now;
}

function info(functionName: string, ...params: [string]) {
  if (process.env.NODE_ENV === 'test') {
    return;
  }

  console.info(`\x1b[36m[INFO: ${functionName}]\x1b[0m`, getTimeNow(), ...params);
}

function error(functionName: string, ...params: [string]) {
  if (process.env.NODE_ENV === 'test') {
    return;
  }
  console.error(`\x1b[31m[ERROR: ${functionName}]\x1b[0m`, getTimeNow(), ...params);
}

 

Here is an example of using ANSI escape codes in JavaScript to display text in different colors in a terminal:

console.log("\x1b[31m%s\x1b[0m", "This text is red");
console.log("\x1b[32m%s\x1b[0m", "This text is green");
console.log("\x1b[33m%s\x1b[0m", "This text is yellow");

In this example, the console.log function is used to display text in different colors in the terminal by using ANSI escape codes. The escape code "\x1b[31m" sets the text color to red, "\x1b[32m" sets the text color to green, and "\x1b[33m" sets the text color to yellow. The "\x1b[0m" code at the end of each line resets the text attributes back to the default values.

标签:console,functionName,text,Utils,params,Create,logger,x1b,0m
From: https://www.cnblogs.com/Answer1215/p/17092740.html

相关文章

  • CSharp: donet 6 create view with EF Core 6
     [Keyless]publicclassPersonOrderCount{publicstringName{get;set;}publicintCount{get;set;}}publicclassPerson{publicintPe......
  • Linux之LVM管理 pvcreate,vgcreate,lvcreate命令
    一、逻辑卷管理(LVM)概念逻辑卷和逻辑卷管理有助于更加轻松地管理磁盘空间。如果托管逻辑卷的文件系统需要更多空间可以将其卷组中的可用空间分配给逻辑卷,并且可以调整文件......
  • DateUtils日期工具类的封装
    DateUtils日期工具类的封装1.字符串转化为util.Date2.util.Date转化为sql.Date3.util.Date转化为字符串样式packagecom.qf.person;importjava.text.ParseExcepti......
  • react 中使用redux的createStore 创建公用变量
    import{createStore}from'redux'exportconststore=createStore(addTodo,0);functionaddTodo(state=0,{type,num=1}){switch(type){......
  • PostgreSQL Create Index Concurrently
     CREATE INDEX CONCURRENTLY idx_kx_kq_storeinandout_time_status   on  public.kx_kq_storeinandout  USING btree(signintime,platstatus); createUNIQ......
  • 开发用工具类2.0:无侵入式的树形状工具类TreeUtils
    packagecn.jow.util;importjava.util.*;importjava.util.function.Function;importjava.util.stream.Collectors;/***无侵入方式处理对象集合,树形状结构数......
  • QiniuUtils七牛云对象存储java-api
    <!--七牛云-对象存储-图片云盘服务--><dependency> <groupId>com.qiniu</groupId> <artifactId>qiniu-java-sdk</artifactId> <version>[7.7.0,7.7.99]</version></d......
  • SMSUtils阿里云短信验证码java-api
    <!--阿里云短信服务--><dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.5.16</version></dependency><depe......
  • 模拟DBUtils中的queryRunner.query()的反射机制的模拟
    本文主要是讲述对于DBUtils中的queryRunner.query(connection,sql,newBeanListHandler<>(Admin.class))的模拟代码结构: DBUtilsReflection类:/***将查询到的结果......
  • DBUtils的使用
    一.DBUtils的引出1、connection不能提前关闭当我们查出结果集resultSet的时候,就关闭了connection连接,这时resultSet就不能使用了示例代码如下:publicclassjdbcDBUti......