Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Replace log4j by logback, other minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hainguyen committed Apr 25, 2015
1 parent d767eb8 commit 098ebaa
Show file tree
Hide file tree
Showing 23 changed files with 318 additions and 489 deletions.
44 changes: 44 additions & 0 deletions mycollab-app-community/src/main/conf/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- For assistance related to logback-translator or configuration -->
<!-- files in general, please contact the logback user mailing list -->
<!-- at http://www.qos.ch/mailman/listinfo/logback-user -->
<!-- -->
<!-- For professional support please see -->
<!-- http://www.qos.ch/shop/products/professionalSupport -->
<!-- -->
<configuration>
<!-- Errors were reported during translation. -->
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="email" class="com.esofthead.mycollab.configuration.MailAppender">
<subject>Error: %logger{20} - %m</subject>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%date %-5level %logger{35} - %message%n</pattern>
</layout>
</appender>
<appender name="R" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/mycollab.out</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>mycollab_%d{yyyy-MM-dd}.log</fileNamePattern>

<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="INFO"></logger>
<logger name="com.esofthead" level="INFO"/>
<logger name="org.eclipse.jetty" level="INFO" />
<root level="INFO">
<appender-ref ref="stdout"/>
<appender-ref ref="email"/>
<appender-ref ref="R"/>
</root>
</configuration>
33 changes: 0 additions & 33 deletions mycollab-app-community/src/main/resources/log4j.properties

This file was deleted.

1 change: 1 addition & 0 deletions mycollab-app-community/src/main/txt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Version 5.0.5
* Add time summary for task group, milestone, component, version views
* Allow system admin can change the SMTP setting on the fly
* Enable gzip compression for assets by default
* Replace the old log4j library by logback

**Bug Fixes**
* Checkbox in Chrome, IE has the unintended border
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
* You should have received a copy of the GNU General Public License
* along with mycollab-config. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* This file is part of mycollab-config.
* <p>
* mycollab-config is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* mycollab-config is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with mycollab-config. If not, see <http://www.gnu.org/licenses/>.
*/
package com.esofthead.mycollab.configuration;

