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

[core] Add server.logFormat configuration option #449

Merged
merged 1 commit into from
Jul 30, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/fresh-avocados-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trifid-core": minor
---

Introduce a `server.logFormat` configuration option, to either output JSON or pretty-formated logs.
1 change: 1 addition & 0 deletions packages/core/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ server:
listener:
port: 8080
logLevel: debug
logFormat: pretty

globals:
value: config
Expand Down
23 changes: 14 additions & 9 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import handler from './lib/config/handler.js'
import {
defaultHost,
defaultLogLevel,
defaultLogFormat,
defaultPort,
} from './lib/config/default.js'
import pluginsAssembler from './lib/plugins/assembler.js'
Expand Down Expand Up @@ -57,6 +58,9 @@ const trifid = async (config, additionalPlugins = {}) => {

const serverOptions = fullConfig?.server?.options || {}

// Template configuration
const template = fullConfig?.template || {}

// Dynamic server configuration
const portFromConfig = fullConfig?.server?.listener?.port
const port = (portFromConfig === 0 || portFromConfig === '0') ? 0 : (portFromConfig || defaultPort)
Expand All @@ -65,18 +69,19 @@ const trifid = async (config, additionalPlugins = {}) => {

// Logger configuration
const logLevel = fullConfig?.server?.logLevel || defaultLogLevel

// Template configuration
const template = fullConfig?.template || {}

// Custom logger instance
const logger = pino({
const logFormat = fullConfig?.server?.logFormat || defaultLogFormat
const loggerConfig = {
name: 'trifid-core',
level: logLevel,
transport: {
}
if (logFormat === 'pretty') {
loggerConfig.transport = {
target: 'pino-pretty',
},
})
}
}

// Custom logger instance
const logger = pino(loggerConfig)

const server = fastify({
logger: false,
Expand Down
1 change: 1 addition & 0 deletions packages/core/lib/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const maxDepth = 50
export const defaultPort = 8080
export const defaultHost = '0.0.0.0'
export const defaultLogLevel = 'info'
export const defaultLogFormat = 'pretty'
7 changes: 7 additions & 0 deletions packages/core/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
"silent"
]
},
"logFormat": {
"type": "string",
"enum": [
"json",
"pretty"
]
},
"options": {
"type": "object",
"additionalProperties": true
Expand Down
1 change: 1 addition & 0 deletions packages/core/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @property {string} [server.listener.host] The host to listen on.
* @property {number|string} [server.listener.port] The port to listen on.
* @property {"fatal"|"error"|"warn"|"info"|"debug"|"trace"|"silent"} [server.logLevel] The log level.
* @property {"pretty"|"json"} [server.logFormat] The log format.
* @property {Object.<string, any>} [server.options] Server options.
* @property {Object.<string, any>} [globals] Global settings.
* @property {Object.<string, any>} [template] Template settings.
Expand Down
1 change: 1 addition & 0 deletions packages/entity-renderer/examples/config/trifid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

server:
logLevel: debug
logFormat: pretty

globals:
datasetBaseUrl: http://localhost:3000/
Expand Down