Skip to content

Adding plugins to coffeescript (i.e. preprocessor for logging) #1466

Closed
@tauren

Description

@tauren

I would like to see coffeescript have a plugin system that would allow users to develop enhancements that can be inserted into the coffeescript compile process.

For instance, I scatter console.log output throughout my application, but there are times that I want to have loglevel features, such as console.debug or console.trace. To make this work cross-browser, I create my own logging functions. The problem is that console output shows the file name and line number of where console.log was called, not where my wrapper function is called. This makes it more time consuming to debug in a browser.

Furthermore, I want all of my logging code to be removed when in production mode. It seems to me that coffeescript would be an ideal place to handle custom logging features, and it could easily choose to include or exclude logging code in production mode. I would love to see coffeescript enhanced to allow users to build preprocessors that would be run on the code before the compiler is run.

Imagine a preprocessor that defines some custom functions. These functions would inline code in the output based on some condition. For instance, my preprocessor defines a logger object and adds some methods to it. This could be used with coffeescript like this:

logger.loglevel 'debug'
logger.info 'Info'
logger.debug 'Debug'
logger.trace 'Trace'

This would generate:

console.log('Info');
console.log('Debug');

Note that 'Trace' isn't output because the loglevel excludes it. The values of logger.loglevel could be kept simple, or could allow lots of levels: none, fatal, error, warn, info, debug, and trace.

The output would be dynamically included depending upon the function called and the current log level. It would be great if the command line compiler could somehow take parameters for preprocessors so that something like --loglevel none could be specified when generating production code.

It would be extremely nice if each file could have it's own loglevel scope. That way if I wanted to only see trace level logging in a certain module of my application, I wouldn't have to see the trace output from everything else.

Anyway, does this seem like a useful idea? Since coffeescript is already compiling code, why not plug into it for features like this? Could this be added without changing coffeescript core, or would it need to go into coffeescript core?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions