For completely disabling logs, it's actually better to call logslog.SetFlags(0)[Joril][1] and set the output to a no-op io.Writer (i.e., log.SetOutput(ioutil.Discard))
For completely disabling logs, it's actually better to call logs.SetFlags(0)[Joril][1] and set the output to a no-op io.Writer (i.e., log.SetOutput(ioutil.Discard))
For completely disabling logs, it's actually better to call log.SetFlags(0)[Joril][1] and set the output to a no-op io.Writer (i.e., log.SetOutput(ioutil.Discard))
#1: YMMV, tested on i7-4500U CPU @ 1.80GHz [1]:How to disable a log.LoggerHow to disable a log.Logger [2a]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "YMMV, tested on i7-4500U CPU @ 1.80GHz" [2b]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "benchmark for package log" [3]:https://github.com/Sirupsen/logrus [4]:https://github.com/Sirupsen/logrus/issues/125 "Issue #125" [5]:https://github.com/op/go-logging [6]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c "Gist"
#1: YMMV, tested on i7-4500U CPU @ 1.80GHz [1]:How to disable a log.Logger [2a]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "YMMV, tested on i7-4500U CPU @ 1.80GHz" [2b]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "benchmark for package log" [3]:https://github.com/Sirupsen/logrus [4]:https://github.com/Sirupsen/logrus/issues/125 "Issue #125" [5]:https://github.com/op/go-logging [6]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c "Gist"
#1: YMMV, tested on i7-4500U CPU @ 1.80GHz [1]:How to disable a log.Logger [2a]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "YMMV, tested on i7-4500U CPU @ 1.80GHz" [2b]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "benchmark for package log" [3]:https://github.com/Sirupsen/logrus [4]:https://github.com/Sirupsen/logrus/issues/125 "Issue #125" [5]:https://github.com/op/go-logging [6]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c "Gist"
the output of the benchmark is as follows:
testing: warning: no tests to run PASS BenchmarkGoLogging-4 1000000 2068 ns/op BenchmarkGoLoggingNullBackend-4 5000000 308 ns/op BenchmarkGoLoggingNullBackendWithFancyFormatter-4 3000000 435 ns/op BenchmarkGoLoggingOffLevel-4 20000000 109 ns/op BenchmarkGoLoggingNullBackendAndOffLevel-4 20000000 108 ns/op BenchmarkGoLoggingNullBackendWithFancyFormatterAndOffLevel-4 20000000 109 ns/op BenchmarkLog15-4 200000 7359 ns/op BenchmarkLog15WithDiscardHandler-4 2000000 922 ns/op BenchmarkLog15WithDiscardHandlerAndOffLevel-4 2000000 926 ns/op BenchmarkLog15WithNopLogger-4 20000000 108 ns/op BenchmarkLog15WithNopLoggerDiscardHandlerA-4 20000000 112 ns/op BenchmarkLog15WithNopLoggerAndDiscardHandlerAndOffLevel-4 20000000 112 ns/op BenchmarkLog-4 1000000 1217 ns/op BenchmarkLogIoDiscardWriter-4 2000000 724 ns/op BenchmarkLogIoDiscardWriterWithoutFlags-4 3000000 543 ns/op BenchmarkLogCustomNullWriter-4 2000000 731 ns/op BenchmarkLogCustomNullWriterWithoutFlags-4 3000000 549 ns/op BenchmarkNopLogger-4 20000000 113 ns/op BenchmarkNopLoggerWithoutFlags-4 20000000 112 ns/op BenchmarkLogrus-4 300000 3832 ns/op BenchmarkLogrusWithDiscardWriter-4 500000 3032 ns/op BenchmarkLogrusWithNullFormatter-4 500000 3814 ns/op BenchmarkLogrusWithPanicLevel-4 500000 3872 ns/op BenchmarkLogrusWithDiscardWriterAndPanicLevel-4 500000 3085 ns/op BenchmarkLogrusWithDiscardWriterAndNullFormatterAndPanicLevel-4 500000 3064 ns/op ok log-benchmarks 51.378s go test -bench . 62.17s user 3.90s system 126% cpu 52.065 total #1: YMMV, tested on i7-4500U CPU @ 1.80GHz [1]:How to disable a log.Logger [2a]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "YMMV, tested on i7-4500U CPU @ 1.80GHz" [2b]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "benchmark for package log" [3]:https://github.com/Sirupsen/logrus [4]:https://github.com/Sirupsen/logrus/issues/125 "Issue #125" [5]:https://github.com/op/go-logging [6]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c "Gist"
#1: YMMV, tested on i7-4500U CPU @ 1.80GHz [1]:How to disable a log.Logger [2a]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "YMMV, tested on i7-4500U CPU @ 1.80GHz" [2b]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "benchmark for package log" [3]:https://github.com/Sirupsen/logrus [4]:https://github.com/Sirupsen/logrus/issues/125 "Issue #125" [5]:https://github.com/op/go-logging [6]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c "Gist"
the output of the benchmark is as follows:
testing: warning: no tests to run PASS BenchmarkGoLogging-4 1000000 2068 ns/op BenchmarkGoLoggingNullBackend-4 5000000 308 ns/op BenchmarkGoLoggingNullBackendWithFancyFormatter-4 3000000 435 ns/op BenchmarkGoLoggingOffLevel-4 20000000 109 ns/op BenchmarkGoLoggingNullBackendAndOffLevel-4 20000000 108 ns/op BenchmarkGoLoggingNullBackendWithFancyFormatterAndOffLevel-4 20000000 109 ns/op BenchmarkLog15-4 200000 7359 ns/op BenchmarkLog15WithDiscardHandler-4 2000000 922 ns/op BenchmarkLog15WithDiscardHandlerAndOffLevel-4 2000000 926 ns/op BenchmarkLog15WithNopLogger-4 20000000 108 ns/op BenchmarkLog15WithNopLoggerDiscardHandlerA-4 20000000 112 ns/op BenchmarkLog15WithNopLoggerAndDiscardHandlerAndOffLevel-4 20000000 112 ns/op BenchmarkLog-4 1000000 1217 ns/op BenchmarkLogIoDiscardWriter-4 2000000 724 ns/op BenchmarkLogIoDiscardWriterWithoutFlags-4 3000000 543 ns/op BenchmarkLogCustomNullWriter-4 2000000 731 ns/op BenchmarkLogCustomNullWriterWithoutFlags-4 3000000 549 ns/op BenchmarkNopLogger-4 20000000 113 ns/op BenchmarkNopLoggerWithoutFlags-4 20000000 112 ns/op BenchmarkLogrus-4 300000 3832 ns/op BenchmarkLogrusWithDiscardWriter-4 500000 3032 ns/op BenchmarkLogrusWithNullFormatter-4 500000 3814 ns/op BenchmarkLogrusWithPanicLevel-4 500000 3872 ns/op BenchmarkLogrusWithDiscardWriterAndPanicLevel-4 500000 3085 ns/op BenchmarkLogrusWithDiscardWriterAndNullFormatterAndPanicLevel-4 500000 3064 ns/op ok log-benchmarks 51.378s go test -bench . 62.17s user 3.90s system 126% cpu 52.065 total #1: YMMV, tested on i7-4500U CPU @ 1.80GHz [1]:How to disable a log.Logger [2a]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "YMMV, tested on i7-4500U CPU @ 1.80GHz" [2b]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c#file-log_test-go "benchmark for package log" [3]:https://github.com/Sirupsen/logrus [4]:https://github.com/Sirupsen/logrus/issues/125 "Issue #125" [5]:https://github.com/op/go-logging [6]:https://gist.github.com/Avinash-Bhat/48c4f06b0cc840d9fd6c "Gist"