New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for dynamic index names #23

wants to merge 1 commit into
base: master


None yet
3 participants
Copy link

koenpunt commented Feb 5, 2019

This allows for creating time based indices when using the library programmatically:

For example:

// custom-pino-elasticsearch.js
const pinoElasticSearch = require('pino-elasticsearch');
const pump = require('pump');
const pad = require('left-pad');

const padNumber = (num) => pad(num, 2, 0);

    index: () => {
      const now = new Date();
      // format index name as `pino-YYYY-MM-DD`
      return `pino-${now.getFullYear()}-${padNumber(
        now.getUTCMonth() + 1
      )}-${padNumber(now.getUTCDate() + 1)}`;
    host: process.env.ES_LOG_HOST || 'localhost',
    port: process.env.ES_LOG_POST || 9200,

I had no success with the tests, but the tests were already failing on the CI, so it might be better to get them fixed over there first?

add support for dynamic index names
this allows for creating time based indices

This comment has been minimized.

Copy link

mcollina commented Feb 5, 2019

Tests might be a bit flaky, but they are passing. I’d love to get a PR that makes them more robust.


This comment has been minimized.

Copy link

tdeo commented Feb 7, 2019

This PR (#22) was released which adds this support using the %{DATE} placeholder in your index name

@mcollina mcollina closed this Feb 7, 2019


This comment has been minimized.

Copy link

koenpunt commented Feb 7, 2019

Even though #22 was implemented, it doesn't give much flexibility; e.g. it's not possible to have monthly or weekly indices using just the %{DATE} replacement.

I must add that the need for this library supporting this has disappeared since I couldn't get it to work when running a node application in Docker on AWS ECS, but I can still imagine someone wanting to have more control in naming their indices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment