Skip to content

Commit

Permalink
docs(core): Add documentation on creating custom logger
Browse files Browse the repository at this point in the history
Relates to #86
  • Loading branch information
michaelbromley committed Apr 17, 2019
1 parent 5966bec commit 06e5997
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/core/src/config/logger/vendure-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,49 @@ const noopLogger: VendureLogger = {
* instance configured in the {@link VendureConfig}. By default, the {@link DefaultLogger} is used, which
* logs to the console.
*
* ## Implementing a custom logger
*
* A custom logger can be passed to the `logger` config option by creating a class which implements the
* {@link VendureLogger} interface. For example, here is how you might go about implementing a logger which
* logs to a file:
*
* @example
* ```ts
* import { VendureLogger } from '@vendure/core';
* import fs from 'fs';
*
* // A simple custom logger which writes all logs to a file.
* export class SimpleFileLogger implements VendureLogger {
* private logfile: fs.WriteStream;
*
* constructor(logfileLocation: string) {
* this.logfile = fs.createWriteStream(logfileLocation, { flags: 'w' });
* }
*
* error(message: string, context?: string) {
* this.logfile.write(`ERROR: [${context}] ${message}\n`);
* }
* warn(message: string, context?: string) {
* this.logfile.write(`WARN: [${context}] ${message}\n`);
* }
* info(message: string, context?: string) {
* this.logfile.write(`INFO: [${context}] ${message}\n`);
* }
* verbose(message: string, context?: string) {
* this.logfile.write(`VERBOSE: [${context}] ${message}\n`);
* }
* debug(message: string, context?: string) {
* this.logfile.write(`DEBUG: [${context}] ${message}\n`);
* }
* }
*
* // in the VendureConfig
* export const config = {
* // ...
* logger: new SimpleFileLogger('server.log'),
* }
* ```
*
* @docsCategory Logger
*/
export class Logger implements LoggerService {
Expand Down

0 comments on commit 06e5997

Please sign in to comment.