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. css实现鼠标经过导航文字偏位效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. Http中Cookie与Set-Cookie头

    [原文:http://hi.baidu.com/qinglvzhuye/item/6664a807bb8be3dd73e676d6] android 获取 cookies 有很多办法,但是记住了. h ...

  3. Linux下停用和启用用户帐号

    有时候某个用户不乖,但是还不想删除他的帐号只是想给他点儿颜色看看,或者出于某种权限管理不想让他/她使用这个帐号,那么冻结帐号就是最好的方法了,linux中的帐号密码保存在/etc/shadow文件里面 ...

  4. INDEX_JOIN

    这里就以INDEX_JOIN为例,简单描述一下如何影响Oracle的执行计划的产生. 控制执行计划最简单的方法莫过于使用HINT,这篇文章要介绍的是,在不使用HINT的情况下,让Oracle产生IND ...

  5. 使用Selenium+appium进行App测试

    1. 启动安卓虚拟机.

  6. Linux 文件的几种类型

    文件的几种类型:    1.普通文件   普通文件就是一般意义上的文件,它们作为数据存储在系统磁盘中,可以随机访问文件的内容.Linux系统中的文件是面向字节的,文 件的内容以字节为单位进行存储与访问 ...

  7. IOS中UIScrollView的详细使用

    UIScrollView 是可以滚动的View 要想让UIScrollView可以滚动,必须设置UIScrollView的contentSize contentSize : 表示UIScrollVie ...

  8. VS如何设置OpenCV静态编译

      可以使用opencv提供的静态链接库也可以自己编译静态链接库. 1 使用opencv提供的静态链接库,位置如下图. 首先设置VS配置.有如下几个配置 1 工具->选项->项目和解决方案 ...

  9. 再来说说Activity

    经过前面多天的了解,现在可以确信一点: activity提供了用户和程序交互的界面. 而且android里有四大组件:Activity,Service,BroadcastReceiver,Conten ...

  10. Chapter10:泛型算法

    泛型算法的基础是迭代器. 迭代器令算法不依赖于容器,但是算法依赖于元素类型的操作.也即:算法永远不会执行容器的操作. 那么,如果想向容器中添加元素或者执行其他的一些操作呢?标准库提供了插入迭代器来完成 ...