{"id":19484064,"url":"https://github.com/rookie-ninja/rk-logger","last_synced_at":"2025-04-25T16:33:18.355Z","repository":{"id":47108779,"uuid":"275989245","full_name":"rookie-ninja/rk-logger","owner":"rookie-ninja","description":"Log initializer written with goLang. See https://rkdev.info/docs/ for details.","archived":false,"fork":false,"pushed_at":"2022-12-19T17:50:18.000Z","size":64,"stargazers_count":6,"open_issues_count":1,"forks_count":4,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-06-18T20:12:02.802Z","etag":null,"topics":["go","golang","log","logger","logging","rk","zap"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rookie-ninja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-30T03:38:29.000Z","updated_at":"2024-06-18T20:12:02.802Z","dependencies_parsed_at":"2023-01-29T22:31:22.551Z","dependency_job_id":null,"html_url":"https://github.com/rookie-ninja/rk-logger","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rookie-ninja%2Frk-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rookie-ninja%2Frk-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rookie-ninja%2Frk-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rookie-ninja%2Frk-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rookie-ninja","download_url":"https://codeload.github.com/rookie-ninja/rk-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224008616,"owners_count":17240417,"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":["go","golang","log","logger","logging","rk","zap"],"created_at":"2024-11-10T20:19:05.638Z","updated_at":"2024-11-10T20:19:07.887Z","avatar_url":"https://github.com/rookie-ninja.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rk-logger\n[![build](https://github.com/rookie-ninja/rk-logger/actions/workflows/ci.yml/badge.svg)](https://github.com/rookie-ninja/rk-logger/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/rookie-ninja/rk-logger/branch/master/graph/badge.svg?token=QQ5WZ5JBD4)](https://codecov.io/gh/rookie-ninja/rk-logger)\n[![Go Report Card](https://goreportcard.com/badge/github.com/rookie-ninja/rk-logger)](https://goreportcard.com/report/github.com/rookie-ninja/rk-logger)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nLog initializer written with golang.\nCurrently, support zap logger as default logger and lumberjack as log rotation\n\n- [zap](https://github.com/uber-go/zap)\n- [lumberjack](https://github.com/natefinch/lumberjack)\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*\n\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n  - [With Config file path](#with-config-file-path)\n  - [With Config as byte array](#with-config-as-byte-array)\n  - [With Config](#with-config)\n  - [Development Status: Stable](#development-status-stable)\n  - [Contributing](#contributing)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Installation\n`go get -u github.com/rookie-ninja/rk-logger`\n\n## Quick Start\nWe combined zap config and lumberjack config in the same config file\nBoth of the configs could keep same format as it \n\nIn order to init zap logger with full log rotation, rk-logger support three different utility functions\n- With zap+lumberjack config file path\n- With zap+lumberjack config as byte array\n- With zap config and lumberjack config\n\n### With Config file path\nconfig:\n```yaml\n---\nlevel: debug\nencoding: console\noutputPaths:\n  - stdout\n  - logs/rk-logger.log\nerrorOutputPaths:\n  - stderr\ninitialFields:\n  initFieldKey: fieldValue\nencoderConfig:\n  messageKey: messagea\n  levelKey: level\n  nameKey: logger\n  timeKey: time\n  callerKey: caller\n  stacktraceKey: stacktrace\n  callstackKey: callstack\n  errorKey: error\n  timeEncoder: iso8601\n  fileKey: file\n  levelEncoder: capital\n  durationEncoder: second\n  callerEncoder: full\n  nameEncoder: full\n  sampling:\n    initial: '3'\n    thereafter: '10'\nmaxsize: 1\nmaxage: 7\nmaxbackups: 3\nlocaltime: true\ncompress: true\n```\n\nExample:\n```go\nfunc NewZapLoggerWithConfPathExample() {\n    // get current working directory\n    dir, _ := os.Getwd()\n\n    // init logger \n    logger, _, _ := rk_logger.NewZapLoggerWithConfPath(path.Clean(path.Join(dir, \"/assets/zap.yaml\")), rk_logger.YAML)\n    \n    // use it \n    logger.Info(\"NewZapLoggerWithConfPathExample\")\n}\n```\n### With Config as byte array\nExample:\n```go\nfunc NewZapLoggerWithBytesExample() {\n    bytes := []byte(`{\n      \"level\": \"debug\",\n      \"encoding\": \"console\",\n      \"outputPaths\": [\"stdout\", \"logs/rk-logger.log\"],\n      \"errorOutputPaths\": [\"stderr\"],\n      \"initialFields\": {\"initFieldKey\": \"fieldValue\"},\n      \"encoderConfig\": {\n        \"messageKey\": \"message\",\n        \"levelKey\": \"level\",\n        \"nameKey\": \"logger\",\n        \"timeKey\": \"time\",\n        \"callerKey\": \"caller\",\n        \"stacktraceKey\": \"stacktrace\",\n        \"callstackKey\": \"callstack\",\n        \"errorKey\": \"error\",\n        \"timeEncoder\": \"iso8601\",\n        \"fileKey\": \"file\",\n        \"levelEncoder\": \"capital\",\n        \"durationEncoder\": \"second\",\n        \"callerEncoder\": \"full\",\n        \"nameEncoder\": \"full\",\n        \"sampling\": {\n            \"initial\": \"3\",\n            \"thereafter\": \"10\"\n        }\n      },\n      \"maxsize\": 1,\n      \"maxage\": 7,\n      \"maxbackups\": 3,\n      \"localtime\": true,\n      \"compress\": true\n    }`)\n\n    logger, _, err := rk_logger.NewZapLoggerWithBytes(bytes, rk_logger.JSON)\n    \n    logger.Info(\"NewZapLoggerWithBytesExample\")\n}\n```\n### With Config\n```go\nfunc NewZapLoggerWithConfExample() {\n    encodingConfig := zapcore.EncoderConfig{\n        TimeKey:        \"zap_timestamp\",\n        LevelKey:       \"level\",\n        NameKey:        \"logger\",\n        CallerKey:      \"caller\",\n        MessageKey:     \"msg\",\n        StacktraceKey:  \"stacktrace\",\n        LineEnding:     zapcore.DefaultLineEnding,\n        EncodeLevel:    zapcore.CapitalLevelEncoder,\n        EncodeTime:     zapcore.ISO8601TimeEncoder,\n        EncodeDuration: zapcore.SecondsDurationEncoder,\n        EncodeCaller:   zapcore.ShortCallerEncoder,\n    }\n    \n    config := \u0026zap.Config{\n        Level: zap.NewAtomicLevelAt(zap.InfoLevel),\n        EncoderConfig: encodingConfig,\n        OutputPaths: []string{\"stdout\", \"logs/rk-logger.log\"},\n    }\n\n    logger, _ := rk_logger.NewZapLoggerWithConf(config, \u0026lumberjack.Logger{})\n    logger.Info(\"NewZapLoggerWithConfExample\")\n}\n```\n\n### Development Status: Stable\n\n### Contributing\nWe encourage and support an active, healthy community of contributors \u0026mdash;\nincluding you! Details are in the [contribution guide](CONTRIBUTING.md) and\nthe [code of conduct](CODE_OF_CONDUCT.md). The rk maintainers keep an eye on\nissues and pull requests, but you can also report any negative conduct to\nlark@rkdev.info.\n\n\u003chr\u003e\n\nReleased under the [Apache 2.0 License](LICENSE).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frookie-ninja%2Frk-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frookie-ninja%2Frk-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frookie-ninja%2Frk-logger/lists"}