karma-runner / karma

Spectacular Test Runner for JavaScript
http://karma-runner.github.io
MIT License
11.95k stars 1.71k forks source link

logger.js ignores layout.pattern #2414

Open justmike opened 7 years ago

justmike commented 7 years ago

Expected behaviour

In karma/lib/logger.js, setup should use the layout.pattern string if it exists.

Actual behaviour

When layout.type === 'pattern', setup only uses one of the built-in constants:

    var pattern = colors ? constant.COLOR_PATTERN : constant.NO_COLOR_PATTERN

Environment Details

    loggers: [
        {
            type: 'console',
            layout: {
                type: 'pattern',
                pattern: '%[%d{ISO8601}:%p [%c]: %]%m'
            }
        }
    ]

Steps to reproduce the behaviour

  1. Supply a custom logger in karma.config.js as specified above.

    Comment

If this is indeed broken, I can submit a PR.

Further, I realize that fixing this to use the provided pattern will then ignore the colors boolean. This might be addressed by having layout.colorPattern and layout.noColorPattern which get assigned appropriately to layout.pattern. I can submit a PR for this as well.

Thanks.

MortenHoustonLudvigsen commented 6 years ago

I just ran into the same issue. Here is an example work around:

Create a custom layout, that is functionally identical to the pattern layout:

const log4js = require('log4js');
const layouts = require('log4js/lib/layouts');

log4js.addLayout('my-layout', function (config) {
    return layouts.patternLayout(config && config.pattern, config && config.tokens);
});

The configuration can now be written as:

loggers: [
    {
        type: 'console',
        layout: {
            type: 'my-layout',
            pattern: '%[%d{ISO8601}:%p [%c]: %]%m'
        }
    }
]