Sql server transport for pino
npm install @totalsoft/pino-mssqlserverThis package provides a pino transport for Microsoft Sql Server.
It supports batching multiple log events and writing them periodically to the database.
``javascript`
npm i @totalsoft/pino-mssqlserver
or
`javascript`
yarn add @totalsoft/pino-mssqlserver
`javascript
const pino = require("pino");
const connectionString =
'Server=myServerAddress,1333;Database=myDataBase; TrustServerCertificate=True;User Id=myUsername;Password=myPassword; MultipleActiveResultSets=true;'
const transport = pino.transport({
target: "@totalsoft/pino-mssqlserver",
options: {
serviceName: "MyService.Gql",
tableName: "__Logs",
connectionString
},
level: logDatabaseMinLevel
});
const logger = pino(transport);
`
`typescript
export interface MsSqlServerTransportOptions {
// A connection string in the Microsoft Sql Server format
connectionString: string
// The logs table name
tableName: string
// A name for the current service / application to partition the log table
serviceName: string
// The maximum number of log events in a batch that is written to the database (default 20)
batchLimit?: number
// Time interval in milliseconds at which log batches are written to the database (default 2000)
flushInterval?: number
}
`
The log table should have the following format:
`sql``
CREATE TABLE [dbo].__Logs NOT NULL,
[Message] nvarchar NULL,
[Level] nvarchar NULL,
[TimeStamp] [datetime] NULL,
[Exception] nvarchar NULL,
[LogEvent] nvarchar NULL,
[ServiceName] varchar NULL,
[TenantId] [uniqueidentifier] NULL,
[CorrelationId] [uniqueidentifier] NULL,
CONSTRAINT [PK___Logs] PRIMARY KEY CLUSTERED ([Id] ASC)
)