@google-cloud/logging - npm

文章推薦指數: 80 %
投票人數:10人

Google Cloud Logging allows you to store, search, analyze, monitor, and alert on log data and events from Google Cloud Platform and Amazon ... @google-cloud/logging9.6.6 • Public • Published3daysagoReadmeExploreBETA15Dependencies200Dependents117Versions CloudLogging:Node.jsClient GoogleCloudLoggingallowsyoutostore,search,analyze, monitor,andalertonlogdataandeventsfromGoogleCloudPlatformandAmazonWebServices. Ifyourequirelightweightdependencies,anexperimental,minifiedversionof thislibraryisavailableat@google-cloud/logging-min. Note:logging-minisexperimental,anditsfeaturesurfaceissubjectto change. Acomprehensivelistofchangesineachversionmaybefoundin theCHANGELOG. CloudLoggingNode.jsClientAPIReference CloudLoggingDocumentation github.com/googleapis/nodejs-logging ReadmoreabouttheclientlibrariesforCloudAPIs,includingtheolder GoogleAPIsClientLibraries,inClientLibrariesExplained. Tableofcontents: Quickstart Beforeyoubegin Installingtheclientlibrary Usingtheclientlibrary Samples Versioning Contributing License Quickstart Beforeyoubegin SelectorcreateaCloudPlatformproject. EnabletheCloudLoggingAPI. Setupauthenticationwithaserviceaccountsoyoucanaccessthe APIfromyourlocalworkstation. Installingtheclientlibrary npminstall@google-cloud/logging Usingtheclientlibrary //ImportstheGoogleCloudclientlibrary const{Logging}=require('@google-cloud/logging'); asyncfunctionquickstart( projectId='YOUR_PROJECT_ID',//YourGoogleCloudPlatformprojectID logName='my-log'//Thenameofthelogtowriteto ){ //Createsaclient constlogging=newLogging({projectId}); //Selectsthelogtowriteto constlog=logging.log(logName); //Thedatatowritetothelog consttext='Hello,world!'; //Themetadataassociatedwiththeentry constmetadata={ resource:{type:'global'}, //See:https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity severity:'INFO', }; //Preparesalogentry constentry=log.entry(metadata,text); asyncfunctionwriteLog(){ //Writesthelogentry awaitlog.write(entry); console.log(`Logged:${text}`); } writeLog(); } BatchingWrites Highthroughputapplicationsshouldavoidawaitingcallstothelogger: awaitlog.write(logEntry1); awaitlog.write(logEntry2); Rather,applicationsshoulduseafireandforgetapproach: log.write(logEntry1); log.write(logEntry2); The@google-cloud/logginglibrarywillhandlebatchinganddispatching theseloglinestotheAPI. WritingtoStdout TheLogSyncclasshelpsuserseasilywritecontext-richstructuredlogsto stdoutoranycustomtransport.Itextractsadditionallogpropertieslike tracecontextfromHTTPheadersandcanbeusedasanon/offtogglebetween writingtotheAPIortostdoutduringlocaldevelopment. Logswrittentostdoutarethenpickedup,out-of-process,byaLogging agentintherespectiveGCPenvironment.Loggingagentscanaddmore propertiestoeachentrybeforestreamingittotheLoggingAPI. ReadmoreaboutLoggingagents. ServerlessapplicationslikeCloudFunctions,CloudRun,andAppEngine arehighlyrecommendedtousetheLogSyncclassasasynclogsmaybedropped duetolackofCPU. Readmoreaboutstructuredlogging. //Optional:Createandconfigureaclient constlogging=newLogging(); awaitlogging.setProjectId() awaitlogging.setDetectedResource() //CreateaLogSynctransport,defaultingto`process.stdout` constlog=logging.logSync(logname); constmeta={//optionalfieldoverrideshere}; constentry=log.entry(meta,'Yourlogmessage'); log.write(entry); //Syntaxsugarforloggingataspecificseverity log.alert(entry); log.warning(entry); PopulatingHttprequestmetadata MetadataaboutHttprequestisapartofthestructuredloginfo thatcanbecapturedwithineachlogentry.Itcanprovideacontextfortheapplicationlogsand isusedtogroupmultiplelogentriesundertheloadbalancerrequestlogs.Seethesample howtopopulatetheHttprequestmetadataforlogentries. Ifyoualreadyhavea"raw"Httprequestobjectyoucanassignittoentry.metadata.httpRequestdirectly.Moreinformationabout howtherequestisinterpretedasrawcanbefoundinthecode. Samples Samplesareinthesamples/directory.Eachsample'sREADME.mdhasinstructionsforrunningitssample. Sample SourceCode Tryit Fluent sourcecode LogHTTPRequest sourcecode Logs sourcecode Quickstart sourcecode Sinks sourcecode TheCloudLoggingNode.jsClientAPIReferencedocumentation alsocontainssamples. SupportedNode.jsVersions OurclientlibrariesfollowtheNode.jsreleaseschedule. Librariesarecompatiblewithallcurrentactiveandmaintenanceversionsof Node.js. Clientlibrariestargetingsomeend-of-lifeversionsofNode.jsareavailable,and canbeinstalledvianpmdist-tags. Thedist-tagsfollowthenamingconventionlegacy-(version). LegacyNode.jsversionsaresupportedasabesteffort: Legacyversionswillnotbetestedincontinuousintegration. Somesecuritypatchesmaynotbeabletobebackported. Dependencieswillnotbekeptup-to-date,andfeatureswillnotbebackported. Legacytagsavailable legacy-8:installclientlibrariesfromthisdist-tagforversions compatiblewithNode.js8. Versioning ThislibraryfollowsSemanticVersioning. ThislibraryisconsideredtobeGeneralAvailability(GA).Thismeansit isstable;thecodesurfacewillnotchangeinbackwards-incompatibleways unlessabsolutelynecessary(e.g.becauseofcriticalsecurityissues)orwith anextensivedeprecationperiod.IssuesandrequestsagainstGAlibraries areaddressedwiththehighestpriority. MoreInformation:GoogleCloudPlatformLaunchStages Contributing Contributionswelcome!SeetheContributingGuide. PleasenotethatthisREADME.md,thesamples/README.md, andavarietyofconfigurationfilesinthisrepository(including.nycrcandtsconfig.json) aregeneratedfromacentraltemplate.Toeditoneofthesefiles,makeanedit toitstemplatesin directory. License ApacheVersion2.0 SeeLICENSE KeywordsgoogleapisclientgoogleapiclientgoogleapisgoogleapigooglegooglecloudplatformgooglecloudcloudgoogleloggingloggingstackdriverloggingstackdriverInstallnpmi@google-cloud/loggingRepositoryGitgithub.com/googleapis/nodejs-loggingHomepagegithub.com/googleapis/nodejs-logging#readmeDownloadsWeeklyDownloads161,464Version9.6.6LicenseApache-2.0UnpackedSize3.6MBTotalFiles68Lastpublish3daysagoCollaboratorsTryonRunKitReportmalware



請為這篇文章評分?