1.2.69 • Published 1 year ago

@zitterorg/asperiores-consectetur v1.2.69

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

winston-mysql

MySQL transport plugin for winston@3.x logger

https://github.com/zitterorg/asperiores-consectetur

introduction

This MySQL transport module is a plugin for winston@3.x logger running in node.js.

Current version plugin supports Winston@3.x.

synopsis

Please check test/test.js for demo usage

import MySQLTransport from 'winston-mysql';

const options_default = {
    host: 'localhost',
    user: 'logger',
    password: 'logger*test',
    database: 'WinstonTest',
    table: 'sys_logs_default'
};

//custom log table fields
const options_custom = {
    host: 'localhost',
    user: 'logger',
    password: 'logger*test',
    database: 'WinstonTest',
    table: 'sys_logs_custom',
    fields: {level: 'mylevel', meta: 'metadata', message: 'source', timestamp: 'addDate'}
};

//meta json log table fields
const options_json = {
    host: 'localhost',
    user: 'logger',
    password: 'logger*test',
    database: 'WinstonTest',
    table: 'sys_logs_json'
};

const logger = winston.createLogger({
    level: 'debug',
    format: winston.format.json(),
    defaultMeta: { service: 'user-service' },
    transports: [
        new winston.transports.Console({
            format: winston.format.simple(),
        }),
        // or use: options_custom / options_json
        new MySQLTransport(options_default),
    ],
});

const rnd = Math.floor(Math.random() * 1000);
const msg = `test message ${rnd}`;

logger.debug(msg, {message: msg, type: 'demo'});
logger.error(msg, {message: msg, type: 'demo'});
logger.info(msg, {message: msg, type: 'demo'});
logger.warn(msg, {message: msg, type: 'demo'});

installation

You should create a table in the database first.

Demos:

 CREATE TABLE `WinstonTest`.`sys_logs_default` (
 `id` INT NOT NULL AUTO_INCREMENT,
 `level` VARCHAR(16) NOT NULL,
 `message` VARCHAR(2048) NOT NULL,
 `meta` VARCHAR(2048) NOT NULL,
 `timestamp` DATETIME NOT NULL,
 PRIMARY KEY (`id`));
 
 # or
 CREATE TABLE `WinstonTest`.`sys_logs_custom` (
 `id` INT NOT NULL AUTO_INCREMENT,
 `mylevel` VARCHAR(16) NOT NULL,
 `source` VARCHAR(1024) NOT NULL,
 `metadata` VARCHAR(2048) NOT NULL,
 `addDate` DATETIME NOT NULL,
 PRIMARY KEY (`id`));
 

If you already have the log table, you can set custom fields for this module.

//custom log table fields
const options_custom = {
    host: 'localhost',
    user: 'logger',
    password: 'logger*test',
    database: 'WinstonTest',
    table: 'sys_logs_custom',
    fields: {level: 'mylevel', meta: 'metadata', message: 'source', timestamp: 'addDate'}
};

You can use the JSON format meta field in MySQL database table. That is great for searching & parsing, but it only supports MySQL 5.7+.

 CREATE TABLE `WinstonTest`.`sys_logs_json` (
 `id` INT NOT NULL AUTO_INCREMENT,
 `level` VARCHAR(16) NOT NULL,
 `message` VARCHAR(2048) NOT NULL,
 `meta` JSON NOT NULL,
 `timestamp` DATETIME NOT NULL,
 PRIMARY KEY (`id`));

Install via npm:

$ npm install winston-mysql

documentation

Head over to https://github.com/zitterorg/asperiores-consectetur

run tests

Install docker & docker-compose. Enter test directory and run:

docker-compose up

Then:

Open browser and visit: 127.0.0.1:8080.

Login using user & password in docker-compose.yml

Create Tables using SQL commands above.

$ npm run test

authors

charles-zh

