# Logger

## Configuration

By default the logger is set to ignore debugging to keep your logs less clustered, however you can change how the logger works.

The following log levels are available to set:

```
None | Info | Warn | Error | Debug
```

**None** - this will completely disable the logger

**Info** - this will log all important information, include warnings and errors

**Warn** - this will log only warnings and errors

**Error** - this will only log errors

**Debug** - this is the highest logger level and will log everything including debugging

{% hint style="info" %}
By default, the log level is **Info** when no value is provided
{% endhint %}

## Log File

Optionally, you may also provide a file-name to log ALL content to, this is very useful for debugging! Simply provide a "file" parameter in the LoggerOptions.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { RCEManager, LogLevel } from "rce.js";

const rce = new RCEManager({
    logger: {
        level: LogLevel.Info,
        file: "rce.log"
    }
});
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const { default: RCEManager, LogLevel } = require("rce.js");

const rce = new RCEManager({
    logger: {
        level: LogLevel.Info,
        file: "rce.log"
    }
});
```

{% endtab %}
{% endtabs %}

## Custom Logger

{% hint style="info" %}
This will only work for **TypeScript**
{% endhint %}

For TypeScript users, there is a logger interface provided which can be used to create your own custom logger - see the below example.

Only the info, warn, error and debug methods are strictly required - beyond that, you can implement your own methods and styles too!

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { ILogger, LogLevel } from "rce.js";
import { inspect } from "util";

export default class MyCustomLogger implements ILogger {
    private level: LogLevel;
    
    public constructor(level: LogLevel) {
        this.level = level;
    }
    
    private format(content: any) {
        return typeof content === "string"
            ? content
            : inspect(content, { depth: 5 });
    }
    
    private has(level: LogLevel): boolean {
        return level >= this.level;
    }
    
    public debug(content: string) {
        if (!this.has(LogLevel.Debug)) return;
        
        console.log(`[DEBUG] ${this.format(content)}`);
    }
    
    public error(content: string) {
        if (!this.has(LogLevel.Error)) return;
        
        console.log(`[ERROR] ${this.format(content)}`);
    }
    
    public info(content: string) {
        if (!this.has(LogLevel.Info)) return;
        
        console.log(`[INFO] ${this.format(content)}`);
    }
    
    public warn(content: string) {
        if (!this.has(LogLevel.Warn)) return;
        
        console.log(`[WARN] ${this.format(content)}`);
    }
    
    // ...
}
```

{% endtab %}
{% endtabs %}

After creating your custom logger class, you can set rce.js to use it like below!

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { RCEManager, LogLevel } from "rce.js";
import MyCustomLogger from "./logger";

const rce = new RCEManager({
    logger: {
        instance: new MyCustomLogger(LogLevel.Info)
    }
});
```

{% endtab %}
{% endtabs %}
