Skip to content
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

Added isoTimestamp option #4518

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ the framework.

Cannot be set to `false` along with a [`port`](#server.options.port) value.

#### <a name="server.options.isotimestamp" /> `server.options.isoTimestamp`

Default value: `false`.

If `true`, shows the log timestamp in ISO-8601 UTC format. If `false`, shows the log timestamp
in milliseconds since 1970-01-01.

#### <a name="server.options.cache" /> `server.options.cache`

Default value: `{ provider: { constructor: require('@hapi/catbox-memory'), options: { partition: 'hapi-cache' } } }`.
Expand Down
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ internals.server = Validate.object({
address: Validate.string().hostname(),
app: Validate.object().allow(null),
autoListen: Validate.boolean(),
isoTimestamp: Validate.boolean().default(false),
cache: Validate.allow(null), // Validated elsewhere
compression: Validate.object({
minBytes: Validate.number().min(1).integer().default(1024)
Expand Down
2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ exports = module.exports = internals.Core = class {
tags = [tags];
}

const timestamp = Date.now();
const timestamp = this.settings.isoTimestamp ? new Date(Date.now()).toISOString() : Date.now();
const field = data instanceof Error ? 'error' : 'data';

let event = { timestamp, tags, [field]: data, channel };
Expand Down
7 changes: 7 additions & 0 deletions lib/types/server/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export interface ServerOptions {
*/
autoListen?: boolean | undefined;

/**
* @default false.
* Used to control the log timestamp format. When false, shows the timestamp in millisceonds since 1970-01-01. When true, shows the timestamp in ISO-8601 format using UTC timezone.
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsisotimestamp)
*/
isoTimestamp?: boolean | undefined;

/**
* @default { engine: require('@hapi/catbox-memory' }.
* Sets up server-side caching providers. Every server includes a default cache for storing application state. By default, a simple memory-based cache is created which has limited capacity and
Expand Down
Loading