首页 > 其他分享 >Go - logging

Go - logging

时间:2023-09-29 14:57:19浏览次数:34  
标签:functions code logging Prints Print exit Go Exit

The log package provides several functions that allow you to write logs. In particular, there are three sets of functions:
Print
• Prints the logs to the logger
Fatal
• Prints to the logger and calls os.Exit with an exit code of 1
Panic
• Prints to the logger and calls panic
Each set comes in a triplet of functions; for example, Print has Print and Printf , which allow formatting, and Println adds a newline after printing.

Fatal ends with exit code 1. Exit code 1 is a catch - all for general errors, meaning something went wrong with the program, and that’s why it has to exit.

Panic ends with exicode 2. Exit code 2, which is technically inaccurate because traditionally, exit code 2 means something like “incorrect arguments.” It will halt the current goroutine, run the deferred code, and return to the calling function, triggering another panic , which bubbles up eventually to main and finally exits.

 

标签:functions,code,logging,Prints,Print,exit,Go,Exit
From: https://www.cnblogs.com/zhangzhihui/p/17736994.html

相关文章

  • Go - Inspecting Errors
    Problem: Youwanttocheckforspecificerrorsorspecifictypesoferrors.Solution: Usetheerrors.Isanderrors.Asfunctions.Theerrors.Isfunctioncomparesanerrortoavalueandtheerrors.Asfunctionchecksifanerrorisofaspecifictype. Us......
  • MongoDB playground All In One
    MongoDBplaygroundAllInOneMongoDBREPLhttps://mongoplayground.net/db={"teacher":[{"_id":ObjectId("64fee9b54273ac2234441225"),"teacherid":ObjectId("64f1d72a4331bc8fc4c5930f"......
  • 关于一个django工程如何与达梦数据库连接的全程总结
    关于一个django工程如何与达梦数据库连接的全程总结目录1.达梦数据库的安装(win、图形化工具)2.DM管理工具的基本使用:表空间的建删用户的管理模式的建删表的创建、删除、查看3.Django项目接入dm数据库settings的database配置解释器中的相关包dmPython的编译※环境准备正式编......
  • Go - Wrapping an Error with Other Errors
    Problem: Youwanttoprovideadditionalinformationandcontexttoanerroryoureceivebeforereturningitasanothererror.Solution: Wraptheerroryoureceivewithanothererroryoucreatebeforereturningit. Thereareacoupleofwaystowraperr......
  • Go - Creating Customized Errors
    Problem: Youwanttocreatecustomerrorstocommunicatemoreinformationabouttheerrorencountered.Solution: Createanewstring-basederrororimplementtheerrorinterfacebycreatingastructwithanErrormethodthatreturnsastring. Therea......
  • Go 语言概述
    本文主要包含以下内容:为什么需要一门新的语言Go 语言基本介绍Go 的发展历程Go 应用领域o 语言基本介绍在上述背景下,谷歌公司于 2009 年推出了新一代的编程语言 Go。提起 Go 语言的出身,我们就必须将我们饱含敬意的眼光投向持续推出惊世骇俗成果的贝尔实验室。贝尔实验室已......
  • 【代码分享】如何用go语言做一个简单的爬虫工具
    之前跟大家分享过一个简单的php做的爬虫,今天给大家带来一个使用golang来制作的一个简单的爬虫工具!大家看在中秋节我还更文的份上大家多评论转发收藏一下哟~也祝大家中秋节快乐安康~*使用colly来做一个简单的爬虫#安装collygogetgithub.com/gocolly/colly编写代码package......
  • Go - Simplifying Repetitive Error Handling
    Problem: Youwanttoreducethenumberoflinesofrepetitiveerror-handlingcode.Solution: Usehelperfunctionstoreducethenumberoflinesofrepetitiveerror-handlingcode. OneofthemostfrequentcomplaintsaboutGo’serrorhandling,especi......
  • Go - Using Multiple Versions of the Same Dependent Packages
    Problem: Youwanttousemultipleversionsofthesamedependentpackagesinyourcode.Solution: Usethereplacedirectiveinthego.modfiletorenameyourpackage.Thoughitmightseemlikeaverynicherequirement,thereissometimesaneedtobeabl......
  • Go - Requiring Local Versions of Dependent Packages
    Problem: Youwanttouselocalversionsofthedependentpackages.Solution: SetupGotouseavendordirectorybyrunninggomodvendor.Localversionsarethespecificversionofthedependentpackagesthatyoucanuseandareasafeguardincasethe......