[{"data":1,"prerenderedAt":552},["ShallowReactive",2],{"docs-\u002Fdocs\u002Fmain\u002Flogging":3},{"id":4,"title":5,"body":6,"description":539,"extension":540,"group":541,"meta":542,"navigation":543,"order":544,"path":545,"section":546,"seo":547,"source":548,"stem":549,"version":550,"__hash__":551},"docs\u002Fdocs\u002Fmain\u002Flogging.md","Server output and logging",{"type":7,"value":8,"toc":532},"minimark",[9,18,23,26,54,73,76,80,87,216,231,266,270,382,385,388,392,480,499,510,513,517,520,528],[10,11,12,13,17],"p",{},"Gonex uses application-scoped ",[14,15,16],"code",{},"log\u002Fslog"," loggers for lifecycle and HTTP completion events. It does not replace the process-wide default logger.",[19,20,22],"h2",{"id":21},"run-an-application","Run an application",[10,24,25],{},"From a CLI-generated app:",[27,28,33],"pre",{"className":29,"code":30,"language":31,"meta":32,"style":32},"language-sh shiki shiki-themes light-plus light-plus dark-plus","go tool gonex run\n","sh","",[14,34,35],{"__ignoreMap":32},[36,37,40,44,48,51],"span",{"class":38,"line":39},"line",1,[36,41,43],{"class":42},"swoLU","go",[36,45,47],{"class":46},"sFD8J"," tool",[36,49,50],{"class":46}," gonex",[36,52,53],{"class":46}," run\n",[10,55,56,57,60,61,64,65,68,69,72],{},"Readable development output shows the application name, resolved Gonex version, environment, listening address and clickable local URL. Wildcard listeners (",[14,58,59],{},"0.0.0.0"," or ",[14,62,63],{},"::",") display a localhost URL with the actual port; this is a local convenience, not a public deployment URL. OpenAPI and optional ",[14,66,67],{},"\u002Fdocs"," URLs are shown only when enabled, along with registered version-specific documents. HTTP-disabled apps show no HTTP URLs. The startup event is emitted after resources start and the listener binds, never on a failed bind; dependency readiness is still reported separately by ",[14,70,71],{},"\u002Freadyz",".",[10,74,75],{},"Ctrl+C triggers graceful shutdown in the generated executable. Lifecycle events report startup failure, stopping, shutdown failure and successful stop.",[19,77,79],{"id":78},"configuration","Configuration",[10,81,82,83,86],{},"The generated ",[14,84,85],{},"config.Load()"," reads these variables:",[88,89,90,106],"table",{},[91,92,93],"thead",{},[94,95,96,100,103],"tr",{},[97,98,99],"th",{},"Variable",[97,101,102],{},"Default",[97,104,105],{},"Meaning",[107,108,109,125,143,169,194],"tbody",{},[94,110,111,117,122],{},[112,113,114],"td",{},[14,115,116],{},"APP_NAME",[112,118,119],{},[14,120,121],{},"Gonex",[112,123,124],{},"Application name in startup output",[94,126,127,132,137],{},[112,128,129],{},[14,130,131],{},"GONEX_ENV",[112,133,134],{},[14,135,136],{},"development",[112,138,139,142],{},[14,140,141],{},"production"," selects JSON for the auto format",[94,144,145,150,155],{},[112,146,147],{},[14,148,149],{},"GONEX_LOG_LEVEL",[112,151,152],{},[14,153,154],{},"INFO",[112,156,157,160,161,160,163,160,166],{},[14,158,159],{},"DEBUG",", ",[14,162,154],{},[14,164,165],{},"WARN",[14,167,168],{},"ERROR",[94,170,171,176,181],{},[112,172,173],{},[14,174,175],{},"GONEX_LOG_FORMAT",[112,177,178],{},[14,179,180],{},"auto",[112,182,183,160,185,160,188,160,191],{},[14,184,180],{},[14,186,187],{},"pretty",[14,189,190],{},"text",[14,192,193],{},"json",[94,195,196,201,205],{},[112,197,198],{},[14,199,200],{},"GONEX_LOG_COLOR",[112,202,203],{},[14,204,180],{},[112,206,207,208,160,210,160,213],{},"Pretty output: ",[14,209,180],{},[14,211,212],{},"always",[14,214,215],{},"never",[10,217,218,219,222,223,226,227,230],{},"Auto color is disabled when stderr is not a terminal, ",[14,220,221],{},"TERM=dumb",", or ",[14,224,225],{},"NO_COLOR"," is set. JSON is one object per line. Logs go to stderr, suitable for container\u002Fplatform log collection. This does not implement file rotation, remote storage or an external collector. Environment variables are read by the generated app configuration, not implicitly by the core library. Export them in your process environment; ",[14,228,229],{},".env"," is not loaded automatically.",[10,232,233,234,237,238,160,241,160,244,160,247,250,251,254,255,258,259,250,262,265],{},"Manual consumers configure ",[14,235,236],{},"config.Config"," with ",[14,239,240],{},"Name",[14,242,243],{},"Environment",[14,245,246],{},"LogLevel",[14,248,249],{},"LogFormat"," and ",[14,252,253],{},"LogColor",". A caller-supplied ",[14,256,257],{},"Logger *slog.Logger"," takes precedence. ",[14,260,261],{},"DisableRequestLogging",[14,263,264],{},"DisableStartupBanner"," opt out of completion events and the startup summary respectively.",[19,267,269],{"id":268},"request-events","Request events",[88,271,272,281],{},[91,273,274],{},[94,275,276,279],{},[97,277,278],{},"Field",[97,280,105],{},[107,282,283,299,312,322,335,355,368],{},[94,284,285,296],{},[112,286,287,160,290,160,293],{},[14,288,289],{},"time",[14,291,292],{},"level",[14,294,295],{},"msg",[112,297,298],{},"slog timestamp, severity and event message",[94,300,301,309],{},[112,302,303,160,306],{},[14,304,305],{},"service",[14,307,308],{},"environment",[112,310,311],{},"Application identity and environment from config",[94,313,314,319],{},[112,315,316],{},[14,317,318],{},"trace_id",[112,320,321],{},"W3C trace identifier shared with unary RPC calls",[94,323,324,329],{},[112,325,326],{},[14,327,328],{},"request_id",[112,330,331,332],{},"Fresh server-generated identifier, also returned as ",[14,333,334],{},"X-Request-ID",[94,336,337,345],{},[112,338,339,160,342],{},[14,340,341],{},"method",[14,343,344],{},"path",[112,346,347,348,351,352],{},"Standard HTTP method (other tokens use ",[14,349,350],{},"OTHER",") and registered route pattern; unknown paths use ",[14,353,354],{},"unmatched",[94,356,357,365],{},[112,358,359,160,362],{},[14,360,361],{},"status",[14,363,364],{},"duration_ms",[112,366,367],{},"Response status and elapsed processing milliseconds",[94,369,370,375],{},[112,371,372],{},[14,373,374],{},"error",[112,376,377,378,381],{},"Safe framework error code or ",[14,379,380],{},"handler panic",", when applicable",[10,383,384],{},"Successful responses use INFO; 4xx use WARN; 5xx and panics use ERROR. One completion event is emitted per request, including recovered panics. Additional business log events are separate. Filtering by log level may suppress lower-severity events. Existing metrics\u002Ftrace middleware can still be installed separately.",[10,386,387],{},"The default request event excludes request\u002Fresponse bodies, headers, query strings, raw path parameter values, arbitrary error strings and panic payloads. Application code remains responsible for the fields it explicitly logs.",[19,389,391],{"id":390},"log-from-a-service","Log from a service",[27,393,396],{"className":394,"code":395,"language":43,"meta":32,"style":32},"language-go shiki shiki-themes light-plus light-plus dark-plus","observability.Logger(ctx, nil).InfoContext(ctx,\n    \"user created\",\n    \"module\", \"users\",\n    \"user_id\", user.ID,\n)\n",[14,397,398,435,443,456,474],{"__ignoreMap":32},[36,399,400,404,407,410,413,416,418,422,425,428,430,432],{"class":38,"line":39},[36,401,403],{"class":402},"sswaR","observability",[36,405,72],{"class":406},"s_Yst",[36,408,409],{"class":42},"Logger",[36,411,412],{"class":406},"(",[36,414,415],{"class":402},"ctx",[36,417,160],{"class":406},[36,419,421],{"class":420},"stxUP","nil",[36,423,424],{"class":406},").",[36,426,427],{"class":42},"InfoContext",[36,429,412],{"class":406},[36,431,415],{"class":402},[36,433,434],{"class":406},",\n",[36,436,438,441],{"class":38,"line":437},2,[36,439,440],{"class":46},"    \"user created\"",[36,442,434],{"class":406},[36,444,446,449,451,454],{"class":38,"line":445},3,[36,447,448],{"class":46},"    \"module\"",[36,450,160],{"class":406},[36,452,453],{"class":46},"\"users\"",[36,455,434],{"class":406},[36,457,459,462,464,467,469,472],{"class":38,"line":458},4,[36,460,461],{"class":46},"    \"user_id\"",[36,463,160],{"class":406},[36,465,466],{"class":402},"user",[36,468,72],{"class":406},[36,470,471],{"class":402},"ID",[36,473,434],{"class":406},[36,475,477],{"class":38,"line":476},5,[36,478,479],{"class":406},")\n",[10,481,482,483,486,487,490,491,494,495,498],{},"Import ",[14,484,485],{},"github.com\u002Famkargar\u002Fgonex\u002Fobservability",". Pass the request context into services; the logger carries its request ID. Outside an HTTP request, supply the application logger as the fallback (",[14,488,489],{},"observability.Logger(ctx, application.Logger())","). The ",[14,492,493],{},"module"," field is explicit business context, not inferred from the URL. ",[14,496,497],{},"observability.RequestID(ctx)"," reads the current ID directly.",[10,500,501,502,505,506,509],{},"For a custom destination, construct a logger with ",[14,503,504],{},"observability.NewLogger(observability.LogOptions{Output: writer, Format: \"json\", Level: \"INFO\"})"," and pass it through ",[14,507,508],{},"config.Config.Logger",". Keep asynchronous tasks' cancellation and log context deliberate.",[10,511,512],{},"Lifecycle failures use safe startup_failed\u002Fresource_failed\u002Fshutdown_failed codes in default logs. Detailed causes are returned to the caller for deliberate private handling; do not log credential-bearing causes indiscriminately.",[19,514,516],{"id":515},"read-the-server-summary","Read the server summary",[10,518,519],{},"The development output groups the application name, local URL, actual listening\naddress, OpenAPI URL, environment, framework version and debug flag. Request\nlines align method, route, status and elapsed milliseconds, while retaining\ncorrelation IDs. Production auto mode continues to use JSON.",[10,521,522,523,72],{},"For the browser welcome page and detailed errors, see ",[524,525,527],"a",{"href":526},"\u002Fdocs\u002Fmain\u002Fdebug\u002F","DEBUG configuration",[529,530,531],"style",{},"html pre.shiki code .swoLU, html code.shiki .swoLU{--shiki-light:#795E26;--shiki-default:#795E26;--shiki-dark:#DCDCAA}html pre.shiki code .sFD8J, html code.shiki .sFD8J{--shiki-light:#A31515;--shiki-default:#A31515;--shiki-dark:#CE9178}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sswaR, html code.shiki .sswaR{--shiki-light:#001080;--shiki-default:#001080;--shiki-dark:#9CDCFE}html pre.shiki code .s_Yst, html code.shiki .s_Yst{--shiki-light:#000000;--shiki-default:#000000;--shiki-dark:#D4D4D4}html pre.shiki code .stxUP, html code.shiki .stxUP{--shiki-light:#0000FF;--shiki-default:#0000FF;--shiki-dark:#569CD6}",{"title":32,"searchDepth":437,"depth":437,"links":533},[534,535,536,537,538],{"id":21,"depth":437,"text":22},{"id":78,"depth":437,"text":79},{"id":268,"depth":437,"text":269},{"id":390,"depth":437,"text":391},{"id":515,"depth":437,"text":516},"Configure readable server startup URLs, correlated request logs, log levels and structured production JSON in a Gonex application.","md","SHIP YOUR APP",{},true,145,"\u002Fdocs\u002Fmain\u002Flogging","build",{"title":5,"description":539},"logging.md","docs\u002Fmain\u002Flogging","main","dLg2JelWjdfkdUQhT9V8HkWDD7WrFODw7aCC_y7RL2g",1792521640577]