> For the complete documentation index, see [llms.txt](https://docs.medable.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.medable.com/cortex-api/decorators/runtime-1/log.md).

# Log

{% tabs %}
{% tab title="Logs Class Methods" %}

```javascript
const { log } = require('decorators')

class Logged {

    @log({ traceResult: true, environment: 'development'})
    logMe() {
        return 'logged!'
    }

    @log({format: ({ className, methodName, lineNumber}) => `${className}.${methodName} @ ${lineNumber}` })
    logFormatted() {
    }

}

new Logged().logMe()
new Logged().logFormatted()

// $ mdctl tail --format=yaml
//
// timestamp: '2020-02-18T19:55:05.308Z'
// level: info
// message:
//   - className: Logged
//     methodName: logMe
//     lineNumber: 5
//     ms: 0.080908203125
//     result: logged!
// 
// timestamp: '2020-02-18T19:55:05.312Z'
// level: info
// message:
//   - Logged.logFormatted @ 10
```

{% endtab %}
{% endtabs %}

## @log(options)

*Arguments*

* `options` { Object } Options object.
  * `target` { String = *"console"* } `logger` logs to the developer log, `console` logs to the console stream, accessible

    using `mdctl tail` (see <https://www.npmjs.com/package/@medable/mdctl-cli>). Possible values (logger, console).
  * `level` { String = *"info"* } The log level to use. Possible values (logger: \['warn', 'error', 'info', 'debug', 'trace'],

    console: \['warn', 'error', 'info'] ).
  * `traceError` { Boolean = *false* } If true, logs errors thrown from the method.
  * `traceResult` { Boolean = *false* } If true, logs the method return value.
  * `roles` { String\[] | ObjectID\[] = *"\*"*} Limits logging to a list of roles&#x20;
  * `environment` { String = *"\*"* } Limits logging to an environment. Possible values (\*, production, development).
  * `format` { Function } A function to transform the log output. Takes a single argument (`function(log) { return log }`)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.medable.com/cortex-api/decorators/runtime-1/log.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
