# JavaScript

Source: https://docs.interop.io/desktop/capabilities/logging/javascript/index.html

## Overview

The Logger API is accessible via the [`io.logger`](https://docs.interop.io/desktop/reference/javascript/logger/api/index.md) object.

## Sub-Loggers

Logger instances have a [`subLogger()`](https://docs.interop.io/desktop/reference/javascript/logger/api/index.md#API-subLogger) method that creates a new sub-logger of the current logger. The name of each logger instance is a dot-delimited string containing all names of the loggers constituting a hierarchy line from the base logger (the app name) down to the current logger. This allows an effective and intuitive logging structure which can be easily adjusted to the component hierarchy in your app. For instance, a structure like `app-name.main-component.sub-component` gives you a clear idea from where the respective log entry originates and helps you find the necessary information much faster in a log file that may (and usually does) contain thousands of entries.

To use a logger in your interop-enabled apps, create a logger instance with the `subLogger()` method and assign the logger a name:

```javascript
const logger = io.logger.subLogger("main-component");
```

## Log Levels

To set the logging level at which to publish log entries to the file, use the [`publishLevel()`](https://docs.interop.io/desktop/reference/javascript/logger/api/index.md#API-publishLevel) method of the logger instance:

```javascript
logger.publishLevel("info");
```

Everything at and above the specified logging level will be logged, all else will be skipped. The available logging levels are `"trace"`, `"debug"`, `"info"`, `"warn"` and `"error"`.

## Log Messages

To log messages, either use the [`log()`](https://docs.interop.io/desktop/reference/javascript/logger/api/index.md#API-log) method of the logger instance, or the respective logging level methods - [`error()`](https://docs.interop.io/desktop/reference/javascript/logger/api/index.md#API-error), [`trace()`](https://docs.interop.io/desktop/reference/javascript/logger/api/index.md#API-trace), and more:

```javascript
// The `log()` method accepts the message and the logging level as arguments.
logger.log("Couldn't load component!", "error");

// Each logging level method accepts only a message as an argument.
logger.error("Couldn't load component!");
```

## API Reference

For a complete list of the available Logger API methods and properties, see the [Logger API reference documentation](https://docs.interop.io/desktop/reference/javascript/logger/api/index.md).
