{"id":18811729,"url":"https://github.com/logicmonitor/lm-zap-hook","last_synced_at":"2025-10-04T21:05:15.616Z","repository":{"id":43997619,"uuid":"506364757","full_name":"logicmonitor/lm-zap-hook","owner":"logicmonitor","description":"LogicMonitor hook for zap logger ","archived":false,"fork":false,"pushed_at":"2022-07-14T07:44:02.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-12-30T00:13:27.148Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/logicmonitor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-22T18:35:16.000Z","updated_at":"2022-07-04T11:06:02.000Z","dependencies_parsed_at":"2022-07-11T01:02:28.516Z","dependency_job_id":null,"html_url":"https://github.com/logicmonitor/lm-zap-hook","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicmonitor%2Flm-zap-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicmonitor%2Flm-zap-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicmonitor%2Flm-zap-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logicmonitor%2Flm-zap-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/logicmonitor","download_url":"https://codeload.github.com/logicmonitor/lm-zap-hook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239748248,"owners_count":19690232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T23:27:27.642Z","updated_at":"2025-10-04T21:05:15.527Z","avatar_url":"https://github.com/logicmonitor.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lm-zap-hook\n\n[![codecov](https://codecov.io/gh/logicmonitor/lm-zap-hook/branch/main/graph/badge.svg?token=RVRA5LFQ7C)](https://codecov.io/gh/logicmonitor/lm-zap-hook)\n[![build_and_test](https://github.com/logicmonitor/lm-zap-hook/actions/workflows/ci.yml/badge.svg)](https://github.com/logicmonitor/lm-zap-hook/actions/workflows/ci.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/logicmonitor/lm-zap-hook.svg)](https://pkg.go.dev/github.com/logicmonitor/lm-zap-hook)\n[![Go Report Card](https://goreportcard.com/badge/github.com/logicmonitor/lm-zap-hook)](https://goreportcard.com/report/github.com/logicmonitor/lm-zap-hook)\n\n**lm-zap-hook** is a `zapcore.Core` implementation to integrate with the Logicmonitor Platform. It sends the log messages generated by the application, to the Logicmonitor platform.\n## Installation\n\n`go get -u github.com/logicmonitor/lm-zap-hook`\n\n## Quick Start\n\n### Authentication:\n\nSet the `LM_ACCESS_ID` and `LM_ACCESS_KEY` for using the LMv1 authentication. The company name or account name must be set to `LM_ACCOUNT` property. All properties can be set using environment variable.\n\n| Environment variable |\tDescription                                        |\n| -------------------- | ------------------------------------------------------|\n|   LM_ACCOUNT         | Account name (Company Name) is your organization name |\n|   LM_ACCESS_ID       | Access id while using LMv1 authentication.|\n|   LM_ACCESS_KEY      | Access key while using LMv1 authentication.|\n\n### Getting Started\n\nHere's an example code snippet for configuring the `lm-zap-hook` with the application code.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"time\"\n\n\tlmzaphook \"github.com/logicmonitor/lm-zap-hook\"\n\t\"go.uber.org/zap\"\n\t\"go.uber.org/zap/zapcore\"\n)\n\nfunc main() {\n\t// create a new Zap logger\n\tlogger, _ := zap.NewProduction()\n\tdefer logger.Sync() // flushes buffer, if any\n\n\t// create resource tags for mapping the log messages to a unique LogicMonitor resource\n\tresourceTags := map[string]string{\"system.displayname\": \"test-device\"}\n\n\t// create a new core that sends zapcore.WarnLevel and above messages to Logicmonitor Platform\n\tlmCore, err := lmzaphook.NewLMCore(context.Background(),\n\t\tlmzaphook.Params{ResourceMapperTags: resourceTags},\n\t\tlmzaphook.WithLogLevel(zapcore.WarnLevel),\n\t)\n\tif err != nil {\n\t\tlogger.Fatal(err.Error())\n\t}\n\n\t// Wrap a NewTee to send log messages to both your main logger and to Logicmonitor\n\tlogger = logger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {\n\t\treturn zapcore.NewTee(core, lmCore)\n\t}))\n\n\t// This info message will only go to the main logger\n\tlogger.Info(\"Test log message for main logger\", zap.String(\"foo\", \"bar\"))\n\n\t// This warning message will go to both the main logger and to Logicmonitor.\n\tlogger.Warn(\"Warning message with fields\", zap.String(\"foo\", \"bar\"))\n\n\t// By default, log send operations happens async way, so blocking the execution\n\ttime.Sleep(15 * time.Second)\n}\n\n```\n### Options\n\nFollowing are the options that can be passed to `NewLMCore()` to configure the `lmCore`.\n\n| Option                                     |   Description                                                                    |             \n|--------------------------------------------|----------------------------------------------------------------------------------|\n|   WithLogLevel(`logLevel zapcore.Level`)                   | Configures `lmCore` to send the logs having level equal or above the level specified by `logLevel`. Default logLevel is `Warning`. |\n|   WithClientBatchingInterval(`batchInterval time.Duration`) | Configures interval for batching of the log messages. |\n|   WithClientBatchingDisabled() | Disables the batching of log messages. By default, batching is enabled. |\n|   WithMetadata(`metadata map[string]string`)                   | Metadata to be sent with the every log message.                                    |\n|   WithNopLogIngesterClient()               | Configures `lmCore` to use the nopLogIngesterClient which discards the log messages. It can be used for testing.                          |\n|   WithBlocking()      | It makes the call to the send log operation blocking. Default value of Async Mode is `true`. |\n---\n\nCopyright, 2022, LogicMonitor, Inc.\n\nThis Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogicmonitor%2Flm-zap-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flogicmonitor%2Flm-zap-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogicmonitor%2Flm-zap-hook/lists"}