Skip to content

Commit

Permalink
fix: #10
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingZhang committed Feb 7, 2024
1 parent 29a25dc commit 99984a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For Deno usage refer to [deno-logger doc](https://deno.land/x/logger)
### console logger

```js
import Logger from "https://deno.land/x/[email protected].3/logger.ts";
import Logger from "https://deno.land/x/[email protected].5/logger.ts";

const logger = new Logger();

Expand All @@ -22,7 +22,7 @@ logger.error("i am from consoleLogger", new Error("test"));
### file and console logger

```js
import Logger from "https://deno.land/x/[email protected].3/logger.ts";
import Logger from "https://deno.land/x/[email protected].5/logger.ts";

const logger = new Logger();

Expand All @@ -42,7 +42,7 @@ logger.error("i am from fileLogger", new Error("test"));
### file logger only

```js
import Logger from "https://deno.land/x/[email protected].3/logger.ts";
import Logger from "https://deno.land/x/[email protected].5/logger.ts";

const logger = new Logger();
await logger.initFileLogger("../log");
Expand All @@ -68,7 +68,7 @@ interface fileLoggerOptions {
example

```js
import Logger from "https://deno.land/x/[email protected].3/logger.ts";
import Logger from "https://deno.land/x/[email protected].5/logger.ts";
const logger = new Logger();

// cut by day
Expand Down Expand Up @@ -158,7 +158,7 @@ await logger.initFileLogger("../log", {
## disableConsole and enableConsole

```js
import Logger from "https://deno.land/x/[email protected].3/logger.ts";
import Logger from "https://deno.land/x/[email protected].5/logger.ts";

const logger = new Logger();

Expand All @@ -175,7 +175,7 @@ logger.info("console enabled, you can see me");
## disableFile and enableFile

```js
import Logger from "https://deno.land/x/[email protected].3/logger.ts";
import Logger from "https://deno.land/x/[email protected].5/logger.ts";

const logger = new Logger();
await logger.initFileLogger("../log");
Expand All @@ -202,7 +202,7 @@ example:
3. fileLogger, consoleLogger => disable => enable => fileLogger, consoleLogger

```js
import Logger from "https://deno.land/x/[email protected].3/logger.ts";
import Logger from "https://deno.land/x/[email protected].5/logger.ts";

const logger = new Logger();
await logger.initFileLogger("../log");
Expand Down
20 changes: 10 additions & 10 deletions logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { fileLoggerOptions, LoggerWriteOptions } from "./interface.ts";
import Types from "./types.ts";
const { inspect } = Deno;

const noop = () => void {};
const noop = async () => {};

export default class Logger {
private stdout = stdout;
Expand All @@ -35,48 +35,48 @@ export default class Logger {
return this.encoder.encode(stripColor(msg) + eol);
}

info(...args: unknown[]): void {
async info(...args: unknown[]): Promise<void> {
args = [this.getInfo(), ...args];
this.stdout(...args);
if (this.dir) {
this.write({
await this.write({
dir: this.dir,
type: Types.INFO,
args,
});
}
}

warn(...args: unknown[]): void {
async warn(...args: unknown[]): Promise<void> {
args = [this.getWarn(), ...args];
this.stdout(...args);
if (this.dir) {
this.write({
await this.write({
dir: this.dir,
type: Types.WARN,
args,
});
}
}

error(...args: unknown[]): void {
async error(...args: unknown[]): Promise<void> {
args = [this.getError(), ...args];
this.stdout(...args);
if (this.dir) {
this.write({
await this.write({
dir: this.dir,
type: Types.ERROR,
args,
});
}
}

private write({ dir, type, args }: LoggerWriteOptions): void {
private write({ dir, type, args }: LoggerWriteOptions): Promise<void> {
const date = this.getDate();
const filename = this.rotate === true ? `${date}_${type}` : type;
const path = `${dir}/${filename}.log`;
const msg = this.format(...args);
this.writer!.write({ path, msg, type });
return this.writer!.write({ path, msg, type });
}

async initFileLogger(
Expand All @@ -87,7 +87,7 @@ export default class Logger {
if (!exist) {
stdout(`${this.getWarn()} Log folder does not exist`);
try {
await Deno.mkdirSync(dir, { recursive: true });
Deno.mkdirSync(dir, { recursive: true });
stdout(`${this.getInfo()} Log folder create success`);
} catch (error) {
stdout(`${this.getError()} Log folder create failed: ` + error);
Expand Down

0 comments on commit 99984a2

Please sign in to comment.