Winston@3 Customize timestamp format

Chris Peng
1 min readJul 27, 2018

--

Trying to log errors with winston, here is how I created the logger

Very simple, it’s what the official document does. But the timestamp in the log file made no sense to me, since it’s ISO date.

'2018-07-27T06:48:08.696Z'

I read the document, it gives no hint of how to customize the date format. So I did the old-fashioned way, read the source code. The file is located at node_modules/logform/timestamp.js

So it either takes a {format: string}, or {format: function}, when passed a string, the string is delegated to fecha to format the date string; or winston calls the function which should return a string. It also supports alias, let’s have fun!

Sorry about the order of the files, I don’t know how to sort the files in Gist.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response