winston#createLogger TypeScript Examples
The following examples show how to use
winston#createLogger.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: logging.ts From Assistive-Webdriver with MIT License | 6 votes |
export function createDefaultLogger(): Logger {
return createLogger({
format: format.combine(
format.timestamp(),
format.colorize(),
messageId(),
defaultFormatter
),
transports: [new transports.Console()]
});
}
Example #2
Source File: logger.ts From javascript-opensdk with Apache License 2.0 | 6 votes |
logger = createLogger({
transports: [
new transports.Console({
level: 'warn',
format: format.combine(
format((info) => {
const newInfo = info;
newInfo.level = info.level.toUpperCase().padEnd(7, ' ');
return newInfo;
})(),
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
format.colorize({ all: true }),
customFormat
),
}),
],
})
Example #3
Source File: logger-console.ts From loopback4-microservice-catalog with MIT License | 6 votes |
constructor() {
super();
const logFormat = format.combine(
format.uncolorize(),
format.timestamp(),
format.printf(
(log: LogEntry) => `[${log.timestamp}] ${log.level} :: ${log.message}`,
),
);
this.logger = createLogger({
transports: [new transports.Console()],
format: logFormat,
level:
process.env.LOG_LEVEL ??
LOGGER.LOG_LEVEL[LOGGER.LOG_LEVEL.ERROR].toLowerCase(),
});
}
Example #4
Source File: logger.ts From server with MIT License | 6 votes |
logger = createLogger({
level: 'error',
format: format.combine(
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
format.printf(data => `${data.timestamp}: ${data.message}`)
),
transports: [new transports.File({ filename: 'logs/errors.log' })]
})
Example #5
Source File: index.ts From bedrock-cli with MIT License | 6 votes |
logger = createLogger({
level: "info",
format: format.combine(format.timestamp(), format.errors({ stack: true })),
defaultMeta: { service: "bedrock" },
transports: [
new transports.File({
filename: CLI_LOG_FILENAME,
format: format.simple(),
}),
new transports.Console({
format: format.cli(),
}),
],
})
Example #6
Source File: commandBuilder.test.ts From bedrock-cli with MIT License | 6 votes |
describe("Tests Command Builder's exit function", () => {
it("calling exit function", async (done) => {
(watchFile as jest.Mock).mockImplementationOnce((f, cb) => {
cb({ size: 100 });
});
const exitFn = jest.fn();
await exitCmd(logger, exitFn, 1, 100).then(() => {
expect(exitFn).toBeCalledTimes(1);
expect(exitFn.mock.calls).toEqual([[1]]);
done();
});
});
it("calling exit function without file transport", async (done) => {
const exitFn = jest.fn();
await exitCmd(
createLogger({
defaultMeta: { service: "bedrock" },
level: "info",
transports: [],
}),
exitFn,
1,
100
).then(() => {
expect(exitFn).toBeCalledTimes(1);
expect(exitFn.mock.calls).toEqual([[1]]);
done();
});
});
});
Example #7
Source File: Logger.ts From covid19-animation-generator with MIT License | 6 votes |
logger = createLogger({
format: combine(
colorize(),
timestamp(),
splat(),
myFormat
),
transports: [new transports.Console()]
})
Example #8
Source File: logger.ts From gear-js with GNU General Public License v3.0 | 6 votes |
Logger = (labelName: string) =>
createLogger({
level: 'debug',
format: combine(
format((info) => {
info.level = info.level.toUpperCase();
return info;
})(),
colorize(),
label({ label: labelName }),
timestamp({ format: 'DD/mm/YY HH:mm:ss' }),
logFormat,
),
transports: [new transports.Console()],
})
Example #9
Source File: application-container.ts From ddd-cqrs-es-aws-sam with MIT License | 6 votes |
/**
* Initialize and bind IoC components.
*/
private constructor() {
super();
// bind logger
this.load(new LoggerModule(), new WinstonModule());
this._loggerInstance = this.createLogger();
this.rebind<Logger>(WINSTON_SYMBOLS.WinstonConfiguration).toConstantValue(this._loggerInstance);
// bind command handlers
this.bind<Handler<RegisterUser>>(RegisterUserHandler).to(RegisterUserHandler);
this.bind<Handler<UpdateUser>>(UpdateUserHandler).to(UpdateUserHandler);
this.bind<Handler<AddUserRole>>(AddUserRoleHandler).to(AddUserRoleHandler);
this.bind<Handler<RemoveUserRole>>(RemoveUserRoleHandler).to(RemoveUserRoleHandler);
this.bind<Handler<DisableUser>>(DisableUserHandler).to(DisableUserHandler);
this.bind<Handler<CreateRole>>(CreateRoleHandler).to(CreateRoleHandler);
this.bind<Handler<DisableRole>>(DisableUserRoleHandler).to(DisableUserRoleHandler);
// bind event projection handlers
this.bind<EventHandler>(UserHandler.name).to(UserHandler);
this.bind<EventHandler>(RoleHandler.name).to(RoleHandler);
// bind services
this.bind<EventPublisher>(DynamoEventPublisher).to(DynamoEventPublisher);
this.bind<Service<User>>(UserService).to(UserService);
this.bind<Service<Role>>(RoleService).to(RoleService);
// bind repositories
this.bind<Repository<any>>(DynamoRepository).to(DynamoRepository);
this.bind<SetValidationRepository>(DynamoSetValidationRepository).to(DynamoSetValidationRepository);
this.bind<ProjectionRepository<any>>(DynamoProjectionRepository).to(DynamoProjectionRepository);
}
Example #10
Source File: application-container.ts From ddd-cqrs-es-aws-sam with MIT License | 6 votes |
/**
* Create logger
* @returns Logger
*/
private createLogger(): Logger {
return createLogger({
level: process.env.logLevel || 'debug',
format: format.combine(
format.prettyPrint(),
format.splat(),
format.simple(),
format.timestamp(),
format.printf(info => {
if (info.message.constructor === Object) {
info.message = JSON.stringify(info.message, null, 2)
}
return `${info.timestamp} ${info.level}: ${info.message}`
}
)),
transports: [new transports.Console()]
});
}
Example #11
Source File: router.test.ts From backstage with Apache License 2.0 | 6 votes |
describe('Router', () => {
describe('/health', () => {
it('should return ok', async () => {
const config = new ConfigReader({ backend: { baseUrl: 'lol' } });
const router = await createRouter({ config, logger: createLogger() });
const app = express().use(router);
const { body } = await supertest(app).get('/health');
expect(body).toEqual({ status: 'ok' });
});
});
});
Example #12
Source File: logger.ts From TXQ with MIT License | 6 votes |
logger = createLogger({
level: 'info',
format: format.combine(
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss',
}),
format.errors({ stack: true }),
format.splat(),
format.json(),
),
transports: transport,
exitOnError: false,
})
Example #13
Source File: logger.ts From projects-bot with MIT License | 6 votes |
export function init (): winston.Logger {
const logPath = path.resolve(__dirname, '../../logs')
const logger = createLogger({
level: process.env.NODE_ENV !== 'development' ? 'info' : 'debug',
format: format.json(),
transports: [
new transports.File({ filename: path.join(logPath, 'error.log'), level: 'error' }),
new transports.File({ filename: path.join(logPath, 'full.log') }),
new transports.Console({ format: format.combine(format.colorize(), format.simple()) })
]
})
return logger
}
Example #14
Source File: Logger.ts From ts-discord-bot-boilerplate with MIT License | 6 votes |
Logger = createLogger({
transports: new Transports.Console(),
format: combine(
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
printf(({ message, level, timestamp }) =>
colorizer.colorize(level, `[${timestamp}]: ${message}`)
)
)
})
Example #15
Source File: methodLogger.ts From Nishan with MIT License | 6 votes |
methodLogger = createLogger({
level: 'info',
format: combine(
colorize(),
timestamp({
format: 'HH:mm:ss'
}),
printf(
({ level, message, timestamp }) => `${colors.blue.bold(timestamp)} - ${level}: ${colors.bold.white(message)}`
)
),
transports: [ new transports.Console() ]
})
Example #16
Source File: endpointLogger.ts From Nishan with MIT License | 6 votes |
endpointLogger = createLogger({
level: 'info',
format: combine(
colorize(),
timestamp({
format: 'HH:mm:ss'
}),
printf(
({ level, message, timestamp }) => `${colors.blue.bold(timestamp)} - ${level}: ${colors.bold.white(message)}`
)
),
transports: [ new transports.Console() ]
})
Example #17
Source File: logger.service.ts From nestjs-starter-rest-api with MIT License | 5 votes |
constructor() {
this.logger = createLogger({
transports: [new transports.Console()],
});
}
Example #18
Source File: logger.service.ts From tradingview-alerts-processor with MIT License | 5 votes |
tradesLogger = createLogger({
level: 'info',
format: defaultLoggerFormat,
transports: [new transports.File(tradesLogFileLoggerOptions)]
})
Example #19
Source File: logger.service.ts From tradingview-alerts-processor with MIT License | 5 votes |
consoleLogger = createLogger({
level: 'debug',
format: defaultLoggerFormat,
transports: [new transports.Console(consoleLoggerOptions)]
})
Example #20
Source File: logger.service.ts From tradingview-alerts-processor with MIT License | 5 votes |
logger = createLogger({
level: 'debug',
format: defaultLoggerFormat,
transports: [
new transports.File(errorLogFileLoggerOptions),
new transports.File(debugLogFileLoggerOptions)
]
})
Example #21
Source File: logger.ts From one-platform with MIT License | 5 votes |
logger = createLogger(winstonOptions)
Example #22
Source File: logger.ts From joplin-utils with MIT License | 5 votes |
logger = createLogger({
level: 'info',
format: format.json(),
defaultMeta: { pluginVersion: json.version },
})
Example #23
Source File: logger.ts From graphql-schema-registry with MIT License | 5 votes |
logger = createLogger({
level: process.env.LOG_LEVEL || 'info',
transports: [new transports.Console()],
format:
process.env.LOG_TYPE === 'json'
? buildJsonFormat()
: buildPrettyFormat(),
})
Example #24
Source File: winston.ts From eosio-contract-api with GNU Affero General Public License v3.0 | 5 votes |
logger = createLogger(options)
Example #25
Source File: Logger.ts From jaebook-server with MIT License | 5 votes |
logger: Logger = createLogger(options)
Example #26
Source File: logger.service.ts From mamori-i-japan-api with BSD 2-Clause "Simplified" License | 5 votes |
constructor() {
//
// As of winston@3, the default logging format is JSON.
//
this.winstonLogger = createLogger({
transports: [new transports.Console()],
})
}
Example #27
Source File: Logger.ts From JSPrismarine with Mozilla Public License 2.0 | 5 votes |
public constructor() {
const date = new Date();
if (!LoggerBuilder.logFile && process.env.NODE_ENV === 'development')
LoggerBuilder.logFile = 'jsprismarine-development.log';
else if (!LoggerBuilder.logFile)
// mmddyyyy-hh-mm-ss. yes American-style, sue me.
LoggerBuilder.logFile = `jsprismarine.${(date.getMonth() + 1).toString().padStart(2, '0')}${date
.getDate()
.toString()
.padStart(2, '0')}${date.getFullYear().toString().padStart(2, '0')}-${date
.getHours()
.toString()
.padStart(2, '0')}${date.getMinutes().toString().padStart(2, '0')}${date
.getSeconds()
.toString()
.padStart(2, '0')}.log`;
this.logger = createLogger({
transports: [
new transports.Console({
level: (global as any).log_level || 'info',
format: combine(
timestamp({ format: 'HH:mm:ss' }),
format((info) => {
info.level = info.level.toUpperCase();
return info;
})(),
format.colorize(),
format.simple(),
printf(({ level, message, timestamp, namespace }) => {
return `[${timestamp} ${level}${colorParser(
`${
namespace &&
((global as any).log_level === 'silly' ||
(global as any).log_level === 'debug' ||
(global as any).log_level === 'verbose')
? ` ${namespace}]`
: ']'
}: ${message}`
)}`;
})
)
}),
new transports.File({
level: 'debug',
filename: path.join(cwd(), 'logs', `${LoggerBuilder.logFile}`),
format: combine(
timestamp({ format: 'HH:mm:ss.SS' }),
format.simple(),
printf(({ level, message, timestamp, namespace }: any) => {
return `[${timestamp}] [${level}]${colorParser(
`${namespace ? ` [${namespace}]` : ''}: ${message}`
)}`.replace(
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
''
);
})
)
})
]
});
}
Example #28
Source File: setup.ts From amplication with Apache License 2.0 | 5 votes |
logger = createLogger({
transports: [new transports.Console()],
format: combine(colorize(), simple()),
})
Example #29
Source File: logger.ts From bdk with Apache License 2.0 | 5 votes |
logger = createLogger( config.isDevMode ? devLoggerConfig : prodLoggerConfig, )