1.4.5 • Published 11 months ago

sz-log v1.4.5

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

sz-log

一个精简的日志记录 SDK,对 TS 友好。

安装

yarn add sz-log
npm install sz-log --save

起步

  1. 在入口文件中初始化 SDK

例:React 应用中

index.tsx

import React from 'react';
import App from './App';
import logs from 'sz-log';

logs.init();

ReactDOM.render(
 <React.StrictMode>
  <App />
  <Toaster />
 </React.StrictMode>,
 document.getElementById('root'),
);

例:在 Vue 项目中

main.ts

import { createApp } from 'vue'
import App from './App.vue'
import logs from 'sz-log';

logs.init();

createApp(App).mount('#app')
  1. 使用

例:在 React 项目中

import React, { useEffect } from 'react';
import logs from 'sz-log';

function App() {
 React.useEffect(() => {
   fetch('http://www.example.com').catch((e) => {
     logs.error(e.message);
   });
 }, []);

 return <div></div>;
}
export default App;

例:在 Vue 项目中

<script setup>
  import HelloWorld from './components/HelloWorld.vue'
  import logs from 'sz-log';
  fetch('https://www.example.com').catch((e) => logs.error(e.message));
</script>

<template>
  <img alt="Vue logo" src="./assets/logo.png" />
  <HelloWorld msg="Hello Vue 3 + Vite" />
</template>

API Reference

logs.init(opts: Options) => void

interface Options {
  enableConsole?: boolean;
  prefix?: string;
}

ParamTypeDescription
optsOptions初始化参数

logs.record(type, msg) => void


ParamTypeDescription
type'error' | 'warn' | 'info'日志类型
msgstring日志信息

logs.error(msg) => void


ParamTypeDescription
msgstring日志信息

logs.warn(msg) => void


ParamTypeDescription
msgstring日志信息

logs.info(msg) => void


ParamTypeDescription
msgstring日志信息
1.4.5

11 months ago

1.4.4

11 months ago

1.2.0

1 year ago

1.1.0

1 year ago

1.4.3

12 months ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago