新的日志格式

Former-commit-id: 7ae55705cd5cf9c92f1e0a88c0b1de6c7e487fab [formerly 7ae55705cd5cf9c92f1e0a88c0b1de6c7e487fab [formerly 7ae55705cd5cf9c92f1e0a88c0b1de6c7e487fab [formerly 7ae55705cd5cf9c92f1e0a88c0b1de6c7e487fab [formerly 4a31495f225f851d089fb4362edd0ac8358ca21c [formerly c8ae7cb50e9b9499812512b4172702752f57b544]]]]]
Former-commit-id: a93e32b805171cd5b9ac2f06e3d830f99a50e825
Former-commit-id: 93fe03aad8fa90cd42cec2d913c26162a8a3307b
Former-commit-id: 5b51ffc4ecb1b979dd2ef504a7f88b16f26b75cb [formerly 8863540da4ed06a0b4b9d5a4e575b8b536b3abaf]
Former-commit-id: dc756f8f5935b6d36e12a1384fcb4be834d37500
Former-commit-id: 4502fff0f4f42b1fc1e33996e118c98ceff85897
Former-commit-id: 42e563abacc02bc7fe11edabe0963007b57b717d
Former-commit-id: b01454379bb448756825f1aad43bb49efcab3fe2
Former-commit-id: 8c7cb3cb4b93fd67933bac039304a9651a366fae
This commit is contained in:
liyang
2019-03-19 20:41:01 +08:00
parent b07250cc40
commit 806079df8d
3 changed files with 36 additions and 37 deletions

View File

@@ -6,16 +6,9 @@ export default {
// 快速打印 log // 快速打印 log
Vue.prototype.$log = util.log Vue.prototype.$log = util.log
// 快速记录日志 // 快速记录日志
Vue.prototype.$logAdd = function (info, show = true) { Vue.prototype.$logAdd = function (data) {
// store 赋值 // store 赋值
store.dispatch('d2admin/log/add', { store.dispatch('d2admin/log/add', data)
type: 'log',
info
})
// 显示在控制台
if (show && process.env.NODE_ENV === 'development') {
util.log.default(info)
}
} }
} }
} }

View File

@@ -1,11 +1,16 @@
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { get, toString } from 'lodash' import { get } from 'lodash'
import util from '@/libs/util.js' import util from '@/libs/util.js'
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
// 错误日志 // 错误日志
// + 日志条目的属性
// - message 必须 日志信息
// - time 必须 日志记录时间
// - type 非必须 类型 success | warning | info | error
// - meta 非必须 其它携带信息
list: [] list: []
}, },
getters: { getters: {
@@ -32,17 +37,12 @@ export default {
* @param {Object} param instance {Object} vue 实例 * @param {Object} param instance {Object} vue 实例
* @param {Object} param info {String} 信息 * @param {Object} param info {String} 信息
*/ */
add ({ state, rootState }, { type, err, instance, info }) { add ({ rootState, commit }, { message, type, meta }) {
// store 赋值 commit('add', {
state.list.push(Object.assign({ message,
// 记录类型 "log" or "error" time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
type: 'log', type,
// 信息 meta: {
info: '',
// 错误对象
err: '',
// vue 实例
instance: '',
// 当前用户信息 // 当前用户信息
user: rootState.d2admin.user.info, user: rootState.d2admin.user.info,
// 当前用户的 uuid // 当前用户的 uuid
@@ -51,17 +51,21 @@ export default {
token: util.cookies.get('token'), token: util.cookies.get('token'),
// 当前地址 // 当前地址
url: get(window, 'location.href', ''), url: get(window, 'location.href', ''),
// 当前时间 // 用户设置
time: dayjs().format('YYYY-M-D HH:mm:ss') ...meta
}, { }
type, })
err,
instance,
info: toString(info)
}))
} }
}, },
mutations: { mutations: {
/**
* @description 添加日志
* @param {Object} state vuex state
* @param {Object} log data
*/
add (state, log) {
state.list.push(log)
},
/** /**
* @description 清空日志 * @description 清空日志
* @param {Object} state vuex state * @param {Object} state vuex state

View File

@@ -21,7 +21,9 @@ export default {
}, },
methods: { methods: {
handleAdd () { handleAdd () {
this.$logAdd(this.text) this.$logAdd({
message: this.text
})
} }
} }
} }