I have trouble in setting up log4j for plugin code. I got message in the server.

I have trouble in setting up log4j for plugin code. I got message in the server.log "log4j:WARN No appenders could be found for logger (...), log4j:WARN Please initialize the log4j system properly.". I added a line in appian_log4j.properties under the resources folder like: "log4j.logger.<my package name>=INFO". It didn't work. Any suggestions?

OriginalPostID-201230

OriginalPostID-201230

  Discussion posts and replies are publicly visible

Parents
  • Not AFAIK. For an example of a plugin that uses loggers, see the Export SQL and Report Data to EXCEL plugin here: forum.appian.com/.../summary
  • I got a forbidden message. May I have access somehow to this page? I really need to understand better how to make log4j work. 

  • 0
    Certified Lead Developer
    in reply to christianb0003

    Hi ,

    Here is the plugin link - https://community.appian.com/b/appmarket/posts/excel-tools

    Also, attaching the part of the ExportSqltoExcel Code for reference

    package com.appiancorp.ps.exceltools.smartservice.export;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.net.URL;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.Types;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;
    
    import javax.naming.Context;
    import javax.sql.DataSource;
    
    import org.apache.commons.lang.StringUtils;
    import org.apache.commons.validator.routines.UrlValidator;
    import org.apache.log4j.Logger;
    import org.apache.poi.common.usermodel.HyperlinkType;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.CellStyle;
    import org.apache.poi.ss.usermodel.CreationHelper;
    import org.apache.poi.ss.usermodel.DataFormat;
    import org.apache.poi.ss.usermodel.Font;
    import org.apache.poi.ss.usermodel.Hyperlink;
    import org.apache.poi.ss.usermodel.IndexedColors;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.xssf.streaming.SXSSFSheet;
    import org.apache.poi.xssf.streaming.SXSSFWorkbook;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    
    import com.appiancorp.ps.exceltools.util.ContentHelperUtils;
    import com.appiancorp.ps.exceltools.util.ExcelHelperUtils;
    import com.appiancorp.ps.exceltools.util.ExportHelper;
    import com.appiancorp.suiteapi.common.Name;
    import com.appiancorp.suiteapi.content.ContentConstants;
    import com.appiancorp.suiteapi.content.ContentService;
    import com.appiancorp.suiteapi.knowledge.Document;
    import com.appiancorp.suiteapi.knowledge.DocumentDataType;
    import com.appiancorp.suiteapi.knowledge.FolderDataType;
    import com.appiancorp.suiteapi.process.analytics2.ProcessAnalyticsService;
    import com.appiancorp.suiteapi.process.exceptions.SmartServiceException;
    import com.appiancorp.suiteapi.process.framework.AppianSmartService;
    import com.appiancorp.suiteapi.process.framework.Input;
    import com.appiancorp.suiteapi.process.framework.MessageContainer;
    import com.appiancorp.suiteapi.process.framework.Required;
    import com.appiancorp.suiteapi.process.framework.SmartServiceContext;
    import com.appiancorp.suiteapi.process.framework.Unattended;
    import com.appiancorp.suiteapi.process.palette.PaletteInfo;
    
    /**
     * @author sathya.srinivasan Smart service to export data from an SQL query to excel
     */
    @PaletteInfo(paletteCategory = "#Deprecated#", palette = "#Deprecated#")
    @Unattended
    @Deprecated
    public class ExportSqlToExcel extends AppianSmartService {
    
      private static final Logger LOG = Logger.getLogger(ExportSqlToExcel.class);
      private final SmartServiceContext smartServiceCtx;
      private String jndiName;
      private String sql;
      private Long excelBaseTemplate;
      private String startingCell;
      private Long sheetNumber = 0l;
      private String documentNameToCreate;
      private Long documentSaveDirectory;
      private Boolean includeHeaderRow = false;
      private Long documentToOverwrite;
      private Long output_document;
      private String[] cellKeys;
      private String[] cellValues;
    
      private DataSource ds;
      private Context ctx;
    
      private ContentService cs;
      private static UrlValidator defaultValidator = new UrlValidator();
    
      public SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MMM-yyyy");
      public SimpleDateFormat DATETIME_FORMAT = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
      public SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");
    
      public ExportSqlToExcel(
        ContentService cs,
        ProcessAnalyticsService pas,
        SmartServiceContext smartServiceCtx,
        Context ctx) {
        super();
        this.smartServiceCtx = smartServiceCtx;
        this.cs = cs;
        this.ctx = ctx;
      }
    
      @Override
      public void run() throws SmartServiceException {
        Locale currentLocale = smartServiceCtx.getUserLocale() != null ? smartServiceCtx.getUserLocale()
          : smartServiceCtx.getPrimaryLocale();
    
        Workbook wb = null;
    
        try {
          Long templateId = excelBaseTemplate == null ? null : cs.getVersionId(excelBaseTemplate, ContentConstants.VERSION_CURRENT);
          wb = ExcelHelperUtils.createDocFromTemplate(templateId, cs);
          Long docId = ContentHelperUtils.registerDocument(documentNameToCreate, ExcelHelperUtils.EXTENSION_XLSX, documentToOverwrite,
            documentSaveDirectory, cs);
          writeDocumentContent(docId, wb);
          exportStaticCells(docId);
          exportSQLCells(docId, currentLocale);
          output_document = docId;
        } catch (Exception e) {
          LOG.error(e.getMessage(), e);
          throw createException(e, "error.export.general", e.getMessage());
        }
      }
    
    
    }

  • Thank you so much!

    Do I have to use org.apache.log4j?  Right now all my code is using org.slf4j. Maybe this is the reason it is not working? 

Reply Children
No Data