-
Notifications
You must be signed in to change notification settings - Fork 5
Intro to Logging
Costin Grigore edited this page Oct 7, 2021
·
6 revisions
-
Logging systems
- javascript app (
console.log)- useful only for devs that open Development/Debug Console
- there is a convention that libraries do not log anything
- server-side
- useful for investigation post-factum (after they happened)
- the server cannot(is not efficient to be restarted) at will (with new debug in it)
- all clients depend on this server
- solution: do not delete logging
- javascript app (
-
Issues
- there are multiple logging libraries
- each library can use any of them
- hiper efficient: libraries think that they log to their library but this is effiently redirected to the actual library (see http://www.slf4j.org/manual.html)
- as developer I might not want to see all INFO events
- wrong: you might miss important information
- if really necessary, temporarly you can put ROOT on WARN.
-
Solutions
- we need a common logging library: slf4j
- logging api standard: slf4j
- logging library: logback
- configure logback for some usage scenarios
- configure log in environments
- production:
classpath:logback.xml - development:
classpath:logback.xml - tests:
classpath:logback-test.xml(overridesclasspath:logback.xml)
- production:
- configure log locally on a dev machine or override by devops
- enable/disable levels from command line or args-files
-Dapplog.level=WARN -Dapplog.revobet.level=WARN
- enable/disable levels from command line or args-files
- configure log at runtime
-
logback.xmlif outside jvm (by devops) the file can be changed and the change is detected14:27:12,832 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [file:/D:/home/raiser/work/revobet-backend/target/classes/logback.xml] 14:27:12,832 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 10 seconds - configure log from
FeatureService(false -> level high: WARN , true -> level low : DEBUG)2021-10-07 14:27:14.193+0300 1836 #INFO [main ] Register feature LoggerFeature(debugLogKafkaInternal/null with value [false]. atCompile=[false] atStart=[None] atRuntime=[None]) - org.jedio.feature.FeatureService.register (FeatureService.java:19) - 2021-10-07 14:27:14.193+0300 1836 #INFO [main ] switchLogger Logger[org.apache.kafka] to INFO - org.jedio.feature.FeatureService.change (LoggerFeature.java:71) -
- configure log from
FeatureServicenu are mod de disable -> revert to defaults- needs to take into consideration inheritance
- logging feature to configure exact level or inherited
-
- configure log in environments
- we need a common logging library: slf4j
-
Concepts
- level - ordered level. Enabling for INFO means also enabling for WARN and ERROR.
- recomandari
- mesajul - splited for performance reasons
- format
- arguments
- category - hierarchical label that can influence the decision to log (ROOT = INFO, org.* = WARN, org.revobet.* = INFO, org.revobet.feed.*=ERROR)
- there is an inheritance mecanism for enabling disabling levels
- level - ordered level. Enabling for INFO means also enabling for WARN and ERROR.
-
In java you do not delete the log instructions
-
nu stergi. ai avut nevoie de loguri sa faci codul bun vor avea nevoie si mentainerii de cod
-
problema de performanta e rezolvata prin pasarea de obiecte si nu de concatenare manuala a mesajului
-
apoi in java ai si package-ul care da un context logului
-
si poti usor configura ca orice sub un package sa nu mai fie afisat si deci sa nu consume spatiu
-
Clasele au anotarea @Slf4j
-
In loc de anotarea aia ai fi putut scrie cod in clasa private static final Logger logger = LoggerFactory.getLogger(FluxFeed.class);
-
practic fieldul log e definit in felul asta local packageului si clasei in care e
el e alt log care stie ca contextul e clasa in care e
De-asta tu oricand poti aplica filtre
revobet.* -> warn
revobet.feed.lsports->debug
revobet.controller.* ->info
tu vrei root -> warn
si apoi faci overwrite la packetul tau cu packageulSauClasaDeInteresVlad ->INFO/DEBUG
acum iti zic ce sa-ti configurezi
hai sa le comitem cu modul imediat superior celui care are loguri in acel pachet Astefel incat logul sa fie gol pentru un nou dezvoltator?
Exact cum iti trebuie la development asa raman in cod si asa sunt comise
Filtrarea o face cel ce are nevoie de ea. Nu comiti cod ca poate are unul din viitor nevoie de alta filtrae.
ok, am inteles principiul, imi setez eu local nivelurile
- Best API/contract is slf4j: https://www.slf4j.org/manual.html
- Log4j is deprecated and continued by slf4j.
- A good implementation of slf4j is logback.
- FATAL - jvm might crash
- ERROR - something bad happened usually program should stop working
- WARN - something is bad but we can continue
- INFO - operation that is not repetitive, low volume
- default level in production where you see everything that happens in production that is not repetitive or dependent on a volume
- in production that has INFO enabled: you want to know everything but do not want to affect performance or visibility with a lot of log
- examples that should not be on info
- users normal usage requests -> dependent on the volume of users/calls per user
- jobs(kafka, quartz, etc) that run hourly or often
- running something at minute/second level
- DEBUG - operation that is repeated, high volume
- TRACE - some gory details
File logback.xml or logback-test.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true" packagingData="true" scan="true" scanPeriod="30 seconds">
<!--disable debug <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> -->
<timestamp key="startTimestamp" datePattern="yyyyMMddHHmmssSSS"/>
<property name="profile" value="test" />
<property name="logs" value="${application.home:-${user.dir}}/target/home/.logs-${profile}--${startTimestamp}" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- eclipse clickable place -->
<!-- %4relative %highlight - to color-->
<pattern>%4relative [%level] [%-10.10thread] \(%file:%line\) %-120message - %logger{10.10}.%-20.20method - %n%xException</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- Support multiple-JVM writing to the same log file -->
<prudent>false</prudent>
<file>${logs}/namek.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%4relative [%level] [%-10.10thread] %-200message%xThrowable - %date{yyyy-MM-dd-'T'-HH-mm-ss-SSS} %logger.%method\(%file:%line\)%n</pattern>
<!--
<pattern>%date %5p [%t] %logger.%M\(%F:%L\) - %m%n</pattern>
<pattern>%4relative %5p [%-17thread] - %-200msg - %date %logger{30}\(%file:%line\)%n</pattern>
<pattern>%4relative %coloredLevel [%-17thread] %logger{15}.%M\(%F:%L\) - %message%n%xException{5}</pattern>
<pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern></pattern>
-->
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logs}/namek-%d{yyyy-MM-dd}-%02i.log</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>60</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="FILE-WARN"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logs}/namek-warn.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%4relative %level [%-10.10thread] %-200message - $d %logger{30}.%M\(%file:%line\)%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logs}/namek-warn-%d{yyyy-MM-dd}-%02i.log</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>60</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
</appender>
<logger name="ch.qos.logback" level="WARN" />
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
<appender-ref ref="FILE-WARN" />
</root>
</configuration>- Home
- Advices
- Development Algorithm
- Who's who
- Software Books
- Career, salary, salariu, brut, net, Levels
-
Tools
- Health
- Physical Tools
- Environment Tools
- File Tools
- Source Tools
- Information Tools
- Collaboration Tools
- Infrastructure Tools
- Language Tools
-
Concepts as Tools spec maturity
- Classes of Objects, Development Algorithm/mantra/practices
- Streaming Tools
- Process Tools psychology, analytical paralysis
- Special
- fiddler kotlin,javascript,scala
- translator scala->kotlin, java->kotlin
- Guides
- Asking for Help
- Aspects
- Security
- Server & Networking load balancing,
-
Principles & Guidelines
- PLS - Principle of Least Surprise (aka no puzzlers)
- SRP - Single Responsibility Principle
- KISS - Keep It Simple
- YAGNI - You aint gona need it
- DRY - Dont Repeat Yourself
- Fail Fast
- OCP - Open Closed
- POE - Premature Optimization is Evil
- LSP - Liskov Substitution Principle
- DIP - Dependency Inversion Principle / Inversion of Control
- Hollywood Principle - Don't call us We call you
- Tell Don't Ask
- Event sourcing
- NIHS - Not invented here syndrome
- Patterns - idioms, best practices, code smells
-
Intro to Problems - common problems: cache, logging, config, representing date, time, money
- Intro to Libraries - reactive, reactor, commons, collections, apache, guava, logging, config, time, test, junit, vavr, immutable, lombok, mapping, mapstruct, time, joda, cache, Guava, Caffeine, and cache2k
- Intro to DateTime
- Intro to Logging
- Intro to Concurrency - thread, parallelism
- Intro to I18N - internationalization, encoding, unicode, big indian, little indian, ascii, utf, utf8, utf16, formatting, parsing, transliteration, charset, localization, time, timezone, zone id, zone offset, GMT
- Intro to Numbers - rounding, ceil, floor, base, integer, decimal, precision, mantis, exponent, significant, statistics
- Java Idioms
- Concepts
- Code Changes refactor, format, eol, bugfix, newfeature
- Convention Over Configuration
- Continuous Integration
- Continuous Delivery
- Code License
- Fluent Interface
- Semantic Versioning
- Take It Offline
- Flow
- Languages
- Hardening
- Smells
-
Intros
- Intro to Paradigms Object Oriented, Functional, Procedural, Asynchronous
- Intro to Logic
- Intro to Product UX, UI, business, technical, backend, frontend
- Intro to Roles
- Intro to Decision Levels : business, financials, domain, product, architecture, high level design, low level design, coding, debugging, quality, roles, stakeholders
- Intro to Steps
- Intro to Software Architecture
- Intro to Software Design
- Intro to UML state machine diagram, class diagram, sequence diagram
- Intro to Graphical Design
- Intro to Performance bigO, algorithm complexity
- Intro to Agile
- Intro to Scripting
- Intro to Shell execution, environment, registry, powershell, cmd, cmder, linux, bash, ash, csh, zsh, ksh
- Intro to Wiki
-
Intro to Building
- Intro to DevMachine
- Intro to Git
- Intro to Maven
- Intro to Docker
- Intro to Hosting Deploy, nameserver, hostname, registrar, ssl, ddns, dns, naked domain, wildcard domain, email, smtp, pop3, imap, DKIM, SPF, spam
-
Intro to Landscapes Language Environments, Web Landscape
- Intro to JVM Landscape
-
Intro to Javascript Landscape
- Intro to Javascript
- Intro to Typescript binding, implicit, explicit, default (global), callsite, lambda, callback, function, promise, async await
- Intro to Node javascript, npm, yarn
- Intro to DotNet Landscape C# csharp
- Intro to Golang
- Intro to Ruby
- Intro to Python
- Coding Style
- Phases
-
Intro to Quality - QA, Quality Assurance, code quality, bugs, bug levels, metabugs
- Intro to Tests
-
Test Driven Development TDD, mantra
- Domain-and-Test-Driven-Design Advanced topics
- Intro to Coding defensive, offensive, preconditions, postconditions
- Intro to Debugging
- Intro to Profiling, Intro to Performance
- Intro to Code Review
-
Intro to Quality - QA, Quality Assurance, code quality, bugs, bug levels, metabugs
- Intro to Functional
- Intro to Computers memory, cpu, hardware, neuman, computer science, devices
- Intro to OFM
- Intro to Databases Intro to Database Migration ORM, ObjectRelationalMapping, Hibernate, JPA, ebeanorm
- Advanced in Databases - optimistic lock, pessimistic lock
- Intro to WebDevelopment - tcp, http
- Data Structures & money
- Intro to Virtualization
- Admin section
- Intro to Types value, record, case class, alias
- Intro to Layers - frontend,ui,ux
- Intro to Culture - teams, psychology, principles, behaviour
- Intro to 41 - aboriginal linux, google whitepapers
- Intro to Security - ssl, handshake, tsl, https, basic auth, tokens, refresh, jwt tokens, access, refresh
- Intro to Crypto
- Advanced
- Advanced Java
- Circuit Breaker, retry, bulkhead, RateLimit, resilience
- Immutable, purity, pure functions, functional style
- Identification Surrogate vs Natural Keys, database, rest, microservice
- Infrastructure devops, docker, containers, kubernetes, k8s, private cloud, continous deployment
- Resources
- Project Templates
- Ships
- Ship10 - 2021-Aug
- Ship 1 - 2017-May
- Ship 2 - 2017-June
- Ship 3 - 2017-July
-
Ship 4 - 2017-September
- Team 4
- Team 4 Reloaded
- Backlog 4
- Sprint 4.1 old
- Sprint 4.1 Home old
- Sprint 4.2 old
- Sprint 4.2 Home old
- Sprint 4.3 old
- Sprint 4.3 Home old
- Sprint 4.4 old
- Sprint 4.4 Home old
- Sprint 4.5 old
- Sprint 4.5 Home old
- Sprint 4.6 old
- Sprint 4.6 Home old
- Sprint 4.7 old
- Sprint 4.7 Home old
- Sprint 4.8 old
- Sprint 4.8 Home old
-
Non software
- Physical Tools - home tooling