planetscale 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +24 -0
- data/.github/workflows/gem-push.yml +38 -0
- data/.github/workflows/licensed.yml +43 -0
- data/.gitignore +10 -0
- data/.licensed.yml +9 -0
- data/.licenses/go/github.com/armon/circbuf.dep.yml +31 -0
- data/.licenses/go/github.com/gorilla/mux.dep.yml +41 -0
- data/.licenses/go/github.com/hashicorp/go-cleanhttp.dep.yml +375 -0
- data/.licenses/go/github.com/mitchellh/go-homedir.dep.yml +32 -0
- data/.licenses/go/github.com/pkg/errors.dep.yml +36 -0
- data/.licenses/go/github.com/planetscale/planetscale-go/planetscale.dep.yml +160 -0
- data/.licenses/go/github.com/planetscale/sql-proxy/proxy.dep.yml +180 -0
- data/.licenses/go/go.uber.org/atomic.dep.yml +31 -0
- data/.licenses/go/go.uber.org/multierr.dep.yml +30 -0
- data/.licenses/go/go.uber.org/zap.dep.yml +30 -0
- data/.licenses/go/go.uber.org/zap/buffer.dep.yml +30 -0
- data/.licenses/go/go.uber.org/zap/internal/bufferpool.dep.yml +30 -0
- data/.licenses/go/go.uber.org/zap/internal/color.dep.yml +30 -0
- data/.licenses/go/go.uber.org/zap/internal/exit.dep.yml +31 -0
- data/.licenses/go/go.uber.org/zap/zapcore.dep.yml +31 -0
- data/.licenses/go/golang.org/x/net/context/ctxhttp.dep.yml +63 -0
- data/.licenses/go/golang.org/x/oauth2.dep.yml +44 -0
- data/.licenses/go/golang.org/x/oauth2/internal.dep.yml +38 -0
- data/.ruby_version +1 -0
- data/Gemfile +8 -0
- data/LICENSE +201 -0
- data/README.md +88 -0
- data/Rakefile +10 -0
- data/bin/console +15 -0
- data/bin/setup +17 -0
- data/controller.go +255 -0
- data/go.mod +16 -0
- data/go.sum +428 -0
- data/lib/generators/planetscale/install_generator.rb +58 -0
- data/lib/planetscale.rb +137 -0
- data/lib/planetscale/version.rb +5 -0
- data/planetscale.gemspec +44 -0
- data/proxy.go +128 -0
- data/vendor/github.com/armon/circbuf/.gitignore +22 -0
- data/vendor/github.com/armon/circbuf/LICENSE +20 -0
- data/vendor/github.com/armon/circbuf/README.md +28 -0
- data/vendor/github.com/armon/circbuf/circbuf.go +92 -0
- data/vendor/github.com/armon/circbuf/go.mod +1 -0
- data/vendor/github.com/golang/protobuf/AUTHORS +3 -0
- data/vendor/github.com/golang/protobuf/CONTRIBUTORS +3 -0
- data/vendor/github.com/golang/protobuf/LICENSE +28 -0
- data/vendor/github.com/golang/protobuf/proto/buffer.go +324 -0
- data/vendor/github.com/golang/protobuf/proto/defaults.go +63 -0
- data/vendor/github.com/golang/protobuf/proto/deprecated.go +113 -0
- data/vendor/github.com/golang/protobuf/proto/discard.go +58 -0
- data/vendor/github.com/golang/protobuf/proto/extensions.go +356 -0
- data/vendor/github.com/golang/protobuf/proto/properties.go +306 -0
- data/vendor/github.com/golang/protobuf/proto/proto.go +167 -0
- data/vendor/github.com/golang/protobuf/proto/registry.go +317 -0
- data/vendor/github.com/golang/protobuf/proto/text_decode.go +801 -0
- data/vendor/github.com/golang/protobuf/proto/text_encode.go +560 -0
- data/vendor/github.com/golang/protobuf/proto/wire.go +78 -0
- data/vendor/github.com/golang/protobuf/proto/wrappers.go +34 -0
- data/vendor/github.com/gorilla/mux/AUTHORS +8 -0
- data/vendor/github.com/gorilla/mux/LICENSE +27 -0
- data/vendor/github.com/gorilla/mux/README.md +805 -0
- data/vendor/github.com/gorilla/mux/doc.go +306 -0
- data/vendor/github.com/gorilla/mux/go.mod +3 -0
- data/vendor/github.com/gorilla/mux/middleware.go +74 -0
- data/vendor/github.com/gorilla/mux/mux.go +606 -0
- data/vendor/github.com/gorilla/mux/regexp.go +388 -0
- data/vendor/github.com/gorilla/mux/route.go +736 -0
- data/vendor/github.com/gorilla/mux/test_helpers.go +19 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/LICENSE +363 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/README.md +30 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go +58 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/doc.go +20 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/go.mod +3 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/handlers.go +48 -0
- data/vendor/github.com/mitchellh/go-homedir/LICENSE +21 -0
- data/vendor/github.com/mitchellh/go-homedir/README.md +14 -0
- data/vendor/github.com/mitchellh/go-homedir/go.mod +1 -0
- data/vendor/github.com/mitchellh/go-homedir/homedir.go +167 -0
- data/vendor/github.com/pkg/errors/.gitignore +24 -0
- data/vendor/github.com/pkg/errors/.travis.yml +10 -0
- data/vendor/github.com/pkg/errors/LICENSE +23 -0
- data/vendor/github.com/pkg/errors/Makefile +44 -0
- data/vendor/github.com/pkg/errors/README.md +59 -0
- data/vendor/github.com/pkg/errors/appveyor.yml +32 -0
- data/vendor/github.com/pkg/errors/errors.go +288 -0
- data/vendor/github.com/pkg/errors/go113.go +38 -0
- data/vendor/github.com/pkg/errors/stack.go +177 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/backups.go +139 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/branches.go +258 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/certs.go +142 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/client.go +305 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/databases.go +131 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/deploy_requests.go +368 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/organizations.go +78 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/service_tokens.go +163 -0
- data/vendor/github.com/planetscale/sql-proxy/proxy/client.go +467 -0
- data/vendor/github.com/planetscale/sql-proxy/proxy/tls_cache.go +73 -0
- data/vendor/go.uber.org/atomic/.codecov.yml +19 -0
- data/vendor/go.uber.org/atomic/.gitignore +12 -0
- data/vendor/go.uber.org/atomic/.travis.yml +27 -0
- data/vendor/go.uber.org/atomic/CHANGELOG.md +76 -0
- data/vendor/go.uber.org/atomic/LICENSE.txt +19 -0
- data/vendor/go.uber.org/atomic/Makefile +78 -0
- data/vendor/go.uber.org/atomic/README.md +63 -0
- data/vendor/go.uber.org/atomic/bool.go +81 -0
- data/vendor/go.uber.org/atomic/bool_ext.go +53 -0
- data/vendor/go.uber.org/atomic/doc.go +23 -0
- data/vendor/go.uber.org/atomic/duration.go +82 -0
- data/vendor/go.uber.org/atomic/duration_ext.go +40 -0
- data/vendor/go.uber.org/atomic/error.go +51 -0
- data/vendor/go.uber.org/atomic/error_ext.go +39 -0
- data/vendor/go.uber.org/atomic/float64.go +76 -0
- data/vendor/go.uber.org/atomic/float64_ext.go +47 -0
- data/vendor/go.uber.org/atomic/gen.go +26 -0
- data/vendor/go.uber.org/atomic/go.mod +8 -0
- data/vendor/go.uber.org/atomic/go.sum +9 -0
- data/vendor/go.uber.org/atomic/int32.go +102 -0
- data/vendor/go.uber.org/atomic/int64.go +102 -0
- data/vendor/go.uber.org/atomic/nocmp.go +35 -0
- data/vendor/go.uber.org/atomic/string.go +54 -0
- data/vendor/go.uber.org/atomic/string_ext.go +43 -0
- data/vendor/go.uber.org/atomic/uint32.go +102 -0
- data/vendor/go.uber.org/atomic/uint64.go +102 -0
- data/vendor/go.uber.org/atomic/value.go +31 -0
- data/vendor/go.uber.org/multierr/.codecov.yml +15 -0
- data/vendor/go.uber.org/multierr/.gitignore +4 -0
- data/vendor/go.uber.org/multierr/.travis.yml +23 -0
- data/vendor/go.uber.org/multierr/CHANGELOG.md +60 -0
- data/vendor/go.uber.org/multierr/LICENSE.txt +19 -0
- data/vendor/go.uber.org/multierr/Makefile +42 -0
- data/vendor/go.uber.org/multierr/README.md +23 -0
- data/vendor/go.uber.org/multierr/error.go +449 -0
- data/vendor/go.uber.org/multierr/glide.yaml +8 -0
- data/vendor/go.uber.org/multierr/go.mod +8 -0
- data/vendor/go.uber.org/multierr/go.sum +11 -0
- data/vendor/go.uber.org/multierr/go113.go +52 -0
- data/vendor/go.uber.org/zap/.codecov.yml +17 -0
- data/vendor/go.uber.org/zap/.gitignore +32 -0
- data/vendor/go.uber.org/zap/.readme.tmpl +109 -0
- data/vendor/go.uber.org/zap/.travis.yml +23 -0
- data/vendor/go.uber.org/zap/CHANGELOG.md +432 -0
- data/vendor/go.uber.org/zap/CODE_OF_CONDUCT.md +75 -0
- data/vendor/go.uber.org/zap/CONTRIBUTING.md +81 -0
- data/vendor/go.uber.org/zap/FAQ.md +156 -0
- data/vendor/go.uber.org/zap/LICENSE.txt +19 -0
- data/vendor/go.uber.org/zap/Makefile +63 -0
- data/vendor/go.uber.org/zap/README.md +134 -0
- data/vendor/go.uber.org/zap/array.go +320 -0
- data/vendor/go.uber.org/zap/buffer/buffer.go +123 -0
- data/vendor/go.uber.org/zap/buffer/pool.go +49 -0
- data/vendor/go.uber.org/zap/checklicense.sh +17 -0
- data/vendor/go.uber.org/zap/config.go +264 -0
- data/vendor/go.uber.org/zap/doc.go +113 -0
- data/vendor/go.uber.org/zap/encoder.go +79 -0
- data/vendor/go.uber.org/zap/error.go +80 -0
- data/vendor/go.uber.org/zap/field.go +539 -0
- data/vendor/go.uber.org/zap/flag.go +39 -0
- data/vendor/go.uber.org/zap/glide.yaml +34 -0
- data/vendor/go.uber.org/zap/global.go +168 -0
- data/vendor/go.uber.org/zap/global_go112.go +26 -0
- data/vendor/go.uber.org/zap/global_prego112.go +26 -0
- data/vendor/go.uber.org/zap/go.mod +13 -0
- data/vendor/go.uber.org/zap/go.sum +56 -0
- data/vendor/go.uber.org/zap/http_handler.go +81 -0
- data/vendor/go.uber.org/zap/internal/bufferpool/bufferpool.go +31 -0
- data/vendor/go.uber.org/zap/internal/color/color.go +44 -0
- data/vendor/go.uber.org/zap/internal/exit/exit.go +64 -0
- data/vendor/go.uber.org/zap/level.go +132 -0
- data/vendor/go.uber.org/zap/logger.go +344 -0
- data/vendor/go.uber.org/zap/options.go +140 -0
- data/vendor/go.uber.org/zap/sink.go +161 -0
- data/vendor/go.uber.org/zap/stacktrace.go +85 -0
- data/vendor/go.uber.org/zap/sugar.go +304 -0
- data/vendor/go.uber.org/zap/time.go +27 -0
- data/vendor/go.uber.org/zap/writer.go +99 -0
- data/vendor/go.uber.org/zap/zapcore/console_encoder.go +161 -0
- data/vendor/go.uber.org/zap/zapcore/core.go +113 -0
- data/vendor/go.uber.org/zap/zapcore/doc.go +24 -0
- data/vendor/go.uber.org/zap/zapcore/encoder.go +443 -0
- data/vendor/go.uber.org/zap/zapcore/entry.go +264 -0
- data/vendor/go.uber.org/zap/zapcore/error.go +115 -0
- data/vendor/go.uber.org/zap/zapcore/field.go +227 -0
- data/vendor/go.uber.org/zap/zapcore/hook.go +68 -0
- data/vendor/go.uber.org/zap/zapcore/increase_level.go +66 -0
- data/vendor/go.uber.org/zap/zapcore/json_encoder.go +534 -0
- data/vendor/go.uber.org/zap/zapcore/level.go +175 -0
- data/vendor/go.uber.org/zap/zapcore/level_strings.go +46 -0
- data/vendor/go.uber.org/zap/zapcore/marshaler.go +61 -0
- data/vendor/go.uber.org/zap/zapcore/memory_encoder.go +179 -0
- data/vendor/go.uber.org/zap/zapcore/sampler.go +208 -0
- data/vendor/go.uber.org/zap/zapcore/tee.go +81 -0
- data/vendor/go.uber.org/zap/zapcore/write_syncer.go +123 -0
- data/vendor/golang.org/x/net/AUTHORS +3 -0
- data/vendor/golang.org/x/net/CONTRIBUTORS +3 -0
- data/vendor/golang.org/x/net/LICENSE +27 -0
- data/vendor/golang.org/x/net/PATENTS +22 -0
- data/vendor/golang.org/x/net/context/context.go +56 -0
- data/vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go +71 -0
- data/vendor/golang.org/x/net/context/go17.go +73 -0
- data/vendor/golang.org/x/net/context/go19.go +21 -0
- data/vendor/golang.org/x/net/context/pre_go17.go +301 -0
- data/vendor/golang.org/x/net/context/pre_go19.go +110 -0
- data/vendor/golang.org/x/oauth2/.travis.yml +13 -0
- data/vendor/golang.org/x/oauth2/AUTHORS +3 -0
- data/vendor/golang.org/x/oauth2/CONTRIBUTING.md +26 -0
- data/vendor/golang.org/x/oauth2/CONTRIBUTORS +3 -0
- data/vendor/golang.org/x/oauth2/LICENSE +27 -0
- data/vendor/golang.org/x/oauth2/README.md +36 -0
- data/vendor/golang.org/x/oauth2/go.mod +9 -0
- data/vendor/golang.org/x/oauth2/go.sum +361 -0
- data/vendor/golang.org/x/oauth2/internal/client_appengine.go +14 -0
- data/vendor/golang.org/x/oauth2/internal/doc.go +6 -0
- data/vendor/golang.org/x/oauth2/internal/oauth2.go +37 -0
- data/vendor/golang.org/x/oauth2/internal/token.go +294 -0
- data/vendor/golang.org/x/oauth2/internal/transport.go +33 -0
- data/vendor/golang.org/x/oauth2/oauth2.go +381 -0
- data/vendor/golang.org/x/oauth2/token.go +178 -0
- data/vendor/golang.org/x/oauth2/transport.go +89 -0
- data/vendor/google.golang.org/appengine/LICENSE +202 -0
- data/vendor/google.golang.org/appengine/internal/api.go +678 -0
- data/vendor/google.golang.org/appengine/internal/api_classic.go +169 -0
- data/vendor/google.golang.org/appengine/internal/api_common.go +123 -0
- data/vendor/google.golang.org/appengine/internal/app_id.go +28 -0
- data/vendor/google.golang.org/appengine/internal/base/api_base.pb.go +308 -0
- data/vendor/google.golang.org/appengine/internal/base/api_base.proto +33 -0
- data/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.pb.go +4367 -0
- data/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.proto +551 -0
- data/vendor/google.golang.org/appengine/internal/identity.go +55 -0
- data/vendor/google.golang.org/appengine/internal/identity_classic.go +61 -0
- data/vendor/google.golang.org/appengine/internal/identity_flex.go +11 -0
- data/vendor/google.golang.org/appengine/internal/identity_vm.go +134 -0
- data/vendor/google.golang.org/appengine/internal/internal.go +110 -0
- data/vendor/google.golang.org/appengine/internal/log/log_service.pb.go +1313 -0
- data/vendor/google.golang.org/appengine/internal/log/log_service.proto +150 -0
- data/vendor/google.golang.org/appengine/internal/main.go +16 -0
- data/vendor/google.golang.org/appengine/internal/main_common.go +7 -0
- data/vendor/google.golang.org/appengine/internal/main_vm.go +69 -0
- data/vendor/google.golang.org/appengine/internal/metadata.go +60 -0
- data/vendor/google.golang.org/appengine/internal/net.go +56 -0
- data/vendor/google.golang.org/appengine/internal/regen.sh +40 -0
- data/vendor/google.golang.org/appengine/internal/remote_api/remote_api.pb.go +361 -0
- data/vendor/google.golang.org/appengine/internal/remote_api/remote_api.proto +44 -0
- data/vendor/google.golang.org/appengine/internal/transaction.go +115 -0
- data/vendor/google.golang.org/appengine/internal/urlfetch/urlfetch_service.pb.go +527 -0
- data/vendor/google.golang.org/appengine/internal/urlfetch/urlfetch_service.proto +64 -0
- data/vendor/google.golang.org/appengine/urlfetch/urlfetch.go +210 -0
- data/vendor/google.golang.org/protobuf/AUTHORS +3 -0
- data/vendor/google.golang.org/protobuf/CONTRIBUTORS +3 -0
- data/vendor/google.golang.org/protobuf/LICENSE +27 -0
- data/vendor/google.golang.org/protobuf/PATENTS +22 -0
- data/vendor/google.golang.org/protobuf/encoding/prototext/decode.go +773 -0
- data/vendor/google.golang.org/protobuf/encoding/prototext/doc.go +7 -0
- data/vendor/google.golang.org/protobuf/encoding/prototext/encode.go +371 -0
- data/vendor/google.golang.org/protobuf/encoding/protowire/wire.go +538 -0
- data/vendor/google.golang.org/protobuf/internal/descfmt/stringer.go +318 -0
- data/vendor/google.golang.org/protobuf/internal/descopts/options.go +29 -0
- data/vendor/google.golang.org/protobuf/internal/detrand/rand.go +69 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/defval/default.go +213 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/messageset/messageset.go +241 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/tag/tag.go +207 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/decode.go +665 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_number.go +190 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_string.go +161 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_token.go +373 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/doc.go +29 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/encode.go +265 -0
- data/vendor/google.golang.org/protobuf/internal/errors/errors.go +89 -0
- data/vendor/google.golang.org/protobuf/internal/errors/is_go112.go +39 -0
- data/vendor/google.golang.org/protobuf/internal/errors/is_go113.go +12 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/build.go +158 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/desc.go +631 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/desc_init.go +471 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/desc_lazy.go +704 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/desc_list.go +450 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/desc_list_gen.go +356 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/placeholder.go +107 -0
- data/vendor/google.golang.org/protobuf/internal/filetype/build.go +297 -0
- data/vendor/google.golang.org/protobuf/internal/flags/flags.go +24 -0
- data/vendor/google.golang.org/protobuf/internal/flags/proto_legacy_disable.go +9 -0
- data/vendor/google.golang.org/protobuf/internal/flags/proto_legacy_enable.go +9 -0
- data/vendor/google.golang.org/protobuf/internal/genid/any_gen.go +34 -0
- data/vendor/google.golang.org/protobuf/internal/genid/api_gen.go +106 -0
- data/vendor/google.golang.org/protobuf/internal/genid/descriptor_gen.go +829 -0
- data/vendor/google.golang.org/protobuf/internal/genid/doc.go +11 -0
- data/vendor/google.golang.org/protobuf/internal/genid/duration_gen.go +34 -0
- data/vendor/google.golang.org/protobuf/internal/genid/empty_gen.go +19 -0
- data/vendor/google.golang.org/protobuf/internal/genid/field_mask_gen.go +31 -0
- data/vendor/google.golang.org/protobuf/internal/genid/goname.go +25 -0
- data/vendor/google.golang.org/protobuf/internal/genid/map_entry.go +16 -0
- data/vendor/google.golang.org/protobuf/internal/genid/source_context_gen.go +31 -0
- data/vendor/google.golang.org/protobuf/internal/genid/struct_gen.go +116 -0
- data/vendor/google.golang.org/protobuf/internal/genid/timestamp_gen.go +34 -0
- data/vendor/google.golang.org/protobuf/internal/genid/type_gen.go +184 -0
- data/vendor/google.golang.org/protobuf/internal/genid/wrappers.go +13 -0
- data/vendor/google.golang.org/protobuf/internal/genid/wrappers_gen.go +175 -0
- data/vendor/google.golang.org/protobuf/internal/impl/api_export.go +177 -0
- data/vendor/google.golang.org/protobuf/internal/impl/checkinit.go +141 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_extension.go +223 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_field.go +830 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_gen.go +5637 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_map.go +388 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_map_go111.go +37 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_map_go112.go +11 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_message.go +217 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_messageset.go +123 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_reflect.go +209 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_tables.go +557 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_unsafe.go +17 -0
- data/vendor/google.golang.org/protobuf/internal/impl/convert.go +496 -0
- data/vendor/google.golang.org/protobuf/internal/impl/convert_list.go +141 -0
- data/vendor/google.golang.org/protobuf/internal/impl/convert_map.go +121 -0
- data/vendor/google.golang.org/protobuf/internal/impl/decode.go +276 -0
- data/vendor/google.golang.org/protobuf/internal/impl/encode.go +201 -0
- data/vendor/google.golang.org/protobuf/internal/impl/enum.go +21 -0
- data/vendor/google.golang.org/protobuf/internal/impl/extension.go +156 -0
- data/vendor/google.golang.org/protobuf/internal/impl/legacy_enum.go +219 -0
- data/vendor/google.golang.org/protobuf/internal/impl/legacy_export.go +92 -0
- data/vendor/google.golang.org/protobuf/internal/impl/legacy_extension.go +176 -0
- data/vendor/google.golang.org/protobuf/internal/impl/legacy_file.go +81 -0
- data/vendor/google.golang.org/protobuf/internal/impl/legacy_message.go +558 -0
- data/vendor/google.golang.org/protobuf/internal/impl/merge.go +176 -0
- data/vendor/google.golang.org/protobuf/internal/impl/merge_gen.go +209 -0
- data/vendor/google.golang.org/protobuf/internal/impl/message.go +276 -0
- data/vendor/google.golang.org/protobuf/internal/impl/message_reflect.go +465 -0
- data/vendor/google.golang.org/protobuf/internal/impl/message_reflect_field.go +543 -0
- data/vendor/google.golang.org/protobuf/internal/impl/message_reflect_gen.go +249 -0
- data/vendor/google.golang.org/protobuf/internal/impl/pointer_reflect.go +178 -0
- data/vendor/google.golang.org/protobuf/internal/impl/pointer_unsafe.go +174 -0
- data/vendor/google.golang.org/protobuf/internal/impl/validate.go +576 -0
- data/vendor/google.golang.org/protobuf/internal/impl/weak.go +74 -0
- data/vendor/google.golang.org/protobuf/internal/order/order.go +89 -0
- data/vendor/google.golang.org/protobuf/internal/order/range.go +115 -0
- data/vendor/google.golang.org/protobuf/internal/pragma/pragma.go +29 -0
- data/vendor/google.golang.org/protobuf/internal/set/ints.go +58 -0
- data/vendor/google.golang.org/protobuf/internal/strs/strings.go +196 -0
- data/vendor/google.golang.org/protobuf/internal/strs/strings_pure.go +27 -0
- data/vendor/google.golang.org/protobuf/internal/strs/strings_unsafe.go +94 -0
- data/vendor/google.golang.org/protobuf/internal/version/version.go +79 -0
- data/vendor/google.golang.org/protobuf/proto/checkinit.go +71 -0
- data/vendor/google.golang.org/protobuf/proto/decode.go +278 -0
- data/vendor/google.golang.org/protobuf/proto/decode_gen.go +603 -0
- data/vendor/google.golang.org/protobuf/proto/doc.go +94 -0
- data/vendor/google.golang.org/protobuf/proto/encode.go +319 -0
- data/vendor/google.golang.org/protobuf/proto/encode_gen.go +97 -0
- data/vendor/google.golang.org/protobuf/proto/equal.go +167 -0
- data/vendor/google.golang.org/protobuf/proto/extension.go +92 -0
- data/vendor/google.golang.org/protobuf/proto/merge.go +139 -0
- data/vendor/google.golang.org/protobuf/proto/messageset.go +93 -0
- data/vendor/google.golang.org/protobuf/proto/proto.go +43 -0
- data/vendor/google.golang.org/protobuf/proto/proto_methods.go +19 -0
- data/vendor/google.golang.org/protobuf/proto/proto_reflect.go +19 -0
- data/vendor/google.golang.org/protobuf/proto/reset.go +43 -0
- data/vendor/google.golang.org/protobuf/proto/size.go +97 -0
- data/vendor/google.golang.org/protobuf/proto/size_gen.go +55 -0
- data/vendor/google.golang.org/protobuf/proto/wrappers.go +29 -0
- data/vendor/google.golang.org/protobuf/reflect/protodesc/desc.go +276 -0
- data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go +248 -0
- data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_resolve.go +286 -0
- data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_validate.go +374 -0
- data/vendor/google.golang.org/protobuf/reflect/protodesc/proto.go +252 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/methods.go +77 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/proto.go +504 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/source.go +128 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go +461 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go +665 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/value.go +285 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_pure.go +59 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go +411 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe.go +98 -0
- data/vendor/google.golang.org/protobuf/reflect/protoregistry/registry.go +869 -0
- data/vendor/google.golang.org/protobuf/runtime/protoiface/legacy.go +15 -0
- data/vendor/google.golang.org/protobuf/runtime/protoiface/methods.go +167 -0
- data/vendor/google.golang.org/protobuf/runtime/protoimpl/impl.go +44 -0
- data/vendor/google.golang.org/protobuf/runtime/protoimpl/version.go +56 -0
- data/vendor/google.golang.org/protobuf/types/descriptorpb/descriptor.pb.go +4039 -0
- data/vendor/modules.txt +79 -0
- metadata +495 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright (c) 2016 Uber Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
|
11
|
+
// all copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
// THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
package zap
|
|
22
|
+
|
|
23
|
+
import "time"
|
|
24
|
+
|
|
25
|
+
func timeToMillis(t time.Time) int64 {
|
|
26
|
+
return t.UnixNano() / int64(time.Millisecond)
|
|
27
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright (c) 2016 Uber Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
|
11
|
+
// all copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
// THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
package zap
|
|
22
|
+
|
|
23
|
+
import (
|
|
24
|
+
"fmt"
|
|
25
|
+
"io"
|
|
26
|
+
"io/ioutil"
|
|
27
|
+
|
|
28
|
+
"go.uber.org/zap/zapcore"
|
|
29
|
+
|
|
30
|
+
"go.uber.org/multierr"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
// Open is a high-level wrapper that takes a variadic number of URLs, opens or
|
|
34
|
+
// creates each of the specified resources, and combines them into a locked
|
|
35
|
+
// WriteSyncer. It also returns any error encountered and a function to close
|
|
36
|
+
// any opened files.
|
|
37
|
+
//
|
|
38
|
+
// Passing no URLs returns a no-op WriteSyncer. Zap handles URLs without a
|
|
39
|
+
// scheme and URLs with the "file" scheme. Third-party code may register
|
|
40
|
+
// factories for other schemes using RegisterSink.
|
|
41
|
+
//
|
|
42
|
+
// URLs with the "file" scheme must use absolute paths on the local
|
|
43
|
+
// filesystem. No user, password, port, fragments, or query parameters are
|
|
44
|
+
// allowed, and the hostname must be empty or "localhost".
|
|
45
|
+
//
|
|
46
|
+
// Since it's common to write logs to the local filesystem, URLs without a
|
|
47
|
+
// scheme (e.g., "/var/log/foo.log") are treated as local file paths. Without
|
|
48
|
+
// a scheme, the special paths "stdout" and "stderr" are interpreted as
|
|
49
|
+
// os.Stdout and os.Stderr. When specified without a scheme, relative file
|
|
50
|
+
// paths also work.
|
|
51
|
+
func Open(paths ...string) (zapcore.WriteSyncer, func(), error) {
|
|
52
|
+
writers, close, err := open(paths)
|
|
53
|
+
if err != nil {
|
|
54
|
+
return nil, nil, err
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
writer := CombineWriteSyncers(writers...)
|
|
58
|
+
return writer, close, nil
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
func open(paths []string) ([]zapcore.WriteSyncer, func(), error) {
|
|
62
|
+
writers := make([]zapcore.WriteSyncer, 0, len(paths))
|
|
63
|
+
closers := make([]io.Closer, 0, len(paths))
|
|
64
|
+
close := func() {
|
|
65
|
+
for _, c := range closers {
|
|
66
|
+
c.Close()
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
var openErr error
|
|
71
|
+
for _, path := range paths {
|
|
72
|
+
sink, err := newSink(path)
|
|
73
|
+
if err != nil {
|
|
74
|
+
openErr = multierr.Append(openErr, fmt.Errorf("couldn't open sink %q: %v", path, err))
|
|
75
|
+
continue
|
|
76
|
+
}
|
|
77
|
+
writers = append(writers, sink)
|
|
78
|
+
closers = append(closers, sink)
|
|
79
|
+
}
|
|
80
|
+
if openErr != nil {
|
|
81
|
+
close()
|
|
82
|
+
return writers, nil, openErr
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return writers, close, nil
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// CombineWriteSyncers is a utility that combines multiple WriteSyncers into a
|
|
89
|
+
// single, locked WriteSyncer. If no inputs are supplied, it returns a no-op
|
|
90
|
+
// WriteSyncer.
|
|
91
|
+
//
|
|
92
|
+
// It's provided purely as a convenience; the result is no different from
|
|
93
|
+
// using zapcore.NewMultiWriteSyncer and zapcore.Lock individually.
|
|
94
|
+
func CombineWriteSyncers(writers ...zapcore.WriteSyncer) zapcore.WriteSyncer {
|
|
95
|
+
if len(writers) == 0 {
|
|
96
|
+
return zapcore.AddSync(ioutil.Discard)
|
|
97
|
+
}
|
|
98
|
+
return zapcore.Lock(zapcore.NewMultiWriteSyncer(writers...))
|
|
99
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Copyright (c) 2016 Uber Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
|
11
|
+
// all copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
// THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
package zapcore
|
|
22
|
+
|
|
23
|
+
import (
|
|
24
|
+
"fmt"
|
|
25
|
+
"sync"
|
|
26
|
+
|
|
27
|
+
"go.uber.org/zap/buffer"
|
|
28
|
+
"go.uber.org/zap/internal/bufferpool"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
var _sliceEncoderPool = sync.Pool{
|
|
32
|
+
New: func() interface{} {
|
|
33
|
+
return &sliceArrayEncoder{elems: make([]interface{}, 0, 2)}
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
func getSliceEncoder() *sliceArrayEncoder {
|
|
38
|
+
return _sliceEncoderPool.Get().(*sliceArrayEncoder)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
func putSliceEncoder(e *sliceArrayEncoder) {
|
|
42
|
+
e.elems = e.elems[:0]
|
|
43
|
+
_sliceEncoderPool.Put(e)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type consoleEncoder struct {
|
|
47
|
+
*jsonEncoder
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// NewConsoleEncoder creates an encoder whose output is designed for human -
|
|
51
|
+
// rather than machine - consumption. It serializes the core log entry data
|
|
52
|
+
// (message, level, timestamp, etc.) in a plain-text format and leaves the
|
|
53
|
+
// structured context as JSON.
|
|
54
|
+
//
|
|
55
|
+
// Note that although the console encoder doesn't use the keys specified in the
|
|
56
|
+
// encoder configuration, it will omit any element whose key is set to the empty
|
|
57
|
+
// string.
|
|
58
|
+
func NewConsoleEncoder(cfg EncoderConfig) Encoder {
|
|
59
|
+
if len(cfg.ConsoleSeparator) == 0 {
|
|
60
|
+
// Use a default delimiter of '\t' for backwards compatibility
|
|
61
|
+
cfg.ConsoleSeparator = "\t"
|
|
62
|
+
}
|
|
63
|
+
return consoleEncoder{newJSONEncoder(cfg, true)}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
func (c consoleEncoder) Clone() Encoder {
|
|
67
|
+
return consoleEncoder{c.jsonEncoder.Clone().(*jsonEncoder)}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
func (c consoleEncoder) EncodeEntry(ent Entry, fields []Field) (*buffer.Buffer, error) {
|
|
71
|
+
line := bufferpool.Get()
|
|
72
|
+
|
|
73
|
+
// We don't want the entry's metadata to be quoted and escaped (if it's
|
|
74
|
+
// encoded as strings), which means that we can't use the JSON encoder. The
|
|
75
|
+
// simplest option is to use the memory encoder and fmt.Fprint.
|
|
76
|
+
//
|
|
77
|
+
// If this ever becomes a performance bottleneck, we can implement
|
|
78
|
+
// ArrayEncoder for our plain-text format.
|
|
79
|
+
arr := getSliceEncoder()
|
|
80
|
+
if c.TimeKey != "" && c.EncodeTime != nil {
|
|
81
|
+
c.EncodeTime(ent.Time, arr)
|
|
82
|
+
}
|
|
83
|
+
if c.LevelKey != "" && c.EncodeLevel != nil {
|
|
84
|
+
c.EncodeLevel(ent.Level, arr)
|
|
85
|
+
}
|
|
86
|
+
if ent.LoggerName != "" && c.NameKey != "" {
|
|
87
|
+
nameEncoder := c.EncodeName
|
|
88
|
+
|
|
89
|
+
if nameEncoder == nil {
|
|
90
|
+
// Fall back to FullNameEncoder for backward compatibility.
|
|
91
|
+
nameEncoder = FullNameEncoder
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
nameEncoder(ent.LoggerName, arr)
|
|
95
|
+
}
|
|
96
|
+
if ent.Caller.Defined {
|
|
97
|
+
if c.CallerKey != "" && c.EncodeCaller != nil {
|
|
98
|
+
c.EncodeCaller(ent.Caller, arr)
|
|
99
|
+
}
|
|
100
|
+
if c.FunctionKey != "" {
|
|
101
|
+
arr.AppendString(ent.Caller.Function)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
for i := range arr.elems {
|
|
105
|
+
if i > 0 {
|
|
106
|
+
line.AppendString(c.ConsoleSeparator)
|
|
107
|
+
}
|
|
108
|
+
fmt.Fprint(line, arr.elems[i])
|
|
109
|
+
}
|
|
110
|
+
putSliceEncoder(arr)
|
|
111
|
+
|
|
112
|
+
// Add the message itself.
|
|
113
|
+
if c.MessageKey != "" {
|
|
114
|
+
c.addSeparatorIfNecessary(line)
|
|
115
|
+
line.AppendString(ent.Message)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Add any structured context.
|
|
119
|
+
c.writeContext(line, fields)
|
|
120
|
+
|
|
121
|
+
// If there's no stacktrace key, honor that; this allows users to force
|
|
122
|
+
// single-line output.
|
|
123
|
+
if ent.Stack != "" && c.StacktraceKey != "" {
|
|
124
|
+
line.AppendByte('\n')
|
|
125
|
+
line.AppendString(ent.Stack)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if c.LineEnding != "" {
|
|
129
|
+
line.AppendString(c.LineEnding)
|
|
130
|
+
} else {
|
|
131
|
+
line.AppendString(DefaultLineEnding)
|
|
132
|
+
}
|
|
133
|
+
return line, nil
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
func (c consoleEncoder) writeContext(line *buffer.Buffer, extra []Field) {
|
|
137
|
+
context := c.jsonEncoder.Clone().(*jsonEncoder)
|
|
138
|
+
defer func() {
|
|
139
|
+
// putJSONEncoder assumes the buffer is still used, but we write out the buffer so
|
|
140
|
+
// we can free it.
|
|
141
|
+
context.buf.Free()
|
|
142
|
+
putJSONEncoder(context)
|
|
143
|
+
}()
|
|
144
|
+
|
|
145
|
+
addFields(context, extra)
|
|
146
|
+
context.closeOpenNamespaces()
|
|
147
|
+
if context.buf.Len() == 0 {
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
c.addSeparatorIfNecessary(line)
|
|
152
|
+
line.AppendByte('{')
|
|
153
|
+
line.Write(context.buf.Bytes())
|
|
154
|
+
line.AppendByte('}')
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
func (c consoleEncoder) addSeparatorIfNecessary(line *buffer.Buffer) {
|
|
158
|
+
if line.Len() > 0 {
|
|
159
|
+
line.AppendString(c.ConsoleSeparator)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Copyright (c) 2016 Uber Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
|
11
|
+
// all copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
// THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
package zapcore
|
|
22
|
+
|
|
23
|
+
// Core is a minimal, fast logger interface. It's designed for library authors
|
|
24
|
+
// to wrap in a more user-friendly API.
|
|
25
|
+
type Core interface {
|
|
26
|
+
LevelEnabler
|
|
27
|
+
|
|
28
|
+
// With adds structured context to the Core.
|
|
29
|
+
With([]Field) Core
|
|
30
|
+
// Check determines whether the supplied Entry should be logged (using the
|
|
31
|
+
// embedded LevelEnabler and possibly some extra logic). If the entry
|
|
32
|
+
// should be logged, the Core adds itself to the CheckedEntry and returns
|
|
33
|
+
// the result.
|
|
34
|
+
//
|
|
35
|
+
// Callers must use Check before calling Write.
|
|
36
|
+
Check(Entry, *CheckedEntry) *CheckedEntry
|
|
37
|
+
// Write serializes the Entry and any Fields supplied at the log site and
|
|
38
|
+
// writes them to their destination.
|
|
39
|
+
//
|
|
40
|
+
// If called, Write should always log the Entry and Fields; it should not
|
|
41
|
+
// replicate the logic of Check.
|
|
42
|
+
Write(Entry, []Field) error
|
|
43
|
+
// Sync flushes buffered logs (if any).
|
|
44
|
+
Sync() error
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type nopCore struct{}
|
|
48
|
+
|
|
49
|
+
// NewNopCore returns a no-op Core.
|
|
50
|
+
func NewNopCore() Core { return nopCore{} }
|
|
51
|
+
func (nopCore) Enabled(Level) bool { return false }
|
|
52
|
+
func (n nopCore) With([]Field) Core { return n }
|
|
53
|
+
func (nopCore) Check(_ Entry, ce *CheckedEntry) *CheckedEntry { return ce }
|
|
54
|
+
func (nopCore) Write(Entry, []Field) error { return nil }
|
|
55
|
+
func (nopCore) Sync() error { return nil }
|
|
56
|
+
|
|
57
|
+
// NewCore creates a Core that writes logs to a WriteSyncer.
|
|
58
|
+
func NewCore(enc Encoder, ws WriteSyncer, enab LevelEnabler) Core {
|
|
59
|
+
return &ioCore{
|
|
60
|
+
LevelEnabler: enab,
|
|
61
|
+
enc: enc,
|
|
62
|
+
out: ws,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type ioCore struct {
|
|
67
|
+
LevelEnabler
|
|
68
|
+
enc Encoder
|
|
69
|
+
out WriteSyncer
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
func (c *ioCore) With(fields []Field) Core {
|
|
73
|
+
clone := c.clone()
|
|
74
|
+
addFields(clone.enc, fields)
|
|
75
|
+
return clone
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func (c *ioCore) Check(ent Entry, ce *CheckedEntry) *CheckedEntry {
|
|
79
|
+
if c.Enabled(ent.Level) {
|
|
80
|
+
return ce.AddCore(ent, c)
|
|
81
|
+
}
|
|
82
|
+
return ce
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
func (c *ioCore) Write(ent Entry, fields []Field) error {
|
|
86
|
+
buf, err := c.enc.EncodeEntry(ent, fields)
|
|
87
|
+
if err != nil {
|
|
88
|
+
return err
|
|
89
|
+
}
|
|
90
|
+
_, err = c.out.Write(buf.Bytes())
|
|
91
|
+
buf.Free()
|
|
92
|
+
if err != nil {
|
|
93
|
+
return err
|
|
94
|
+
}
|
|
95
|
+
if ent.Level > ErrorLevel {
|
|
96
|
+
// Since we may be crashing the program, sync the output. Ignore Sync
|
|
97
|
+
// errors, pending a clean solution to issue #370.
|
|
98
|
+
c.Sync()
|
|
99
|
+
}
|
|
100
|
+
return nil
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
func (c *ioCore) Sync() error {
|
|
104
|
+
return c.out.Sync()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
func (c *ioCore) clone() *ioCore {
|
|
108
|
+
return &ioCore{
|
|
109
|
+
LevelEnabler: c.LevelEnabler,
|
|
110
|
+
enc: c.enc.Clone(),
|
|
111
|
+
out: c.out,
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Copyright (c) 2016 Uber Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
|
11
|
+
// all copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
// THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
// Package zapcore defines and implements the low-level interfaces upon which
|
|
22
|
+
// zap is built. By providing alternate implementations of these interfaces,
|
|
23
|
+
// external packages can extend zap's capabilities.
|
|
24
|
+
package zapcore // import "go.uber.org/zap/zapcore"
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
// Copyright (c) 2016 Uber Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
|
11
|
+
// all copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
// THE SOFTWARE.
|
|
20
|
+
|
|
21
|
+
package zapcore
|
|
22
|
+
|
|
23
|
+
import (
|
|
24
|
+
"encoding/json"
|
|
25
|
+
"time"
|
|
26
|
+
|
|
27
|
+
"go.uber.org/zap/buffer"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
// DefaultLineEnding defines the default line ending when writing logs.
|
|
31
|
+
// Alternate line endings specified in EncoderConfig can override this
|
|
32
|
+
// behavior.
|
|
33
|
+
const DefaultLineEnding = "\n"
|
|
34
|
+
|
|
35
|
+
// OmitKey defines the key to use when callers want to remove a key from log output.
|
|
36
|
+
const OmitKey = ""
|
|
37
|
+
|
|
38
|
+
// A LevelEncoder serializes a Level to a primitive type.
|
|
39
|
+
type LevelEncoder func(Level, PrimitiveArrayEncoder)
|
|
40
|
+
|
|
41
|
+
// LowercaseLevelEncoder serializes a Level to a lowercase string. For example,
|
|
42
|
+
// InfoLevel is serialized to "info".
|
|
43
|
+
func LowercaseLevelEncoder(l Level, enc PrimitiveArrayEncoder) {
|
|
44
|
+
enc.AppendString(l.String())
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// LowercaseColorLevelEncoder serializes a Level to a lowercase string and adds coloring.
|
|
48
|
+
// For example, InfoLevel is serialized to "info" and colored blue.
|
|
49
|
+
func LowercaseColorLevelEncoder(l Level, enc PrimitiveArrayEncoder) {
|
|
50
|
+
s, ok := _levelToLowercaseColorString[l]
|
|
51
|
+
if !ok {
|
|
52
|
+
s = _unknownLevelColor.Add(l.String())
|
|
53
|
+
}
|
|
54
|
+
enc.AppendString(s)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// CapitalLevelEncoder serializes a Level to an all-caps string. For example,
|
|
58
|
+
// InfoLevel is serialized to "INFO".
|
|
59
|
+
func CapitalLevelEncoder(l Level, enc PrimitiveArrayEncoder) {
|
|
60
|
+
enc.AppendString(l.CapitalString())
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// CapitalColorLevelEncoder serializes a Level to an all-caps string and adds color.
|
|
64
|
+
// For example, InfoLevel is serialized to "INFO" and colored blue.
|
|
65
|
+
func CapitalColorLevelEncoder(l Level, enc PrimitiveArrayEncoder) {
|
|
66
|
+
s, ok := _levelToCapitalColorString[l]
|
|
67
|
+
if !ok {
|
|
68
|
+
s = _unknownLevelColor.Add(l.CapitalString())
|
|
69
|
+
}
|
|
70
|
+
enc.AppendString(s)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// UnmarshalText unmarshals text to a LevelEncoder. "capital" is unmarshaled to
|
|
74
|
+
// CapitalLevelEncoder, "coloredCapital" is unmarshaled to CapitalColorLevelEncoder,
|
|
75
|
+
// "colored" is unmarshaled to LowercaseColorLevelEncoder, and anything else
|
|
76
|
+
// is unmarshaled to LowercaseLevelEncoder.
|
|
77
|
+
func (e *LevelEncoder) UnmarshalText(text []byte) error {
|
|
78
|
+
switch string(text) {
|
|
79
|
+
case "capital":
|
|
80
|
+
*e = CapitalLevelEncoder
|
|
81
|
+
case "capitalColor":
|
|
82
|
+
*e = CapitalColorLevelEncoder
|
|
83
|
+
case "color":
|
|
84
|
+
*e = LowercaseColorLevelEncoder
|
|
85
|
+
default:
|
|
86
|
+
*e = LowercaseLevelEncoder
|
|
87
|
+
}
|
|
88
|
+
return nil
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// A TimeEncoder serializes a time.Time to a primitive type.
|
|
92
|
+
type TimeEncoder func(time.Time, PrimitiveArrayEncoder)
|
|
93
|
+
|
|
94
|
+
// EpochTimeEncoder serializes a time.Time to a floating-point number of seconds
|
|
95
|
+
// since the Unix epoch.
|
|
96
|
+
func EpochTimeEncoder(t time.Time, enc PrimitiveArrayEncoder) {
|
|
97
|
+
nanos := t.UnixNano()
|
|
98
|
+
sec := float64(nanos) / float64(time.Second)
|
|
99
|
+
enc.AppendFloat64(sec)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// EpochMillisTimeEncoder serializes a time.Time to a floating-point number of
|
|
103
|
+
// milliseconds since the Unix epoch.
|
|
104
|
+
func EpochMillisTimeEncoder(t time.Time, enc PrimitiveArrayEncoder) {
|
|
105
|
+
nanos := t.UnixNano()
|
|
106
|
+
millis := float64(nanos) / float64(time.Millisecond)
|
|
107
|
+
enc.AppendFloat64(millis)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// EpochNanosTimeEncoder serializes a time.Time to an integer number of
|
|
111
|
+
// nanoseconds since the Unix epoch.
|
|
112
|
+
func EpochNanosTimeEncoder(t time.Time, enc PrimitiveArrayEncoder) {
|
|
113
|
+
enc.AppendInt64(t.UnixNano())
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
func encodeTimeLayout(t time.Time, layout string, enc PrimitiveArrayEncoder) {
|
|
117
|
+
type appendTimeEncoder interface {
|
|
118
|
+
AppendTimeLayout(time.Time, string)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if enc, ok := enc.(appendTimeEncoder); ok {
|
|
122
|
+
enc.AppendTimeLayout(t, layout)
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
enc.AppendString(t.Format(layout))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ISO8601TimeEncoder serializes a time.Time to an ISO8601-formatted string
|
|
130
|
+
// with millisecond precision.
|
|
131
|
+
//
|
|
132
|
+
// If enc supports AppendTimeLayout(t time.Time,layout string), it's used
|
|
133
|
+
// instead of appending a pre-formatted string value.
|
|
134
|
+
func ISO8601TimeEncoder(t time.Time, enc PrimitiveArrayEncoder) {
|
|
135
|
+
encodeTimeLayout(t, "2006-01-02T15:04:05.000Z0700", enc)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// RFC3339TimeEncoder serializes a time.Time to an RFC3339-formatted string.
|
|
139
|
+
//
|
|
140
|
+
// If enc supports AppendTimeLayout(t time.Time,layout string), it's used
|
|
141
|
+
// instead of appending a pre-formatted string value.
|
|
142
|
+
func RFC3339TimeEncoder(t time.Time, enc PrimitiveArrayEncoder) {
|
|
143
|
+
encodeTimeLayout(t, time.RFC3339, enc)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// RFC3339NanoTimeEncoder serializes a time.Time to an RFC3339-formatted string
|
|
147
|
+
// with nanosecond precision.
|
|
148
|
+
//
|
|
149
|
+
// If enc supports AppendTimeLayout(t time.Time,layout string), it's used
|
|
150
|
+
// instead of appending a pre-formatted string value.
|
|
151
|
+
func RFC3339NanoTimeEncoder(t time.Time, enc PrimitiveArrayEncoder) {
|
|
152
|
+
encodeTimeLayout(t, time.RFC3339Nano, enc)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// TimeEncoderOfLayout returns TimeEncoder which serializes a time.Time using
|
|
156
|
+
// given layout.
|
|
157
|
+
func TimeEncoderOfLayout(layout string) TimeEncoder {
|
|
158
|
+
return func(t time.Time, enc PrimitiveArrayEncoder) {
|
|
159
|
+
encodeTimeLayout(t, layout, enc)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// UnmarshalText unmarshals text to a TimeEncoder.
|
|
164
|
+
// "rfc3339nano" and "RFC3339Nano" are unmarshaled to RFC3339NanoTimeEncoder.
|
|
165
|
+
// "rfc3339" and "RFC3339" are unmarshaled to RFC3339TimeEncoder.
|
|
166
|
+
// "iso8601" and "ISO8601" are unmarshaled to ISO8601TimeEncoder.
|
|
167
|
+
// "millis" is unmarshaled to EpochMillisTimeEncoder.
|
|
168
|
+
// "nanos" is unmarshaled to EpochNanosEncoder.
|
|
169
|
+
// Anything else is unmarshaled to EpochTimeEncoder.
|
|
170
|
+
func (e *TimeEncoder) UnmarshalText(text []byte) error {
|
|
171
|
+
switch string(text) {
|
|
172
|
+
case "rfc3339nano", "RFC3339Nano":
|
|
173
|
+
*e = RFC3339NanoTimeEncoder
|
|
174
|
+
case "rfc3339", "RFC3339":
|
|
175
|
+
*e = RFC3339TimeEncoder
|
|
176
|
+
case "iso8601", "ISO8601":
|
|
177
|
+
*e = ISO8601TimeEncoder
|
|
178
|
+
case "millis":
|
|
179
|
+
*e = EpochMillisTimeEncoder
|
|
180
|
+
case "nanos":
|
|
181
|
+
*e = EpochNanosTimeEncoder
|
|
182
|
+
default:
|
|
183
|
+
*e = EpochTimeEncoder
|
|
184
|
+
}
|
|
185
|
+
return nil
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// UnmarshalYAML unmarshals YAML to a TimeEncoder.
|
|
189
|
+
// If value is an object with a "layout" field, it will be unmarshaled to TimeEncoder with given layout.
|
|
190
|
+
// timeEncoder:
|
|
191
|
+
// layout: 06/01/02 03:04pm
|
|
192
|
+
// If value is string, it uses UnmarshalText.
|
|
193
|
+
// timeEncoder: iso8601
|
|
194
|
+
func (e *TimeEncoder) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
195
|
+
var o struct {
|
|
196
|
+
Layout string `json:"layout" yaml:"layout"`
|
|
197
|
+
}
|
|
198
|
+
if err := unmarshal(&o); err == nil {
|
|
199
|
+
*e = TimeEncoderOfLayout(o.Layout)
|
|
200
|
+
return nil
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
var s string
|
|
204
|
+
if err := unmarshal(&s); err != nil {
|
|
205
|
+
return err
|
|
206
|
+
}
|
|
207
|
+
return e.UnmarshalText([]byte(s))
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// UnmarshalJSON unmarshals JSON to a TimeEncoder as same way UnmarshalYAML does.
|
|
211
|
+
func (e *TimeEncoder) UnmarshalJSON(data []byte) error {
|
|
212
|
+
return e.UnmarshalYAML(func(v interface{}) error {
|
|
213
|
+
return json.Unmarshal(data, v)
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// A DurationEncoder serializes a time.Duration to a primitive type.
|
|
218
|
+
type DurationEncoder func(time.Duration, PrimitiveArrayEncoder)
|
|
219
|
+
|
|
220
|
+
// SecondsDurationEncoder serializes a time.Duration to a floating-point number of seconds elapsed.
|
|
221
|
+
func SecondsDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder) {
|
|
222
|
+
enc.AppendFloat64(float64(d) / float64(time.Second))
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// NanosDurationEncoder serializes a time.Duration to an integer number of
|
|
226
|
+
// nanoseconds elapsed.
|
|
227
|
+
func NanosDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder) {
|
|
228
|
+
enc.AppendInt64(int64(d))
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// MillisDurationEncoder serializes a time.Duration to an integer number of
|
|
232
|
+
// milliseconds elapsed.
|
|
233
|
+
func MillisDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder) {
|
|
234
|
+
enc.AppendInt64(d.Nanoseconds() / 1e6)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// StringDurationEncoder serializes a time.Duration using its built-in String
|
|
238
|
+
// method.
|
|
239
|
+
func StringDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder) {
|
|
240
|
+
enc.AppendString(d.String())
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// UnmarshalText unmarshals text to a DurationEncoder. "string" is unmarshaled
|
|
244
|
+
// to StringDurationEncoder, and anything else is unmarshaled to
|
|
245
|
+
// NanosDurationEncoder.
|
|
246
|
+
func (e *DurationEncoder) UnmarshalText(text []byte) error {
|
|
247
|
+
switch string(text) {
|
|
248
|
+
case "string":
|
|
249
|
+
*e = StringDurationEncoder
|
|
250
|
+
case "nanos":
|
|
251
|
+
*e = NanosDurationEncoder
|
|
252
|
+
case "ms":
|
|
253
|
+
*e = MillisDurationEncoder
|
|
254
|
+
default:
|
|
255
|
+
*e = SecondsDurationEncoder
|
|
256
|
+
}
|
|
257
|
+
return nil
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// A CallerEncoder serializes an EntryCaller to a primitive type.
|
|
261
|
+
type CallerEncoder func(EntryCaller, PrimitiveArrayEncoder)
|
|
262
|
+
|
|
263
|
+
// FullCallerEncoder serializes a caller in /full/path/to/package/file:line
|
|
264
|
+
// format.
|
|
265
|
+
func FullCallerEncoder(caller EntryCaller, enc PrimitiveArrayEncoder) {
|
|
266
|
+
// TODO: consider using a byte-oriented API to save an allocation.
|
|
267
|
+
enc.AppendString(caller.String())
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ShortCallerEncoder serializes a caller in package/file:line format, trimming
|
|
271
|
+
// all but the final directory from the full path.
|
|
272
|
+
func ShortCallerEncoder(caller EntryCaller, enc PrimitiveArrayEncoder) {
|
|
273
|
+
// TODO: consider using a byte-oriented API to save an allocation.
|
|
274
|
+
enc.AppendString(caller.TrimmedPath())
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// UnmarshalText unmarshals text to a CallerEncoder. "full" is unmarshaled to
|
|
278
|
+
// FullCallerEncoder and anything else is unmarshaled to ShortCallerEncoder.
|
|
279
|
+
func (e *CallerEncoder) UnmarshalText(text []byte) error {
|
|
280
|
+
switch string(text) {
|
|
281
|
+
case "full":
|
|
282
|
+
*e = FullCallerEncoder
|
|
283
|
+
default:
|
|
284
|
+
*e = ShortCallerEncoder
|
|
285
|
+
}
|
|
286
|
+
return nil
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// A NameEncoder serializes a period-separated logger name to a primitive
|
|
290
|
+
// type.
|
|
291
|
+
type NameEncoder func(string, PrimitiveArrayEncoder)
|
|
292
|
+
|
|
293
|
+
// FullNameEncoder serializes the logger name as-is.
|
|
294
|
+
func FullNameEncoder(loggerName string, enc PrimitiveArrayEncoder) {
|
|
295
|
+
enc.AppendString(loggerName)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// UnmarshalText unmarshals text to a NameEncoder. Currently, everything is
|
|
299
|
+
// unmarshaled to FullNameEncoder.
|
|
300
|
+
func (e *NameEncoder) UnmarshalText(text []byte) error {
|
|
301
|
+
switch string(text) {
|
|
302
|
+
case "full":
|
|
303
|
+
*e = FullNameEncoder
|
|
304
|
+
default:
|
|
305
|
+
*e = FullNameEncoder
|
|
306
|
+
}
|
|
307
|
+
return nil
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// An EncoderConfig allows users to configure the concrete encoders supplied by
|
|
311
|
+
// zapcore.
|
|
312
|
+
type EncoderConfig struct {
|
|
313
|
+
// Set the keys used for each log entry. If any key is empty, that portion
|
|
314
|
+
// of the entry is omitted.
|
|
315
|
+
MessageKey string `json:"messageKey" yaml:"messageKey"`
|
|
316
|
+
LevelKey string `json:"levelKey" yaml:"levelKey"`
|
|
317
|
+
TimeKey string `json:"timeKey" yaml:"timeKey"`
|
|
318
|
+
NameKey string `json:"nameKey" yaml:"nameKey"`
|
|
319
|
+
CallerKey string `json:"callerKey" yaml:"callerKey"`
|
|
320
|
+
FunctionKey string `json:"functionKey" yaml:"functionKey"`
|
|
321
|
+
StacktraceKey string `json:"stacktraceKey" yaml:"stacktraceKey"`
|
|
322
|
+
LineEnding string `json:"lineEnding" yaml:"lineEnding"`
|
|
323
|
+
// Configure the primitive representations of common complex types. For
|
|
324
|
+
// example, some users may want all time.Times serialized as floating-point
|
|
325
|
+
// seconds since epoch, while others may prefer ISO8601 strings.
|
|
326
|
+
EncodeLevel LevelEncoder `json:"levelEncoder" yaml:"levelEncoder"`
|
|
327
|
+
EncodeTime TimeEncoder `json:"timeEncoder" yaml:"timeEncoder"`
|
|
328
|
+
EncodeDuration DurationEncoder `json:"durationEncoder" yaml:"durationEncoder"`
|
|
329
|
+
EncodeCaller CallerEncoder `json:"callerEncoder" yaml:"callerEncoder"`
|
|
330
|
+
// Unlike the other primitive type encoders, EncodeName is optional. The
|
|
331
|
+
// zero value falls back to FullNameEncoder.
|
|
332
|
+
EncodeName NameEncoder `json:"nameEncoder" yaml:"nameEncoder"`
|
|
333
|
+
// Configures the field separator used by the console encoder. Defaults
|
|
334
|
+
// to tab.
|
|
335
|
+
ConsoleSeparator string `json:"consoleSeparator" yaml:"consoleSeparator"`
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// ObjectEncoder is a strongly-typed, encoding-agnostic interface for adding a
|
|
339
|
+
// map- or struct-like object to the logging context. Like maps, ObjectEncoders
|
|
340
|
+
// aren't safe for concurrent use (though typical use shouldn't require locks).
|
|
341
|
+
type ObjectEncoder interface {
|
|
342
|
+
// Logging-specific marshalers.
|
|
343
|
+
AddArray(key string, marshaler ArrayMarshaler) error
|
|
344
|
+
AddObject(key string, marshaler ObjectMarshaler) error
|
|
345
|
+
|
|
346
|
+
// Built-in types.
|
|
347
|
+
AddBinary(key string, value []byte) // for arbitrary bytes
|
|
348
|
+
AddByteString(key string, value []byte) // for UTF-8 encoded bytes
|
|
349
|
+
AddBool(key string, value bool)
|
|
350
|
+
AddComplex128(key string, value complex128)
|
|
351
|
+
AddComplex64(key string, value complex64)
|
|
352
|
+
AddDuration(key string, value time.Duration)
|
|
353
|
+
AddFloat64(key string, value float64)
|
|
354
|
+
AddFloat32(key string, value float32)
|
|
355
|
+
AddInt(key string, value int)
|
|
356
|
+
AddInt64(key string, value int64)
|
|
357
|
+
AddInt32(key string, value int32)
|
|
358
|
+
AddInt16(key string, value int16)
|
|
359
|
+
AddInt8(key string, value int8)
|
|
360
|
+
AddString(key, value string)
|
|
361
|
+
AddTime(key string, value time.Time)
|
|
362
|
+
AddUint(key string, value uint)
|
|
363
|
+
AddUint64(key string, value uint64)
|
|
364
|
+
AddUint32(key string, value uint32)
|
|
365
|
+
AddUint16(key string, value uint16)
|
|
366
|
+
AddUint8(key string, value uint8)
|
|
367
|
+
AddUintptr(key string, value uintptr)
|
|
368
|
+
|
|
369
|
+
// AddReflected uses reflection to serialize arbitrary objects, so it can be
|
|
370
|
+
// slow and allocation-heavy.
|
|
371
|
+
AddReflected(key string, value interface{}) error
|
|
372
|
+
// OpenNamespace opens an isolated namespace where all subsequent fields will
|
|
373
|
+
// be added. Applications can use namespaces to prevent key collisions when
|
|
374
|
+
// injecting loggers into sub-components or third-party libraries.
|
|
375
|
+
OpenNamespace(key string)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ArrayEncoder is a strongly-typed, encoding-agnostic interface for adding
|
|
379
|
+
// array-like objects to the logging context. Of note, it supports mixed-type
|
|
380
|
+
// arrays even though they aren't typical in Go. Like slices, ArrayEncoders
|
|
381
|
+
// aren't safe for concurrent use (though typical use shouldn't require locks).
|
|
382
|
+
type ArrayEncoder interface {
|
|
383
|
+
// Built-in types.
|
|
384
|
+
PrimitiveArrayEncoder
|
|
385
|
+
|
|
386
|
+
// Time-related types.
|
|
387
|
+
AppendDuration(time.Duration)
|
|
388
|
+
AppendTime(time.Time)
|
|
389
|
+
|
|
390
|
+
// Logging-specific marshalers.
|
|
391
|
+
AppendArray(ArrayMarshaler) error
|
|
392
|
+
AppendObject(ObjectMarshaler) error
|
|
393
|
+
|
|
394
|
+
// AppendReflected uses reflection to serialize arbitrary objects, so it's
|
|
395
|
+
// slow and allocation-heavy.
|
|
396
|
+
AppendReflected(value interface{}) error
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// PrimitiveArrayEncoder is the subset of the ArrayEncoder interface that deals
|
|
400
|
+
// only in Go's built-in types. It's included only so that Duration- and
|
|
401
|
+
// TimeEncoders cannot trigger infinite recursion.
|
|
402
|
+
type PrimitiveArrayEncoder interface {
|
|
403
|
+
// Built-in types.
|
|
404
|
+
AppendBool(bool)
|
|
405
|
+
AppendByteString([]byte) // for UTF-8 encoded bytes
|
|
406
|
+
AppendComplex128(complex128)
|
|
407
|
+
AppendComplex64(complex64)
|
|
408
|
+
AppendFloat64(float64)
|
|
409
|
+
AppendFloat32(float32)
|
|
410
|
+
AppendInt(int)
|
|
411
|
+
AppendInt64(int64)
|
|
412
|
+
AppendInt32(int32)
|
|
413
|
+
AppendInt16(int16)
|
|
414
|
+
AppendInt8(int8)
|
|
415
|
+
AppendString(string)
|
|
416
|
+
AppendUint(uint)
|
|
417
|
+
AppendUint64(uint64)
|
|
418
|
+
AppendUint32(uint32)
|
|
419
|
+
AppendUint16(uint16)
|
|
420
|
+
AppendUint8(uint8)
|
|
421
|
+
AppendUintptr(uintptr)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Encoder is a format-agnostic interface for all log entry marshalers. Since
|
|
425
|
+
// log encoders don't need to support the same wide range of use cases as
|
|
426
|
+
// general-purpose marshalers, it's possible to make them faster and
|
|
427
|
+
// lower-allocation.
|
|
428
|
+
//
|
|
429
|
+
// Implementations of the ObjectEncoder interface's methods can, of course,
|
|
430
|
+
// freely modify the receiver. However, the Clone and EncodeEntry methods will
|
|
431
|
+
// be called concurrently and shouldn't modify the receiver.
|
|
432
|
+
type Encoder interface {
|
|
433
|
+
ObjectEncoder
|
|
434
|
+
|
|
435
|
+
// Clone copies the encoder, ensuring that adding fields to the copy doesn't
|
|
436
|
+
// affect the original.
|
|
437
|
+
Clone() Encoder
|
|
438
|
+
|
|
439
|
+
// EncodeEntry encodes an entry and fields, along with any accumulated
|
|
440
|
+
// context, into a byte buffer and returns it. Any fields that are empty,
|
|
441
|
+
// including fields on the `Entry` type, should be omitted.
|
|
442
|
+
EncodeEntry(Entry, []Field) (*buffer.Buffer, error)
|
|
443
|
+
}
|