"use strict";(globalThis.webpackChunk_elliemae_pui_diagnostics=globalThis.webpackChunk_elliemae_pui_diagnostics||[]).push([[5722],{116:(e,n,s)=>{s.d(n,{R:()=>o,x:()=>l});var t=s(758);const a={},i=t.createContext(a);function o(e){const n=t.useContext(i);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),t.createElement(i.Provider,{value:n},e.children)}},3115:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>r,contentTitle:()=>l,default:()=>d,frontMatter:()=>o,metadata:()=>t,toc:()=>c});const t=JSON.parse('{"id":"usage","title":"Basic Example","description":"Create instance of the logger","source":"@site/docs/usage.md","sourceDirName":".","slug":"/usage","permalink":"/diagnostics/usage","draft":false,"unlisted":false,"editUrl":"https://git.elliemae.io/platform-ui/pui-diagnostics.git/docs/usage.md","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"Installation","permalink":"/diagnostics/installation"}}');var a=s(6070),i=s(116);const o={},l="Basic Example",r={},c=[{value:"Logging Exceptions",id:"logging-exceptions",level:2},{value:"Changing default log level",id:"changing-default-log-level",level:2}];function g(e){const n={code:"code",h1:"h1",h2:"h2",header:"header",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.header,{children:(0,a.jsx)(n.h1,{id:"basic-example",children:"Basic Example"})}),"\n",(0,a.jsx)(n.p,{children:"Create instance of the logger"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"const appLogger = logger({\n  transport: http('https://int.api.ellielabs.com/diagnostics/v2/logging'),\n  index: 'myapp',\n  team: 'my team',\n  appName: 'Hello World App',\n});\n"})}),"\n",(0,a.jsx)(n.p,{children:"log messages with different log level"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"appLogger.info('My application log message');\n"})}),"\n",(0,a.jsx)(n.h2,{id:"logging-exceptions",children:"Logging Exceptions"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-ts",children:"  try {\n    ...\n  } catch(ex) {\n     const logRecord = {\n      code: 'puiweb002',\n      message: 'Unable to send message',\n      exception: ex as Error,\n    };\n    appLogger.error(logRecord);\n  }\n"})}),"\n",(0,a.jsx)(n.h2,{id:"changing-default-log-level",children:"Changing default log level"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-ts",children:"  import { LogLevel } from '@elleimae/pui-diagnostics';\n  ...\n  appLogger.setLogLevel(LogLevels.DEBUG);\n"})})]})}function d(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(g,{...e})}):g(e)}}}]);