博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
memcached Logging
阅读量:6985 次
发布时间:2019-06-27

本文共 2612 字,大约阅读时间需要 8 分钟。

For reasons now relegated to history, Spy has its own logging implementation. However, it is compatible with other types of logging, if configured as such.

Logging Howto

spymemcached is built on top of an internal logging API that has some nice logging abstractions built in. It's analogous to what you might find in Apache's commons-logging, except Dustin had his for quite a while before finding that one.

Both log4j and Java's built-in logging are supported. The logger is selected via the system propertynet.spy.memcached.compat.log.LoggerImpl.

Using log4j

Set the logger impl to net.spy.log.Log4JLogger. For example:

  -Dnet.spy.log.LoggerImpl=net.spy.memcached.compat.log.Log4JLogger

Using Java's Built-in Logging

Set the logger impl to net.spy.memcached.compat.log.SunLogger. For example:

  -Dnet.spy.log.LoggerImpl=net.spy.memcached.compat.log.SunLogger

This can also be done programmatically, as shown below.

If you're writing a simple application, say a test, and you simply want to get the default console handler to be more verbose, you can set that up like so:

        // Tell spy to use the SunLogger         Properties systemProperties = System.getProperties(); systemProperties.put("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.SunLogger"); System.setProperties(systemProperties); Logger.getLogger("net.spy.memcached").setLevel(Level.FINEST); //get the top Logger Logger topLogger = java.util.logging.Logger.getLogger(""); // Handler for console (reuse it if it already exists) Handler consoleHandler = null; //see if there is already a console handler for (Handler handler : topLogger.getHandlers()) { if (handler instanceof ConsoleHandler) { //found the console handler consoleHandler = handler; break; } } if (consoleHandler == null) { //there was no console handler found, create a new one consoleHandler = new ConsoleHandler(); topLogger.addHandler(consoleHandler); } //set the console handler to fine: consoleHandler.setLevel(java.util.logging.Level.FINEST);

Making Logging More Verbose with JDK Logger

Sometimes, you want to log what's happening with the internals of spymemcached, but not for every class. An easy way to do that is to define some properties and pass in more specific logging properties. For instance, if you start the JVM with -Djava.util.logging.config.file=logging.properties defined and then put the text below in a file named logging.properties in your classpath, you can log for just the net.spymemcached.vbucket classes.

net.spy.memcached.vbucket.level = FINEST

---

Attribution: The java.util.logging method of getting the consoleHandler was borrowed from 

转载地址:http://nqcpl.baihongyu.com/

你可能感兴趣的文章
上海张江人工智能岛“开岛” IBM首家入驻
查看>>
2019年如何确保国企效益增长?国资委明确这六项措施
查看>>
Python爬虫工作好做吗?爬虫工作发展前景如何呢?
查看>>
从程序员客栈的优秀成功案例,我们想告诉创业者什么信息?
查看>>
你一定不知道IDE里的Tomcat是怎么工作的
查看>>
Typescript 2+迷你书 :从入门到不放弃
查看>>
cms优化之晋升失败
查看>>
mybatis 批量更新
查看>>
Android studio 跟踪 Gradle Task 执行
查看>>
Java面试通关要点汇总集
查看>>
把收集的文章分下类
查看>>
手把手教你打造支持手势放大缩小的ImageView
查看>>
从源码角度理解Handler、Looper、MessageQueue之间关系
查看>>
Bitmap 比你想的更费内存 | 吊打 OOM
查看>>
四大组件之Activity_Fragment
查看>>
团队技术信息流建设
查看>>
为你揭秘小程序音视频背后的故事......
查看>>
自定义侧边快速索引栏
查看>>
一种自动化检测 Flash 中 XSS 方法的探讨
查看>>
基于环信sdk实现简单即时聊天
查看>>