import com.esofthead.mycollab.core.MyCollabException;
Expand All @@ -28,87 +44,83 @@
/**
* This file contains all constants define in system properties file
* mycollab.properties read at system started.
*
*
* @author MyCollab Ltd.
* @since 1.0
*
*
*/
public class ApplicationProperties {
private static final String RESOURCE_PROPERTIES = "mycollab.properties";
private static final String DECRYPT_PASS = "esofthead321";

private static Properties properties;

public static final String DB_USERNAME = "db.username";
public static final String DB_PASSWORD = "db.password";
public static final String DB_DRIVER_CLASS = "db.driverClassName";
public static final String DB_URL = "db.url";

public static final String CDN_URL = "cdn.url";
static final String APP_URL = "app.url";

static final String FACEBOOK_URL = "facebook.url";
static final String GOOGLE_URL = "google.url";
static final String LINKEDIN_URL = "linkedin.url";
static final String TWITTER_URL = "twitter.url";

public static final String MAIL_SMTPHOST = "mail.smtphost";
public static final String MAIL_PORT = "mail.port";
public static final String MAIL_USERNAME = "mail.username";
public static final String MAIL_PASSWORD = "mail.password";
public static final String MAIL_IS_TLS = "mail.isTLS";
public static final String MAIL_NOREPLY = "mail.noreply";

public static final String ERROR_SENDTO = "error.sendTo";
public static final String STORAGE_SYSTEM = "storageSystem";

public static final String LOCALES = "locale.list";
public static final String DEFAULT_LOCALE = "locale.default";
public static final String SITE_NAME = "site.name";
public static final String SERVER_ADDRESS = "server.address";
public static final String RUNNING_MODE = "running.mode";

public static final String DROPBOX_AUTH_LINK = "dropbox.callbackUrl";
public static final String GOOGLE_DRIVE_LINK = "ggDrive.callbackUrl";

public static final String BI_ENDECRYPT_PASSWORD = "endecryptPassword";

public static void loadProps() {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword(DECRYPT_PASS);

properties = new EncryptableProperties(encryptor);
try {
File myCollabResourceFile = getAppConfigFile();

if (myCollabResourceFile != null) {
properties.load(new FileInputStream(myCollabResourceFile));
} else {
properties.load(Thread.currentThread().getContextClassLoader()
.getResourceAsStream(RESOURCE_PROPERTIES));
}
} catch (Exception e) {
throw new MyCollabException(e);
}
}

public static File getAppConfigFile() {
return FileUtils.getDesireFile(System.getProperty("user.dir"),"conf/mycollab.properties", "src/main/conf/mycollab.properties");
}

public static Properties getAppProperties() {
return properties;
}

public static String getString(String key) {
return getString(key, "");
}

public static String getString(String key, String defaultValue) {
if (properties != null) {
return properties.getProperty(key, defaultValue);
} else {
return defaultValue;
}
}
private static final String RESOURCE_PROPERTIES = "mycollab.properties";
private static final String DECRYPT_PASS = "esofthead321";

private static Properties properties;

public static final String DB_USERNAME = "db.username";
public static final String DB_PASSWORD = "db.password";
public static final String DB_DRIVER_CLASS = "db.driverClassName";
public static final String DB_URL = "db.url";

public static final String CDN_URL = "cdn.url";
static final String APP_URL = "app.url";

static final String FACEBOOK_URL = "facebook.url";
static final String GOOGLE_URL = "google.url";
static final String LINKEDIN_URL = "linkedin.url";
static final String TWITTER_URL = "twitter.url";

public static final String MAIL_SMTPHOST = "mail.smtphost";
public static final String MAIL_PORT = "mail.port";
public static final String MAIL_USERNAME = "mail.username";
public static final String MAIL_PASSWORD = "mail.password";
public static final String MAIL_IS_TLS = "mail.isTLS";
public static final String MAIL_NOREPLY = "mail.noreply";

public static final String ERROR_SENDTO = "error.sendTo";
public static final String STORAGE_SYSTEM = "storageSystem";

public static final String LOCALES = "locale.list";
public static final String DEFAULT_LOCALE = "locale.default";
public static final String SITE_NAME = "site.name";
public static final String SERVER_ADDRESS = "server.address";
public static final String RUNNING_MODE = "running.mode";

public static final String DROPBOX_AUTH_LINK = "dropbox.callbackUrl";
public static final String GOOGLE_DRIVE_LINK = "ggDrive.callbackUrl";

public static final String BI_ENDECRYPT_PASSWORD = "endecryptPassword";

public static void loadProps() {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword(DECRYPT_PASS);

properties = new EncryptableProperties(encryptor);
try {
File myCollabResourceFile = getAppConfigFile();

if (myCollabResourceFile != null) {
properties.load(new FileInputStream(myCollabResourceFile));
} else {
properties.load(Thread.currentThread().getContextClassLoader()
.getResourceAsStream(RESOURCE_PROPERTIES));
}
} catch (Exception e) {
throw new MyCollabException(e);
}
}

public static File getAppConfigFile() {
return FileUtils.getDesireFile(System.getProperty("user.dir"), "conf/mycollab.properties", "src/main/conf/mycollab.properties");
}

public static Properties getAppProperties() {
return properties;
}

public static String getString(String key) {
return getString(key, "");
}

public static String getString(String key, String defaultValue) {
return properties.getProperty(key, defaultValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* This file is part of mycollab-config.
*
* mycollab-config is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* mycollab-config is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with mycollab-config. If not, see <http://www.gnu.org/licenses/>.
*/
package com.esofthead.mycollab.configuration;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import com.esofthead.mycollab.core.utils.FileUtils;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
* @author MyCollab Ltd
* @since 5.0.5
*/
public class LogConfig {
public static void initLog() {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.reset();
JoranConfigurator configurator = new JoranConfigurator();
InputStream inputStream = LogConfig.class.getClassLoader().getResourceAsStream("logback-test.xml");
if (inputStream == null) {
try {
File configFile = FileUtils.getDesireFile(System.getProperty("user.dir"), "conf/logback.xml", "src/main/conf/logback.xml");
if (configFile != null) inputStream = new FileInputStream(configFile);
} catch (FileNotFoundException e) {
inputStream = LogConfig.class.getClassLoader().getResourceAsStream("logback.xml");
}
}

try {

configurator.setContext(loggerContext);
configurator.doConfigure(inputStream); // loads logback file
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* This file is part of mycollab-config.
*
* mycollab-config is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* mycollab-config is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with mycollab-config. If not, see <http://www.gnu.org/licenses/>.
*/
package com.esofthead.mycollab.configuration;

import ch.qos.logback.classic.net.SMTPAppender;
import org.apache.commons.lang3.StringUtils;

/**
* @author MyCollab Ltd
* @since 5.0.5
*/
public class MailAppender extends SMTPAppender {

@Override
public void start() {
EmailConfiguration conf = SiteConfiguration.getEmailConfiguration();
if (StringUtils.isBlank(conf.getHost())) {
return;
}

this.setSMTPHost(conf.getHost());
this.setSMTPPort(conf.getPort());
this.setUsername(conf.getUser());
this.setPassword(conf.getPassword());
this.setSTARTTLS(conf.getIsTls());
this.setFrom(SiteConfiguration.getNoReplyEmail());
this.addTo(SiteConfiguration.getSendErrorEmail());
super.start();
}
}
Loading

0 comments on commit 098ebaa

Please sign in to comment.