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 this stackoverflow thread

memcached Logging的更多相关文章

  1. Python自动化 【第十一篇】:Python进阶-RabbitMQ队列/Memcached/Redis

     本节内容: RabbitMQ队列 Memcached Redis 1.  RabbitMQ 安装 http://www.rabbitmq.com/install-standalone-mac.htm ...

  2. Memcached缓存瓶颈分析

    Memcached缓存瓶颈分析 获取Memcached的统计信息 Shell: # echo "stats" | nc 127.0.0.1 11211 PHP: $mc = new ...

  3. 代码中实际运用memcached——java

    以下文章取自:http://jameswxx.iteye.com/blog/1168711 memcached的java客户端有好几种,http://code.google.com/p/memcach ...

  4. NET Core2.0 Memcached踩坑,基于EnyimMemcachedCore整理MemcachedHelper帮助类。

    DotNetCore2.0下使用memcached缓存. Memcached目前微软暂未支持,暂只支持Redis,由于项目历史原因,先用博客园开源项目EnyimMemcachedCore,后续用到的时 ...

  5. Asp.Net Core 2.0 项目实战(9) 日志记录,基于Nlog或Microsoft.Extensions.Logging的实现及调用实例

    本文目录 1. Net下日志记录 2. NLog的使用     2.1 添加nuget引用NLog.Web.AspNetCore     2.2 配置文件设置     2.3 依赖配置及调用     ...

  6. memcached command

    http://lzone.de/cheat-sheet/memcached memcached Cheat Sheet Telnet Interface How To Connect Use &quo ...

  7. java集成memcached、redis防止缓存穿透

    下载相关jar,安装Memcached,安装教程:http://www.runoob.com/memcached/memcached-install.html spring配置memcached &l ...

  8. Docker部署Django项目+Nginx+Fluend日志收集 和redis、memcached、RabbitMQ、Celery

    前言 一.docker 1.docker是什么? Docker的英文本意是“搬运工”,Docker搬运的是集装箱(Container)可以成为容器,我可以把写的Django的WEB应用以及Python ...

  9. Tomcat通过Memcached实现session共享的完整部署记录

    对于web应用集群的技术实现而言,最大的难点就是:如何能在集群中的多个节点之间保持数据的一致性,会话(Session)信息是这些数据中最重要的一块.要实现这一点, 大体上有两种方式:一种是把所有Ses ...

随机推荐

  1. 树莓派 Linux 剪贴板

    安装: apt-get install xsel 显示剪贴板中的数据: xsel -b -oxsel -b -o 向剪贴板中追加数据: xsel -b -a 覆盖剪贴板中的数据: xsel -b -i ...

  2. myeclipse 8.5最新注册码(过期时间到2016年)

    myeclipse 8.5最新注册码(过期时间到2016年) 这几天myeclipse弹出注册码过期,去网上一搜,要么已过期,要么就剩一两个月.倒腾了半天,自己申请了几个注册码,给大家分享一下 Sub ...

  3. 利用命令控制台cmd进入某个硬盘的某个文件夹的命令是什么?

    在命令行窗口中输入F:后回车就可以切换到F盘,如果想查看F盘的内容,可以再输入dir后回车 (输入“F”后要再输入一个“ :”再回车才行哦)

  4. php的header()大全

    <?php /*** Function: PHP header() examples (PHP) ** Desc: Some examples on how to use the header( ...

  5. 康乐不风流之爱解题的pde灌水王张祖锦

    康乐不风流之爱解题的pde灌水王张祖锦 师弟: 邓洪存 (现在烟台大学任教) 好吧, 我一直想写写康乐园里与我相熟的这几个人, 不如趁此机会开始. 第一批人物为张祖锦.苏延辉.张会春.黄显涛.刘兴兴. ...

  6. Optional优雅的使用null

    在我们学习和使用Guava的Optional之前,我们需要来了解一下Java中null.因为,只有我们深入的了解了null的相关知识,我们才能更加深入体会领悟到Guava的Optional设计和使用上 ...

  7. WCF服务通过防火墙怎么设置

    设置防火墙 1.首先点击控制面板->系统与安全->Window防火墙->点击允许程序通过Windows防火墙 2.查找Windows Communication Foundation ...

  8. PreferenceActivity使用方法

              public class MainActivity extends Activity { @Override protected void onCreate(Bundle save ...

  9. 数往知来 ASP.NET 表单的提交_url传值_重定向 <十八>

    一.表单提交时注意 如果是以get方式提交数据的时候,在接收时是用QueryString方式进行接收 如果是以post请求数据时在接收时是用Form进行接收 为什么么要这样做呢?我们用Request[ ...

  10. 150个JS特效脚本

    收集了其它一些不太方便归类的JS特效,共150个,供君查阅. 1. simplyScroll simplyScroll这个jQuery插件能够让任意一组元素产生滚动动画效果,可以是自动.手动滚动,水平 ...