2013年10月27日 星期日

Log4j概念 與使用情境

那天在跟公司新人介紹log4j的時候

就突然想到其實這個設計很簡單啊 怎麼會一直都沒有被弄清楚?

所以 來吧!! 介紹一下!!

在log4j的官方文件上面有一段清楚地說明

http://logging.apache.org/log4j/1.2/manual.html

Log4j has three main components: loggers, appenders and layouts. These three types of components work together to enable developers to log messages according to message type and level, and to control at runtime how these messages are formatted and where they are reported.
Logger用來記錄訊息,包含log等級與log類型

Appender用來控制訊息會被放到什麼地方

Layout用來控制訊息的格式



簡單的情境如下

我們設定一個appender與layout

指定log會被記錄到檔案中 (appender)

並且會使用 "yyyy/mm/dd hh:MM:ss [訊息等級] 訊息內容" 格式來記錄訊息

接著設定 logger

指定一個logger要log的等級是INFO以上

並且將logger與appender接上


之後在程式裡面就取得此logger,並且使用應該使用的log等級來記錄訊息

例如
logger.trace("測試測試");
logger.debug("變數A = " + A);
logger.error("db conn. setting error.");


因為設定已經將log的等級設定為INFO

所以依照 TRACE < DEBUG < INFO < WARN < ERROR < FATAL 的等級

之前的訊息只有 error的項目 會被記錄到最後產生出來的檔案中

2013年9月13日 星期五

Maven專案設定

通常我們在開發的時候,會把專案切成幾個部分

例如前端呈現與後台邏輯,各自也可以有自己架構

前端呈現或許可以是單純html+javascript library

也可以用類似ZK這樣比較大型的framework

這時候我們一樣可以使用Maven來幫助我們做管理


首先 建立一個主專案 裡面的pom.xml設定
<project>
.
.
.
   <packaging>pom</packaging>
.
.
.
   <modules>
      <module>webProject</module>
      <module>serviceProject</module>   </modules>
.
.
.
</project>

有看到module嗎?我們可以直接在主專案資料夾裡面建立其他的maven專案

這樣當我們編譯主專案的時候,就會跟著依照module的名稱,去編譯其他的module囉

2013年7月30日 星期二

Jasypt - BasicTextEncryptor

http://jasypt.org/api/jasypt/1.9.0/org/jasypt/util/text/BasicTextEncryptor.html

Sample:

import org.jasypt.util.text.BasicTextEncryptor;

public class EncryptTest {
    public static void main(String[] args) {
        BasicTextEncryptor bte = new BasicTextEncryptor();
        bte.setPassword("password");

        String text = "This is visible message!";
        String encrypt = bte.encrypt(text);
        System.out.println("invisible msg:"+encrypt);

        String rs = bte.decrypt(encrypt);
        System.out.println("Decode:" +rs);
    }

}

聽說寫網誌 還是要打一些字。

所以跟廢話注解一樣,這是在說明BasicTextEncryptor的用法。

(Y)

2013年6月28日 星期五

bootstrap compile

brew install nodejs
// 先有nodeJS才會有npm

npm install
// 到git下來的資料夾,裡面有個package.json設定有該裝的東西 npm可以安裝起來

make
// 先make安裝基本的library -> node_modules

make bootstrap
// 編譯,會輸出到bootstrap資料夾

--
npm 已經安裝了!!! (超怪...)

被安裝在 /usr/local/lib/node_modules/npm

導致不能安裝nodejs

homebrew指定的解安裝指令也不能用... 真的有點囧 (npm uninstall npm -g)

最後直接移除掉npm的資料夾

再安裝nodejs (成功)

--
路徑沒有被自動建立起來.... (囧)

brew link node (失敗)

brew link --overwrite node

2013年6月26日 星期三

mac install pure-ftpd

progden:~ $brew install pure-ftpd
dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid
==> Downloading http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/pure-ftpd/1.0.35 --mandir=/usr/local/
==> make install
==> Caveats
To have launchd start pure-ftpd at login:
    ln -sfv /usr/local/opt/pure-ftpd/*.plist ~/Library/LaunchAgents
Then to load pure-ftpd now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.pure-ftpd.plist
Or, if you don't want/need launchctl, you can just run:
    pure-ftpd
/usr/local/Cellar/pure-ftpd/1.0.35: 26 files, 608K, built in 29 seconds

2013年6月19日 星期三

Maven lifecycle phase整理

Maven command format

  mvn <lifycyclePhase>

  mvn <plugin-prefix>:<goal>

  mvn <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>


Available lifecycle phases

validate,
initialize,
generate-sources, process-sources, generate-resources, process-resources,
compile,
process-classes,
generate-test-sources, process-test-sources, generate-test-resources, process-test-resources,
test-compile,
process-test-classes,
test,
prepare-package, package,
pre-integration-test, integration-test, post-integration-test,
verify,
install,
deploy,
pre-clean, clean, post-clean,
pre-site, site, post-site, site-deploy


start httpd with right configuration

httpd_start.sh

#!/bin/sh
sudo httpd -k start -f ~/conf/httpd.conf


~/conf/httpd.conf

.
.
.
DocumentRoot "/specify/path/to/the/root"
.
.
.

2013年6月11日 星期二

Homebrew安裝Mysql

brew install mysql

cp /usr/local/Cellar/mysql/5.5.28/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist


unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
/usr/local/Cellar/mysql/5.5.28/bin/mysqladmin -u root -h Denniss-MacBook-Pro.local password 'password'

mysql.server start
mysql -u root -p

2013年6月6日 星期四

Maven 清除下載失敗


Mac/Linux

find ~/.m2 -name "*.lastUpdated" -exec grep -q "Could not transfer" {} \; -print -exec rm {} \;


Windows

cd %userprofile%\.m2\repository
for /r %i in (*.lastUpdated) do del %i

Homebrew安裝多個版本程式 與 建立link

1. 檢視所有的版本
2. 依照版本安裝更新程式
3. 重新建立連結

brew update
brew versions FORMULA

#move to Homebrew's install path
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb
brew unlink FORMULA(option)
brew install FORMULA

brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb(??)


Ex.
$brew update
$brew versions tomcat

7.0.32   git checkout 55cfbdf /usr/local/Library/Formula/tomcat.rb
7.0.30   git checkout ec5e2ca /usr/local/Library/Formula/tomcat.rb
7.0.29   git checkout 1683f9e /usr/local/Library/Formula/tomcat.rb
7.0.28   git checkout 3293f97 /usr/local/Library/Formula/tomcat.rb
7.0.27   git checkout 82498e5 /usr/local/Library/Formula/tomcat.rb
7.0.26   git checkout ee016a5 /usr/local/Library/Formula/tomcat.rb
7.0.25   git checkout 48c1c63 /usr/local/Library/Formula/tomcat.rb
7.0.23   git checkout 09e1800 /usr/local/Library/Formula/tomcat.rb
7.0.21   git checkout 22d9df7 /usr/local/Library/Formula/tomcat.rb
7.0.20   git checkout f857eca /usr/local/Library/Formula/tomcat.rb
7.0.19   git checkout 548514e /usr/local/Library/Formula/tomcat.rb
7.0.16   git checkout 14e4db3 /usr/local/Library/Formula/tomcat.rb
7.0.14   git checkout bdd4756 /usr/local/Library/Formula/tomcat.rb
7.0.6    git checkout 0476235 /usr/local/Library/Formula/tomcat.rb
6.0.26   git checkout 9e18876 /usr/local/Library/Formula/tomcat.rb

2.
cd `brew --prefix`