public static void setupLogger(Config config) throws IOException { Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n"); Appender appender = new DailyRollingFileAppender( layout, config.getString("logger.file"), "'.'yyyyMMdd"); LogManager.resetConfiguration(); LogManager.getRootLogger().addAppender(new NullAppender()); logger = Logger.getLogger(LOGGER_NAME); logger.addAppender(appender); logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL)); // Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem" InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() { @Override public InternalLogger newInstance(String string) { return new NettyInternalLogger(); } }); Log.logSystemInfo(); Log.info("Version: " + getAppVersion()); }
/** * * @param prop * @param clazz * @return */ public static Logger getLogger(Properties prop, Class<?> clazz) { Logger LOG = Logger.getLogger(clazz); String appName = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.APP_NAME); String fileDir = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.LOG_DIR); String patternLayout = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.LOG_PATTERN); String level = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.LOG_LEVEL); LOG.setLevel(Level.toLevel(level, Level.INFO)); DailyRollingFileAppender rollingAppender = new DailyRollingFileAppender(); rollingAppender.setFile(fileDir + "/" + appName + ".log"); rollingAppender.setLayout(new PatternLayout(patternLayout)); rollingAppender.setDatePattern("'.'yyyy-MM-dd"); rollingAppender.activateOptions(); LOG.addAppender(rollingAppender); LOG.setAdditivity(false); return LOG; }
public void setLevel(DailyRollingFileAppender fa){ if (CmdLineParams.hasOptionTrace()) { fa.setThreshold(Level.TRACE); Logger.getRootLogger().setLevel(Level.TRACE); } else if (CmdLineParams.hasOptionDebug()) { fa.setThreshold(Level.DEBUG); } else if (CmdLineParams.hasOptionInfo()) { fa.setThreshold(Level.INFO); } else if(CmdLineParams.hasOptionWarn()){ fa.setThreshold(Level.WARN); }else if(CmdLineParams.hasOptionError()){ fa.setThreshold(Level.ERROR); }else { fa.setThreshold(Level.WARN); } }
/** * Configures the logger. */ private static void configureLogging() { PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd' 'HH:mm:ss.SSS} [%-5p] [%c] - %m%n"); ConsoleAppender console = new ConsoleAppender(); console.setLayout(layout); console.setThreshold(Level.INFO); console.activateOptions(); DailyRollingFileAppender file = new DailyRollingFileAppender(); file.setFile("log/app.log"); file.setDatePattern("'.'yyyy-MM-dd"); file.setLayout(layout); file.activateOptions(); org.apache.log4j.Logger logger = org.apache.log4j.Logger.getRootLogger(); logger.addAppender(console); logger.addAppender(file); }
boolean init(FairSchedulerConfiguration conf) { try { logDir = conf.getEventlogDir(); File logDirFile = new File(logDir); if (!logDirFile.exists()) { if (!logDirFile.mkdirs()) { throw new IOException( "Mkdirs failed to create " + logDirFile.toString()); } } String username = System.getProperty("user.name"); logFile = String.format("%s%shadoop-%s-fairscheduler.log", logDir, File.separator, username); logDisabled = false; PatternLayout layout = new PatternLayout("%d{ISO8601}\t%m%n"); appender = new DailyRollingFileAppender(layout, logFile, "'.'yyyy-MM-dd"); appender.activateOptions(); LOG.info("Initialized fair scheduler event log, logging to " + logFile); } catch (IOException e) { LOG.error( "Failed to initialize fair scheduler event log. Disabling it.", e); logDisabled = true; } return !(logDisabled); }
void init() { String rootLoggerDirectory = getRootLoggerDirectory(); if (rootLoggerDirectory == null) { return; } String absolutePath = new File(rootLoggerDirectory, failedMessageFile).getAbsolutePath(); try { DailyRollingFileAppender failedLogFilesAppender = new DailyRollingFileAppender( new PatternLayout(PATTERN_SPEC_TIMESTAMP_MESSAGE_NEWLINE), absolutePath, DATE_PATTERN); logger.addAppender(failedLogFilesAppender); logger.setLevel(Level.ERROR); logger.setAdditivity(false); } catch (IOException e) { e.printStackTrace(); } }
/** * This create log4j logger for resource access tool using root logger. * It adds file appender with specified filename to the logger which creates separate * log file for each resource access tool. * * @param clazz Class object for Resource Access Tool * @param logFile String containing name of log file. * @return log4j Logger object */ @SuppressWarnings("unchecked") public static Logger createRATSpecificLogger(Class clazz, String logFile) { Enumeration<Appender> appenders = Logger.getRootLogger() .getAllAppenders(); // Add all appenders of root logger while (appenders.hasMoreElements()) { Appender appender = appenders.nextElement(); // For file appender create new appender with different log file if (appender instanceof DailyRollingFileAppender) { try { // Creates new file appender ((DailyRollingFileAppender) appender).setFile(FileParameters.obrLogFolder() + logFile); ((DailyRollingFileAppender) appender).activateOptions(); } catch (Exception e) { e.printStackTrace(); } } } return Logger.getLogger(clazz); }
/** * This create log4j logger for OBS work flow using root logger. * It adds file appender with specified filename to the logger which creates separate * log file for each resource access tool. * * @param clazz * @param logFile String containing name of log file. * @return log4j Logger object */ @SuppressWarnings("unchecked") public static Logger createOBSLogger(Class clazz) { Enumeration<Appender> appenders = Logger.getRootLogger() .getAllAppenders(); // Add all appenders of root logger while (appenders.hasMoreElements()) { Appender appender = appenders.nextElement(); // For file appender create new appender with different log file if (appender instanceof DailyRollingFileAppender) { try { // Creates new file appender ((DailyRollingFileAppender) appender).setFile(FileParameters.obsLogFolder() + OBS_LOG_FILE); ((DailyRollingFileAppender) appender).activateOptions(); } catch (Exception e) { e.printStackTrace(); } } } return Logger.getLogger(clazz); }
public static void setupLogger(Properties properties) throws IOException { Layout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %5p: %m%n"); Appender appender = new DailyRollingFileAppender( layout, properties.getProperty("logger.file"), "'.'yyyyMMdd"); LogManager.resetConfiguration(); logger = Logger.getLogger(LOGGER_NAME); logger.addAppender(appender); logger.setLevel(Level.ALL); // Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem" InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() { @Override public InternalLogger newInstance(String string) { return new NettyInternalLogger(); } }); }
public static Logger getServerLogger() { if (serverLogger == null) { // Initialise le gestionnaire de logs try { DailyRollingFileAppender fileAppender = new DailyRollingFileAppender( new PatternLayout("%-5p %d{HH:mm:ss} %m%n"), Config.getServerLogFile(), "'.'yyyy-MM-dd"); serverLogger = Logger.getLogger("server"); serverLogger.addAppender(fileAppender); serverLogger.setLevel(Level.toLevel(Config.getServerLogLevel())); if (Config.isDebug()) { ConsoleAppender consoleAppender = new ConsoleAppender( new PatternLayout("%-5p %d{HH:mm:ss} %m [%C#%M, line %L]%n")); serverLogger.addAppender(consoleAppender); } } catch (IOException e) { System.err.println("Could not initialize server logging!"); e.printStackTrace(); } serverLogger.info("Server logging initialized."); } return serverLogger; }
public static Logger getPremiumLogger() { if (premiumLogger == null) { // Initialise le gestionnaire de logs try { DailyRollingFileAppender fileAppender = new DailyRollingFileAppender( new PatternLayout("%-5p %d{HH:mm:ss} %m%n"), Config.getPremiumLogFile(), "'.'yyyy-MM-dd"); premiumLogger = Logger.getLogger("premium"); premiumLogger.addAppender(fileAppender); premiumLogger.setLevel(Level.DEBUG); if (Config.isDebug()) { ConsoleAppender consoleAppender = new ConsoleAppender( new PatternLayout("%-5p %d{HH:mm:ss} %m [%C#%M, line %L]%n")); premiumLogger.addAppender(consoleAppender); } } catch (IOException e) { System.err.println("Could not initialize premium transactions logging!"); e.printStackTrace(); } premiumLogger.info("Premium transactions logging initialized."); } return premiumLogger; }
public static Logger getChatLogger() { if (chatLogger == null) { try { DailyRollingFileAppender fileAppender = new DailyRollingFileAppender( new PatternLayout("%d{HH:mm:ss} %m%n"), Config.getChatLogFile(), "'.'yyyy-MM-dd"); chatLogger = Logger.getLogger("chat"); chatLogger.addAppender(fileAppender); chatLogger.setLevel(Level.DEBUG); // if (Config.isDebug()) { // ConsoleAppender consoleAppender = new ConsoleAppender( // new PatternLayout("%d{HH:mm:ss} %m%n")); // chatLogger.addAppender(consoleAppender); // } } catch (IOException e) { System.err.println("Could not initialize chat logging!"); e.printStackTrace(); } } return chatLogger; }
public static Logger getActionLogger() { if (actionLogger == null) { try { DailyRollingFileAppender fileAppender = new DailyRollingFileAppender( new PatternLayout("%d{HH:mm:ss} %m%n"), Config.getActionLogFile(), "'.'yyyy-MM-dd"); actionLogger = Logger.getLogger("action"); actionLogger.addAppender(fileAppender); actionLogger.setLevel(Level.DEBUG); // if (Config.isDebug()) { // ConsoleAppender consoleAppender = new ConsoleAppender( // new PatternLayout("%d{HH:mm:ss} %m%n")); // actionLogger.addAppender(consoleAppender); // } } catch (IOException e) { System.err.println("Could not initialize action logging!"); e.printStackTrace(); } } return actionLogger; }
/** * Constructs a log which writes log entries to the given log file. * * @param title Identifies the log entries * @param logfile Location of the log file */ public SecureLog(String title, String logfile) throws IOException { defaultLog = new FileOutputStream(logfile); logAppender = new DailyRollingFileAppender(defaultLayout, logfile, rotationInterval); logAppender.setName(defaultLogName); // Configure the logging options //logRoot = new SecureCategory(title); logRoot = (SecureCategory)SecureCategory.getLogger(title); logRoot.addAppender(logAppender); setLogLevel(DEBUG); logEntry(this, DEBUG, "Constructing " + title + " log. Initial log level is DEBUG. " + "Output will be sent to: " + logfile); }
boolean init(FairSchedulerConfiguration conf) { if (conf.isEventLogEnabled()) { try { logDir = conf.getEventlogDir(); File logDirFile = new File(logDir); if (!logDirFile.exists()) { if (!logDirFile.mkdirs()) { throw new IOException( "Mkdirs failed to create " + logDirFile.toString()); } } String username = System.getProperty("user.name"); logFile = String.format("%s%shadoop-%s-fairscheduler.log", logDir, File.separator, username); logDisabled = false; PatternLayout layout = new PatternLayout("%d{ISO8601}\t%m%n"); appender = new DailyRollingFileAppender(layout, logFile, "'.'yyyy-MM-dd"); appender.activateOptions(); LOG.info("Initialized fair scheduler event log, logging to " + logFile); } catch (IOException e) { LOG.error( "Failed to initialize fair scheduler event log. Disabling it.", e); logDisabled = true; } } else { logDisabled = true; } return !(logDisabled); }
@Override public void setupLogger() { String file =checkFile(); DailyRollingFileAppender fa = new DailyRollingFileAppender(); fa.setName("FileLogger"); fa.setFile(file); fa.setLayout(new PatternLayout(pattern)); setLevel(fa); fa.setAppend(true); fa.activateOptions(); Logger.getRootLogger().addAppender(fa); }
protected void initFields() throws Exception { nextCheckField = DailyRollingFileAppender.class.getDeclaredField("nextCheck"); nowField = DailyRollingFileAppender.class.getDeclaredField("now"); rcField = DailyRollingFileAppender.class.getDeclaredField("rc"); scheduledFilenameField = DailyRollingFileAppender.class.getDeclaredField("scheduledFilename"); nextCheckField.setAccessible(true); nowField.setAccessible(true); rcField.setAccessible(true); scheduledFilenameField.setAccessible(true); }
/** * Attaches a rolling file logger for search queries * * @param path * @param filename * @throws IOException */ private static void setupLogger(String path, String filename, Level level) throws IOException { Path logDir = Paths.get(path, filename + "_log"); if (!Files.exists(logDir)) { Files.createDirectories(logDir); } Appender appender = new DailyRollingFileAppender( new PatternLayout("%p %d{ISO8601} %m%n"), logDir.resolve("searsia.log").toString(), "'.'yyyy-MM-dd"); LOGGER.addAppender(appender); LOGGER.setLevel(level); LOGGER.warn("Searsia restart"); }
boolean init(Configuration conf, String jobtrackerHostname) { try { logDir = conf.get("mapred.fairscheduler.eventlog.location", new File(System.getProperty("hadoop.log.dir")).getAbsolutePath() + File.separator + "fairscheduler"); File logDirFile = new File(logDir); if (!logDirFile.exists()) { if (!logDirFile.mkdirs()) { throw new IOException( "Mkdirs failed to create " + logDirFile.toString()); } } String username = System.getProperty("user.name"); logFile = String.format("%s%shadoop-%s-fairscheduler-%s.log", logDir, File.separator, username, jobtrackerHostname); logDisabled = false; PatternLayout layout = new PatternLayout("%d{ISO8601}\t%m%n"); appender = new DailyRollingFileAppender(layout, logFile, "'.'yyyy-MM-dd"); appender.activateOptions(); LOG.info("Initialized fair scheduler event log, logging to " + logFile); } catch (IOException e) { LOG.error( "Failed to initialize fair scheduler event log. Disabling it.", e); logDisabled = true; } return !(logDisabled); }
private Appender getFileAppender(Level level, String pattern, String file) { DailyRollingFileAppender appender = new DailyRollingFileAppender(); appender.setFile(file); appender.setLayout(new PatternLayout(pattern)); appender.setThreshold(level); appender.setAppend(true); appender.activateOptions(); return appender; }
private Appender buildAppender(String name, String fileName, String pattern) { DailyRollingFileAppender appender = new DailyRollingFileAppender(); appender.setName(name); appender.setAppend(true); appender.setEncoding(getEncoding()); appender.setLayout(new PatternLayout(pattern)); appender.setFile(new File(getLogPath(), fileName).getAbsolutePath()); appender.activateOptions();// 很重要,否则原有日志内容会被清空 return appender; }
/** * This create log4j logger for OBS work flow using root logger. * It adds file appender with specified filename to the logger which creates separate * log file for each resource access tool. * * @param clazz * @param logFile String containing name of log file. * @return log4j Logger object */ @SuppressWarnings("unchecked") public static Logger createOBRLogger(Class clazz) { Logger logger = Logger.getLogger(clazz); Enumeration<Appender> appenders = Logger.getRootLogger() .getAllAppenders(); // Add all appenders of root logger while (appenders.hasMoreElements()) { Appender appender = appenders.nextElement(); // For file appender create new appender with different log file if (appender instanceof DailyRollingFileAppender) { try { // Creates new file appender DailyRollingFileAppender newFileAppender = new DailyRollingFileAppender( appender.getLayout(), FileParameters.obrLogFolder() + OBR_LOG_FILE, ((DailyRollingFileAppender) appender) .getDatePattern()); newFileAppender.activateOptions(); logger.addAppender(newFileAppender); } catch (Exception e) { e.printStackTrace(); } } else { logger.addAppender(appender); } } logger.setAdditivity(false); return logger; }
public static Appender createAppender(Path logdir, String name, Layout layout) { final DailyRollingFileAppender dst = new DailyRollingFileAppender(); dst.setName(name); dst.setLayout(layout); dst.setEncoding(UTF_8.name()); dst.setFile(resolve(logdir).resolve(name).toString()); dst.setImmediateFlush(true); dst.setAppend(true); dst.setErrorHandler(new DieErrorHandler()); dst.activateOptions(); dst.setErrorHandler(new OnlyOnceErrorHandler()); return dst; }
public static void main(String argv[]) { FileAppender fa = new FileAppender(); RollingFileAppender rfa = new RollingFileAppender(); DailyRollingFileAppender drfa = new DailyRollingFileAppender(); FileHandler fh = new FileHandler(); SocketHandler sh = new SocketHandler("host", 1); }
public static boolean isFileAppenderConfiguredForST() { Logger rootLogger = Logger.getRootLogger(); DailyRollingFileAppender logger = (DailyRollingFileAppender) rootLogger .getAppender(CARBON_LOGFILE_APPENDER); if (logger != null && CarbonContext.getThreadLocalCarbonContext().getTenantId() == org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_ID) { return true; } else { return false; } }
boolean init(Configuration conf, String jobtrackerHostname) { try { logDir = conf.get("mapred.fairscheduler.eventlog.location", new File(System.getProperty("hadoop.log.dir")).getAbsolutePath() + File.separator + "fairscheduler"); Path logDirPath = new Path(logDir); FileSystem fs = logDirPath.getFileSystem(conf); if (!fs.exists(logDirPath)) { if (!fs.mkdirs(logDirPath)) { throw new IOException( "Mkdirs failed to create " + logDirPath.toString()); } } String username = System.getProperty("user.name"); logFile = String.format("%s%shadoop-%s-fairscheduler-%s.log", logDir, File.separator, username, jobtrackerHostname); logDisabled = false; PatternLayout layout = new PatternLayout("%d{ISO8601}\t%m%n"); appender = new DailyRollingFileAppender(layout, logFile, "'.'yyyy-MM-dd"); appender.activateOptions(); LOG.info("Initialized fair scheduler event log, logging to " + logFile); } catch (IOException e) { LOG.error( "Failed to initialize fair scheduler event log. Disabling it.", e); logDisabled = true; } return !(logDisabled); }
/** * Initialize logging * * @param contextPath */ private void initLogging(String contextPath) { System.out.println("Rafael: Initializing logging"); // enable appenders String logPath = contextPath.substring(0,contextPath.indexOf("webapps")); logPath += "logs/rafael/rafael.log"; try { // default layout Layout layout = new PatternLayout("%-5p: %d{yyyy-MM-dd HH:mm:ss,SSS} %c %x - %m%n"); // rolling file appender DailyRollingFileAppender appender1 = new DailyRollingFileAppender(layout,logPath,"'.'yyyy-MM-dd"); BasicConfigurator.configure(appender1); // console appender ConsoleAppender appender2 = new ConsoleAppender(layout); BasicConfigurator.configure(appender2); } catch(IOException e) { System.out.println("Got an exception while initializing the logging configuration"); e.printStackTrace(); } /* * turn off all logging, and enable ERROR logging for the root package * use restlet.LoggingResource to enable specific logging */ Logger.getRootLogger().setLevel(Level.OFF); Logger.getLogger(PACKAGE_ROOT).setLevel(Level.INFO); System.out.println("Rafael: Initializing logging done"); }
/** * Start logging to an additional log file location. * * @param logfile New logfile location */ public void addLogfile(String logfile) throws IOException { Appender existing = logRoot.getAppender(logfile); if (existing == null) { logEntry(this, INFO, "Adding new log file: " + logfile); logAppender = new DailyRollingFileAppender(defaultLayout, logfile, rotationInterval); logAppender.setName(logfile); logRoot.addAppender(logAppender); if (!logFiles.contains(logfile)) { logFiles.add(logfile); } } else { logEntry(this, DEBUG, "Log file already active: " + logfile); } }
/** * Sets the rotation interval of the log files. The interval must * be one of the defined constants: WEEKLY, MONTHLY, YEARLY */ public void setRotationInterval(String interval) { rotationInterval = interval; // Locate all appenders which can be rotated Enumeration appenderList = logRoot.getAllAppenders(); while ((appenderList != null) && (appenderList.hasMoreElements())) { Appender current = (Appender)appenderList.nextElement(); if (current instanceof DailyRollingFileAppender) { ((DailyRollingFileAppender)current).setDatePattern(interval); } } }