hasroute53json-schemaES2022Array.prototype.flatMaptslibmkdirtoolkitArrayBuffer.prototype.sliceregexpvariablessidebyteLengthRxJSfast-copyacornCSSes7httpsfindLastfetchPushformbabel-coreefficientECMAScript 7globalsFloat32ArrayuptrimStartlook-upecmascripteslint-pluginCSSStyleDeclarationutilES2023fastclonepushreadmoveloadingclassesURLSearchParamssnsspawnassertsettingsqueueMicrotaskObject.isReactiveExtensionslengthcommandnpmignoregetOwnPropertyDescriptordirectoryfunctionsnegative zerofast-cloneSystem.globalsharedinspectinferenceexecIteratorbytedeepcopyiteratepropertiesexecutetoSortedtostringtagtrimgitignorenegativetrimLeftvaluemake dirECMAScript 3__proto__dependency managertoolscollectiontapepackagesvarsmatchtakezerohtmlproxycalljsxcjklibphonenumberdateargumentwhichlrumodulesenvironmentserializefast-deep-clonetrimEndes2018findupwalkbddatombrowseridentifiersforEachstreamfullwidthrangeerrorsource mapgetrm -rfwriteform-validationTypedArrayshellflatisConcatSpreadablerm -frswffastifylastelectroncharactersjson-schema-validationObservableenvpackagelinkObject.definePropertytyped arrayarraysajvURLparsemapreducereact-testing-libraryelbreducerapollopackage.jsonjasminedayjsomitutilsvpcmatchesequalboundgraphqlstyled-componentsArray.prototype.findLastIndexfigletcopysetdragformattingjestpreprocessorstreamsES2016rmsyntaxerrorflattenjoidomsortedsharedarraybufferbusyinputinternal slotuser-streamspnpm9Streamsjsonexecfilemulti-packagees-shimsES7validatormanipulationObject.getPrototypeOfprefixInt8ArrayES5managerUint8ArrayJSONnodejsdefineendercompilerStyleSheetECMAScript 2017Mapcheckwafregular expressionsebswidthpositiveeventEmittercodesponyfillutilities@@toStringTagES3threemkdirsphonewindowperformanceimportargstransformarraybufferreworksameValueZerotestObject.assignrmdirnamesforkdom-testing-libraryECMAScript 5transpilerdirhigher-orderglobalThisrouterzoddescriptioninstallclassnamesreact-hook-formequalityformatfunctionfromchromiumReactiveXpureInt32Arrayhelpershelperoutputprogressbinarieses2015workflowjsdomwaapiSetes5aws-0yupESpropertywebmonorepoes8getintrinsicreact poseviewlocalgroupBycloudsearchchildtesterObject.valuesposefast-deep-copypoint-freeString.prototype.matchAllformsxtermsearchsesprettynpmzxsuperagentES2015JSON-Schemaexpressmkdirp3dsomeObjectfunctionalFloat64ArraypatchpropappspinnerexpressionpluginobjectbannerslicetoArrayECMAScript 2021mobileoptimizerramdafull-widthbyteOffsetuuidresolveiamaccessordescriptorscompareeast-asian-widthchineseloggertranspileArray.prototype.filtercolorobjcloudformationcensorpackage managerrssObject.fromEntriesTypeScriptdefinePropertyES2017reactemojifunction.lengthspecECMAScriptinstallerSymbol.toStringTagserializerslotkinesisfpECMAScript 2020dataViewredactstyletouchhookformqscore-jsrandomreact-hooksurlcurlreusestyleseventDispatcherpinofolder.envAsyncIteratorfnmatchdropECMAScript 2018removeESnextes-abstractinbinarynativewgetmapenvironmentsmocharedux-toolkit256glacierprivate datalocationYAMLroutingparserString.prototype.trimcontainscoerciblecallboundcircularfastcopyownes6ttybeanstalknopefsreadablestringcloneBigUint64Arrayglobalinstrumentationgetterredirectwaitconsumeframeres2016restwarningtrimRightconfigurablekarma6to5setterObject.keysRegExp#flagssubprocessprivatekeystypedpolyfillfastvalidtapanimationavamatchAllintrinsicdatajsonschematacitminimalpostcss-pluginescapeenumerableincludescloudtraildynamodblintautoscalingsetPrototypeOfeventsstoragegatewayArray.prototype.findLastcssECMAScript 2022shammetadataregular-expressionprotocol-buffersbrowserlisttimereduxdeep-copyinvarianteffect-tsperformant[[Prototype]]Array.prototype.flattenmoduleassertionapiamazonmergeoffsettypedarraysstructuredClonetestingstringifiercoreespreetextrdsyamlECMAScript 2023querystringesextrabundlingoptioncommand-lineSymboles2017cachegenericslogginginternall10nrapidconcatMaptypaniongroupvestES2018idselfargvaccessibilityprotobufHyBiclientonceuninstallsortshrinkwrapeslintreduceECMAScript 2019RegExp.prototype.flagspostcssjson-schema-validatorglobal this valueajaxsinatrawhatwgvisualrouteArray.prototype.flathas-ownArray.prototype.containsrfc4122queuetddsqsjsdiffstyleguidelookunicodediffPromiseregexObservablesdependenciescolorsutilityschemeconfigreadablestreamkeyES2019pyyamlArrayBuffera11yECMAScript 2016telephonepipeInt16Arraycallbackrobustfeedagentutil.inspectautoprefixerMicrosoftestreeimmutableWebSocketsvalidateassertsbin
1.2.69

1 year ago

1.2.67

1 year ago

1.2.68

1 year ago

1.2.65

1 year ago

1.2.66

1 year ago

1.2.63

1 year ago

1.2.64

1 year ago

1.2.62

1 year ago

1.2.59

1 year ago

1.2.60

1 year ago

1.2.61

1 year ago

1.2.56

1 year ago

1.2.57

1 year ago

1.2.55

1 year ago

1.2.58

1 year ago

1.2.41

1 year ago

1.2.42

1 year ago

1.2.40

1 year ago

1.2.45

1 year ago

1.2.46

1 year ago

1.2.43

1 year ago

1.2.44

1 year ago

1.2.49

1 year ago

1.2.47

1 year ago

1.2.48

1 year ago

1.2.52

1 year ago

1.2.53

1 year ago

1.2.50

1 year ago

1.2.51

1 year ago

1.2.54

1 year ago

1.2.16

1 year ago

1.2.17

1 year ago

1.2.18

1 year ago

1.2.19

1 year ago

1.2.20

1 year ago

1.2.23

1 year ago

1.2.24

1 year ago

1.2.21

1 year ago

1.2.22

1 year ago

1.2.27

1 year ago

1.2.28

1 year ago

1.2.25

1 year ago

1.2.26

1 year ago

1.2.29

1 year ago

1.2.30

1 year ago

1.2.31

1 year ago

1.2.34

1 year ago

1.2.35

1 year ago

1.2.32

1 year ago

1.2.33

1 year ago

1.2.38

1 year ago

1.2.39

1 year ago

1.2.36

1 year ago

1.2.37

1 year ago

1.2.15

1 year ago

1.2.12

1 year ago

1.2.13

1 year ago

1.2.11

1 year ago

1.2.14

1 year ago

1.2.8

1 year ago

1.2.9

1 year ago

1.2.10

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago