All Projects → hg-pyun → Axios Logger

hg-pyun / Axios Logger

Licence: mit
Beautify Axios Logging Messages

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Axios Logger

Starter Lapis
Cutting edge starter kit
Stars: ✭ 72 (-13.25%)
Mutual labels:  axios
Loguru
Python logging made (stupidly) simple
Stars: ✭ 10,510 (+12562.65%)
Mutual labels:  logger
Vue H5 Pro
🚀 基于@vue/CLI3构建的移动端h5项目模板
Stars: ✭ 78 (-6.02%)
Mutual labels:  axios
Form Object
Form object to use with Vue components for sending data to a Laravel application using axios.
Stars: ✭ 73 (-12.05%)
Mutual labels:  axios
Putongoj Fe
The front end of the Putong Online Judge -- An online judge with nothing special
Stars: ✭ 74 (-10.84%)
Mutual labels:  axios
Vue element shopmanage
基于vue+element的商品后台管理
Stars: ✭ 75 (-9.64%)
Mutual labels:  axios
Android Filelogger
A general-purpose logging library with built-in support to save logs to file efficiently.
Stars: ✭ 70 (-15.66%)
Mutual labels:  logger
Laravel Console Logger
Logging and Notifications for Laravel Console Commands.
Stars: ✭ 79 (-4.82%)
Mutual labels:  logger
Logtofile
Android一个简单实用把Log日志打印到手机本地文件,可以自行取出来上传到服务器开源代码
Stars: ✭ 74 (-10.84%)
Mutual labels:  logger
Vue2 Multi Uploader
Drag and drop multiple file uploader with Vue.js v2 and Axios
Stars: ✭ 77 (-7.23%)
Mutual labels:  axios
Vue Admin Element
(Vue2 演示项目)物业后台管理系统 - ElementUI ( 基本结构已完成, 剩下的就是具体业务开发; 如有疑问请留言 )
Stars: ✭ 73 (-12.05%)
Mutual labels:  axios
Vue2 Admin
基于vue-element-admin、Vue2 权限、监控、管理系统(包含地图等嵌套)
Stars: ✭ 74 (-10.84%)
Mutual labels:  axios
Vue Cli3 Multipage
由vue-cli3搭建的多页面多路由初始化项目包,包含ESlint,Axios,vue-router,vuex,babel,以及自己封装的异步请求API接口。
Stars: ✭ 76 (-8.43%)
Mutual labels:  axios
Awesome Canbus
🚛 A curated list of awesome CAN bus tools, hardware and resources
Stars: ✭ 73 (-12.05%)
Mutual labels:  logger
Vue Study
vue-cli4 + vue2.6 + vuex + vue-router + axios + element-ui
Stars: ✭ 78 (-6.02%)
Mutual labels:  axios
Docker Vue
Frontend for DockerRails, built with Vue.js
Stars: ✭ 72 (-13.25%)
Mutual labels:  axios
Use Axios Well
axios请求超时,设置重新请求的完美解决方法
Stars: ✭ 74 (-10.84%)
Mutual labels:  axios
Coolog
A expandable and flexible log framework for iOS. iOS一个灵活、可扩展的日志组件。
Stars: ✭ 82 (-1.2%)
Mutual labels:  logger
Kikoeru Express
kikoeru 后端,不再维护,请到https://github.com/umonaca/kikoeru-express 获取更新
Stars: ✭ 79 (-4.82%)
Mutual labels:  axios
Kotlin Inline Logger
A logger facilitating lazily-evaluated log calls via Kotlin's inline classes & functions.
Stars: ✭ 77 (-7.23%)
Mutual labels:  logger

axios-logger

npm npm GitHub license CircleCI

Beautify Axios Logging Messages.

logo

When you send a request in nodejs, you need to show the log to the console. This library display the necessary information while communicating with the server.

Basically This package is working as Axios's interceptors.

sample

Install

$ npm install axios-logger --save-dev

How to use

You can use various loggers through the axios's interceptor API.

Logging Request

import axios from 'axios';
import * as AxiosLogger from 'axios-logger';

const instance = axios.create();
instance.interceptors.request.use(AxiosLogger.requestLogger);

If you want to use your own interceptor, you can compose(mixin) with requestLogger.

instance.interceptors.request.use((request) => {
    // write down your request intercept.
    return AxiosLogger.requestLogger(request);
});

Logging Response

import axios from 'axios';
import * as AxiosLogger from 'axios-logger';

const instance = axios.create();
instance.interceptors.response.use(AxiosLogger.responseLogger);

Also if you want to use your own interceptor, you can compose(mixin) with responseLogger.

instance.interceptors.response.use((response) => {
    // write down your response intercept.
    return AxiosLogger.responseLogger(response);
});

Error

You can inject errorLogger right after requestLogger or responseLogger.

import axios from 'axios';
import * as AxiosLogger from 'axios-logger';

const instance = axios.create();
instance.interceptors.request.use(AxiosLogger.requestLogger, AxiosLogger.errorLogger);
instance.interceptors.response.use(AxiosLogger.responseLogger, AxiosLogger.errorLogger);

Also if you want to use your own interceptor, you can compose(mixin) with errorLogger.

instance.interceptors.response.use(AxiosLogger.responseLogger, (err) => {
    // write down your error intercept.
    return AxiosLogger.errorLogger(err);
});

Configuration Settings

You can adjust several features as desired through configuration file. If you want to set config globally, using setGlobalConfig method.

setGlobalConfig({
    prefixText: 'your prefix',
    dateFormat: 'HH:MM:ss',
    status: false,
    headers: true,
    logger: someLogger.info.bind(this),
});

Or it can also be passed on as a second argument and applied locally. In this case, any property explicitly defined will override the global configuration.

instance.interceptors.request.use((request) => {
    // write down your request intercept.
    return AxiosLogger.requestLogger(request, {
        prefixText: 'your prefix',
        dateFormat: 'HH:MM:ss',
        status: false,
        headers: true,
        logger: someLogger.error.bind(this),
    });
});

Enable config list

Property Type Default Description
method boolean true Whether to include HTTP method or not.
url boolean true Whether to include the URL or not.
data boolean true Whether to include request/response data or not.
status boolean true Whether to include response statuses or not.
headers boolean false Whether to include HTTP headers or not.
prefixText string | false 'Axios' false => no prefix, otherwise, customize the prefix wanted.
dateFormat dateformat | false new Date().toISOString() false => no timestamp, otherwise, customize its format
logger function<string, any> console.log Allows users to customize the logger function to be used. e.g. Winston's logger.info could be leveraged, like this: logger.info.bind(this)

CONTRIBUTE

I always welcome Feedback and Pull Request :)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].