consola 教程

2019-09-23 16:17:13

你没看错,consola 和 console 只差一个字母,并且它们都是控制器日志输出的好帮手。console 在某些方面,使用有些局限性。consola 是一个功能更丰富,更漂亮的控制台日志输出控件。今天我们一起来学习它的

什么是 Consola ?

  • Easy to use 易于使用。

  • Fancy output with Fallback for Continuous Integration (CI) environments 具有连续集成(CI)环境的备用输出。

  • Global mockable stdout/stderr wrapper 全球mockable stdout/stderr包装。

  • Pluggable reporters  可插拔的插件。

  • Consistent Command Line Interface (CLI) experience 命令行接口(CLI)。

  • Scoped Loggers 有范围的记录日志。

安装 Consola

yarn 安装方法:

1
yarn add consola

npm 命令安装方法:

1
npm i consola

一些用法。

基本用法

1
2
3
4
5
6
7
const consola = require('consola')
// See types section for all available types
consola.start('Starting build')
consola.success('Built!')
consola.info('Reporter: Some info')
consola.error(new Error('Foo'))

图片效果如下:

Consola

输出的日志内容如下:

1
2
3
4
5
[2:17:17 PM] Starting build
[2:17:17 PM] [TEST] Log from test scope
[2:17:18 PM] Built!
[2:17:18 PM] Some info
[2:17:18 PM] Error: Foo

日志的作用域

日志的分组使用:

1
2
const logger = consola.withScope('test')
logger.info('Log from test scope'// [Test] Log from test scope

Reporter

根据不同的终端,默认情况下使用FancyReporter或BasicReporter。

  • BasicReporter

  • FancyReporter

  • JSONReporter

  • WinstonReporter

上面4个是 Consola 提供的4种可供选择的 Reporter。另外我们还可以自定义 Reporter。相关用法可以查看官方文档:https://github.com/nuxt/consola。更多 API 的用法也可以参考官方 demo 和文档。


  • 2020-04-21 15:14:20

    SpringBoot + Redis:基本配置及使用

    # Redis数据库索引(默认为0) spring.redis.database=0# Redis服务器地址 spring.redis.host=127.0.0.1# Redis服务器连接端口 spring.redis.port=6379# Redis服务器连接密码(默认为空) spring.redis.password=# 连接池最大连接数(使用负值表示没有限制) spring.redis.jedis.pool.max-active=20# 连接池最大阻塞等待时间(使用负值表示没有限制) spring.redis.jedis.pool.max-wait=-1# 连接池中的最大空闲连接 spring.redis.jedis.pool.max-idle=10# 连接池中的最小空闲连接 spring.redis.jedis.pool.min-idle=0# 连接超时时间(毫秒) spring.redis.timeout=1000

  • 2020-04-22 10:49:10

    css按钮特效大全

    打开这个连接,你会发现很多按钮动画脚本,基本这些动画就够大家用的了。

  • 2020-04-27 09:26:49

    transform与transition区别与详解

    对元素进行移动、缩放、转动、拉长或拉伸。 方法:translate(): 元素从其当前位置移动,根据给定的 left(x 坐标) 和 top(y 坐标) 位置参数 有两个div,它们的css样式如下,transition:过渡 元素从一种样式逐渐改变为另一种的效果 有一个div,它的css样式如下:

  • 2020-04-27 11:02:21

    CSS 气泡对话框

    点击上面地址,我们可以看到一个灵活的css气泡,拖动按钮,改变气泡效果。

  • 2020-04-27 16:59:23

    Docker部署nuxtjs

    将一下文件拷贝至服务器目录/app |名称|描述| |-|-| |.nuxt|编译后生成的目录,开发模式和发布模式通用,注意发布前使用npm run build 防止将dev目录发布| |static| 静态资源文件,通过/可直接访问| |package.json|npm 包管理配置文件| |nuxt.config.js|Nuxt.js 默认的配置涵盖了大部分使用情形,可通过 nuxt.config.js 来覆盖默认的配置。| |node_modules|依赖模块|