Skip to content

Instantly share code, notes, and snippets.

@tbrannam
tbrannam / logger.ts
Created August 21, 2023 20:43 — forked from BinaryShrub/logger.ts
Winston with console.log and colors support with util.format
import winston from 'winston';
import util from 'util';
const utilFormat = (enableColor: boolean) => {
const printFormat = winston.format.printf(({ level, message, timestamp }) => `${timestamp} ${level}: ${message}`);
const format = winston.format.combine(winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }), {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
transform: (info: any) => {
const args = info[Symbol.for('splat')] || [];
info.message = util.formatWithOptions({ colors: enableColor }, info.message, ...args);
@tbrannam
tbrannam / winston-nodejs-console.js
Created August 21, 2023 20:42 — forked from psenger/winston-nodejs-console.js
[Winston Log to file and console just like NodeJS] #NodeJS #Winston #console #log
const util = require('util')
const path = require( 'path' )
const winston = require( 'winston' );
const { createLogger, transports, format } = winston
const { Console, File } = transports
const { timestamp } = format
// Adapted from https://github.com/winstonjs/winston/issues/1427
const commonConfig = {
handleExceptions: true,
import { URL } from "@fastly/as-url";
import { RegExp } from "assemblyscript-regex";
import { Dictionary } from "@fastly/as-compute"
import { JSON } from "assemblyscript-json";
// import { md5 } from "hash-wasm";
function normalizePath(url: URL): URL {
const filenameRegEx = new RegExp(".*\.([a-zA-Z0-9]{1,11})$", "g");
let path = url.pathname;