# sz-log

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

Latest version **1.4.5** (published 2023-06-06) · MIT  license · 0 weekly downloads

## Install

```sh
npm install sz-log
pnpm add sz-log
yarn add sz-log
bun add sz-log
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.5 |
| Published | 2023-06-06 |
| First published | 2022-03-15 |
| Weekly downloads | 0 |
| License | MIT  |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 82.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 鲁举佩 |
| Maintainers | ljp100862 |

## Links

- npm: https://www.npmjs.com/package/sz-log
- npm.io page: https://npm.io/package/sz-log

## Recent versions

- 1.4.5 (latest) — 2023-06-06
- 1.4.4 — 2023-06-05
- 1.4.3 — 2023-05-19
- 1.4.2 — 2023-04-27
- 1.4.1 — 2023-04-27
- 1.4.0 — 2023-04-27
- 1.3.0 — 2023-04-26
- 1.2.0 — 2023-04-11
- 1.1.0 — 2023-04-11
- 1.0.7 — 2022-12-22
- 1.0.6 — 2022-12-22
- 1.0.5 — 2022-11-30
- 1.0.4 — 2022-06-02
- 1.0.3 — 2022-05-16
- 1.0.2 — 2022-03-18
- … 2 more at https://npm.io/package/sz-log/versions

## README

# sz-log

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

## 安装

```shell
yarn add sz-log
```

```shell
npm install sz-log --save
```

## 起步

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

> 例：React 应用中

index.tsx

```Typescript
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

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

logs.init();

createApp(App).mount('#app')
```

2. 使用

> 例：在 React 项目中

```Typescript
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 项目中

```Typescript
<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`

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

---

| Param | Type    | Description |
| ----- | ------- | ----------- |
| opts  | Options | 初始化参数  |

### `logs.record(type, msg) => void`

---

| Param | Type                        | Description |
| ----- | --------------------------- | ----------- |
| type  | `'error' | 'warn' | 'info'` | 日志类型    |
| msg   | `string`                    | 日志信息    |

### `logs.error(msg) => void`

---

| Param | Type     | Description |
| ----- | -------- | ----------- |
| msg   | `string` | 日志信息    |

### `logs.warn(msg) => void`

---

| Param | Type     | Description |
| ----- | -------- | ----------- |
| msg   | `string` | 日志信息    |

### `logs.info(msg) => void`

---

| Param | Type     | Description |
| ----- | -------- | ----------- |
| msg   | `string` | 日志信息    |

---
_Source: https://npm.io/package/sz-log · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
